ecosystems-bibliothecary 14.3.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/README.md +8 -23
- data/bibliothecary.gemspec +5 -9
- data/lib/bibliothecary/analyser.rb +0 -31
- data/lib/bibliothecary/cli.rb +35 -26
- data/lib/bibliothecary/configuration.rb +1 -6
- data/lib/bibliothecary/dependency.rb +1 -4
- data/lib/bibliothecary/parsers/bentoml.rb +0 -2
- data/lib/bibliothecary/parsers/bower.rb +0 -1
- data/lib/bibliothecary/parsers/cargo.rb +12 -10
- data/lib/bibliothecary/parsers/carthage.rb +51 -15
- data/lib/bibliothecary/parsers/clojars.rb +14 -18
- data/lib/bibliothecary/parsers/cocoapods.rb +100 -19
- data/lib/bibliothecary/parsers/cog.rb +0 -2
- data/lib/bibliothecary/parsers/conan.rb +156 -0
- data/lib/bibliothecary/parsers/conda.rb +0 -3
- data/lib/bibliothecary/parsers/cpan.rb +0 -2
- data/lib/bibliothecary/parsers/cran.rb +40 -19
- data/lib/bibliothecary/parsers/docker.rb +0 -2
- data/lib/bibliothecary/parsers/dub.rb +33 -8
- data/lib/bibliothecary/parsers/dvc.rb +0 -2
- data/lib/bibliothecary/parsers/elm.rb +13 -3
- data/lib/bibliothecary/parsers/go.rb +14 -5
- data/lib/bibliothecary/parsers/hackage.rb +132 -24
- data/lib/bibliothecary/parsers/haxelib.rb +14 -4
- data/lib/bibliothecary/parsers/hex.rb +37 -20
- data/lib/bibliothecary/parsers/homebrew.rb +0 -2
- data/lib/bibliothecary/parsers/julia.rb +0 -2
- data/lib/bibliothecary/parsers/maven.rb +35 -25
- data/lib/bibliothecary/parsers/meteor.rb +14 -4
- data/lib/bibliothecary/parsers/mlflow.rb +0 -2
- data/lib/bibliothecary/parsers/npm.rb +47 -59
- data/lib/bibliothecary/parsers/nuget.rb +22 -21
- data/lib/bibliothecary/parsers/ollama.rb +0 -2
- data/lib/bibliothecary/parsers/packagist.rb +0 -3
- data/lib/bibliothecary/parsers/pub.rb +0 -2
- data/lib/bibliothecary/parsers/pypi.rb +54 -35
- data/lib/bibliothecary/parsers/rubygems.rb +92 -27
- data/lib/bibliothecary/parsers/shard.rb +0 -1
- data/lib/bibliothecary/parsers/swift_pm.rb +77 -29
- data/lib/bibliothecary/parsers/vcpkg.rb +68 -17
- data/lib/bibliothecary/runner.rb +2 -15
- data/lib/bibliothecary/version.rb +1 -1
- data/lib/bibliothecary.rb +0 -4
- metadata +2 -110
- data/.codeclimate.yml +0 -25
- data/.github/CONTRIBUTING.md +0 -195
- data/.github/workflows/ci.yml +0 -25
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.rubocop.yml +0 -69
- data/.ruby-version +0 -1
- data/.tidelift +0 -1
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -35
- data/Rakefile +0 -18
- data/bin/benchmark +0 -386
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/bibliothecary/multi_parsers/bundler_like_manifest.rb +0 -26
- data/lib/bibliothecary/multi_parsers/cyclonedx.rb +0 -170
- data/lib/bibliothecary/multi_parsers/dependencies_csv.rb +0 -155
- data/lib/bibliothecary/multi_parsers/json_runtime.rb +0 -22
- data/lib/bibliothecary/multi_parsers/spdx.rb +0 -149
- data/lib/bibliothecary/purl_util.rb +0 -37
- data/lib/bibliothecary/runner/multi_manifest_filter.rb +0 -92
- data/lib/sdl_parser.rb +0 -30
data/.rubocop.yml
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
|
|
3
|
-
# Without this, CI might pickup nested dep's rubocop files in vendor/
|
|
4
|
-
inherit_mode:
|
|
5
|
-
merge:
|
|
6
|
-
- Exclude
|
|
7
|
-
|
|
8
|
-
AllCops:
|
|
9
|
-
NewCops: enable
|
|
10
|
-
TargetRubyVersion: 4.0
|
|
11
|
-
Exclude:
|
|
12
|
-
- spec/fixtures/**/*
|
|
13
|
-
- vendor/bundle/**/* # This is actually needed for CI, not for biblio itself
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Metrics/BlockLength:
|
|
17
|
-
Max: 100
|
|
18
|
-
Exclude:
|
|
19
|
-
- config/routes.rb
|
|
20
|
-
- config/initializers/*
|
|
21
|
-
- spec/**/*_spec.rb
|
|
22
|
-
- spec/factories.rb
|
|
23
|
-
- lib/tasks/*.rake
|
|
24
|
-
|
|
25
|
-
# metrics and documentation. code is complex as it needs to be,
|
|
26
|
-
# and docs shouldn't be required. add them when needed.
|
|
27
|
-
Metrics/AbcSize:
|
|
28
|
-
Enabled: false
|
|
29
|
-
Layout/LineLength:
|
|
30
|
-
Enabled: false
|
|
31
|
-
Metrics/ClassLength:
|
|
32
|
-
Enabled: false
|
|
33
|
-
Metrics/MethodLength:
|
|
34
|
-
Enabled: false
|
|
35
|
-
Metrics/ModuleLength:
|
|
36
|
-
Enabled: false
|
|
37
|
-
Metrics/CyclomaticComplexity:
|
|
38
|
-
Enabled: false
|
|
39
|
-
Metrics/PerceivedComplexity:
|
|
40
|
-
Enabled: false
|
|
41
|
-
Metrics/ParameterLists:
|
|
42
|
-
Max: 7
|
|
43
|
-
CountKeywordArgs: false
|
|
44
|
-
Style/Documentation:
|
|
45
|
-
Enabled: false
|
|
46
|
-
|
|
47
|
-
# differences from standard ruby style guide.
|
|
48
|
-
Style/RegexpLiteral:
|
|
49
|
-
Enabled: false
|
|
50
|
-
Style/StringLiterals:
|
|
51
|
-
EnforcedStyle: double_quotes
|
|
52
|
-
Style/TrailingCommaInArrayLiteral:
|
|
53
|
-
EnforcedStyleForMultiline: comma
|
|
54
|
-
Style/TrailingCommaInHashLiteral:
|
|
55
|
-
EnforcedStyleForMultiline: comma
|
|
56
|
-
Layout/FirstArrayElementIndentation:
|
|
57
|
-
Enabled: false
|
|
58
|
-
Layout/MultilineMethodCallIndentation:
|
|
59
|
-
EnforcedStyle: indented
|
|
60
|
-
Style/NumericPredicate:
|
|
61
|
-
Enabled: false
|
|
62
|
-
Style/FormatStringToken:
|
|
63
|
-
Enabled: false
|
|
64
|
-
Style/MultilineBlockChain:
|
|
65
|
-
Enabled: false
|
|
66
|
-
Style/IfUnlessModifier:
|
|
67
|
-
Enabled: false
|
|
68
|
-
Layout/BlockAlignment:
|
|
69
|
-
EnforcedStyleAlignWith: start_of_block
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
4.0.0
|
data/.tidelift
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
TIDELIFT_EXCLUDED_MANIFESTS=spec/fixtures
|
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
-
orientation.
|
|
11
|
-
|
|
12
|
-
## Our Standards
|
|
13
|
-
|
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
|
15
|
-
include:
|
|
16
|
-
|
|
17
|
-
* Using welcoming and inclusive language
|
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
|
19
|
-
* Gracefully accepting constructive criticism
|
|
20
|
-
* Focusing on what is best for the community
|
|
21
|
-
* Showing empathy towards other community members
|
|
22
|
-
|
|
23
|
-
Examples of unacceptable behavior by participants include:
|
|
24
|
-
|
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
-
advances
|
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
-
* Public or private harassment
|
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
|
30
|
-
address, without explicit permission
|
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
-
professional setting
|
|
33
|
-
|
|
34
|
-
## Our Responsibilities
|
|
35
|
-
|
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
-
response to any instances of unacceptable behavior.
|
|
39
|
-
|
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
-
threatening, offensive, or harmful.
|
|
45
|
-
|
|
46
|
-
## Scope
|
|
47
|
-
|
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
-
when an individual is representing the project or its community. Examples of
|
|
50
|
-
representing a project or community include using an official project e-mail
|
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
|
53
|
-
further defined and clarified by project maintainers.
|
|
54
|
-
|
|
55
|
-
## Enforcement
|
|
56
|
-
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
-
reported by contacting the project team at andrew@libraries.io. All
|
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
|
63
|
-
|
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
-
members of the project's leadership.
|
|
67
|
-
|
|
68
|
-
## Attribution
|
|
69
|
-
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
-
|
|
73
|
-
[homepage]: http://contributor-covenant.org
|
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
# Temporarily pegging to HEAD until 0.2.1 is released: https://github.com/piotrmurach/strings-ansi/pull/2
|
|
6
|
-
gem "strings-ansi", ref: "35d0c9430cf0a8022dc12bdab005bce296cb9f00", github: "piotrmurach/strings-ansi"
|
|
7
|
-
|
|
8
|
-
# Ruby 3.4+ no longer includes these as default gems
|
|
9
|
-
gem "base64"
|
|
10
|
-
gem "benchmark"
|
|
11
|
-
gem "bigdecimal"
|
|
12
|
-
gem "csv"
|
|
13
|
-
gem "logger"
|
|
14
|
-
gem "ostruct"
|
|
15
|
-
|
|
16
|
-
# Specify your gem's dependencies in bibliothecary.gemspec
|
|
17
|
-
gemspec
|
|
18
|
-
|
|
19
|
-
group :development do
|
|
20
|
-
gem "pry"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
group :development, :test do
|
|
24
|
-
gem "rake", "~> 13.0"
|
|
25
|
-
gem "rubocop", "~> 1.71"
|
|
26
|
-
gem "rubocop-rails"
|
|
27
|
-
gem "rubocop-rake" # This is needed by packageurl-ruby, until it reclassifies it as a dev dependency.
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
group :test do
|
|
31
|
-
gem "rspec", "~> 3.0"
|
|
32
|
-
gem "simplecov"
|
|
33
|
-
gem "super_diff", "~> 0.18.0"
|
|
34
|
-
gem "webmock"
|
|
35
|
-
end
|
data/Rakefile
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/gem_tasks"
|
|
4
|
-
require "rspec/core/rake_task"
|
|
5
|
-
|
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
-
|
|
8
|
-
task default: :spec
|
|
9
|
-
|
|
10
|
-
desc "Run the linter"
|
|
11
|
-
task :lint do
|
|
12
|
-
sh "bundle exec rubocop -P"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
desc "Run the linter with autofix"
|
|
16
|
-
task :fix do
|
|
17
|
-
sh "bundle exec rubocop -A"
|
|
18
|
-
end
|
data/bin/benchmark
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require "bundler/setup"
|
|
5
|
-
require "bibliothecary"
|
|
6
|
-
require "benchmark"
|
|
7
|
-
require "optparse"
|
|
8
|
-
|
|
9
|
-
class InfrastructureBenchmark
|
|
10
|
-
FIXTURES_DIR = File.expand_path("../spec/fixtures", __dir__)
|
|
11
|
-
|
|
12
|
-
def initialize(iterations: 100)
|
|
13
|
-
@iterations = iterations
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def run
|
|
17
|
-
puts "Infrastructure Benchmark"
|
|
18
|
-
puts "=" * 60
|
|
19
|
-
puts "Iterations: #{@iterations}"
|
|
20
|
-
puts
|
|
21
|
-
|
|
22
|
-
# Prepare test data - mix of different file types
|
|
23
|
-
test_files = prepare_test_files
|
|
24
|
-
puts "Test files: #{test_files.length}"
|
|
25
|
-
puts
|
|
26
|
-
|
|
27
|
-
benchmark_package_managers
|
|
28
|
-
benchmark_matching_overhead
|
|
29
|
-
benchmark_load_file_info_list_from_contents(test_files)
|
|
30
|
-
benchmark_analyse_file(test_files)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def prepare_test_files
|
|
34
|
-
files = []
|
|
35
|
-
# Get a representative sample of fixtures
|
|
36
|
-
%w[package.json Gemfile.lock Cargo.toml pom.xml requirements.txt go.mod].each do |name|
|
|
37
|
-
path = Dir.glob("#{FIXTURES_DIR}/**/#{name}").first
|
|
38
|
-
next unless path
|
|
39
|
-
|
|
40
|
-
files << { file_path: path.sub("#{FIXTURES_DIR}/", ""), contents: File.read(path) }
|
|
41
|
-
end
|
|
42
|
-
files
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def benchmark_package_managers
|
|
46
|
-
puts "package_managers method:"
|
|
47
|
-
puts "-" * 40
|
|
48
|
-
|
|
49
|
-
runner = Bibliothecary.runner
|
|
50
|
-
|
|
51
|
-
# Warm up
|
|
52
|
-
5.times { runner.package_managers }
|
|
53
|
-
|
|
54
|
-
time = Benchmark.measure do
|
|
55
|
-
@iterations.times { runner.package_managers }
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
printf " %d calls: %.3f ms total, %.4f ms/call\n",
|
|
59
|
-
@iterations, time.real * 1000, (time.real / @iterations) * 1000
|
|
60
|
-
puts
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def benchmark_load_file_info_list_from_contents(test_files)
|
|
64
|
-
puts "load_file_info_list_from_contents:"
|
|
65
|
-
puts "-" * 40
|
|
66
|
-
|
|
67
|
-
runner = Bibliothecary.runner
|
|
68
|
-
|
|
69
|
-
# Warm up
|
|
70
|
-
5.times { runner.load_file_info_list_from_contents(test_files) }
|
|
71
|
-
|
|
72
|
-
time = Benchmark.measure do
|
|
73
|
-
@iterations.times { runner.load_file_info_list_from_contents(test_files) }
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
total_files = test_files.length * @iterations
|
|
77
|
-
printf " %d calls (%d files each): %.3f ms total\n",
|
|
78
|
-
@iterations, test_files.length, time.real * 1000
|
|
79
|
-
printf " %.4f ms/call, %.4f ms/file\n",
|
|
80
|
-
(time.real / @iterations) * 1000,
|
|
81
|
-
(time.real / total_files) * 1000
|
|
82
|
-
puts
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def benchmark_analyse_file(test_files)
|
|
86
|
-
puts "analyse_file (full pipeline):"
|
|
87
|
-
puts "-" * 40
|
|
88
|
-
|
|
89
|
-
runner = Bibliothecary.runner
|
|
90
|
-
|
|
91
|
-
test_files.each do |file|
|
|
92
|
-
# Warm up
|
|
93
|
-
3.times { runner.analyse_file(file[:file_path], file[:contents]) }
|
|
94
|
-
|
|
95
|
-
time = Benchmark.measure do
|
|
96
|
-
@iterations.times { runner.analyse_file(file[:file_path], file[:contents]) }
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
printf " %-30s %.4f ms/call\n",
|
|
100
|
-
File.basename(file[:file_path]),
|
|
101
|
-
(time.real / @iterations) * 1000
|
|
102
|
-
end
|
|
103
|
-
puts
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def benchmark_matching_overhead
|
|
107
|
-
puts "Matching overhead breakdown:"
|
|
108
|
-
puts "-" * 40
|
|
109
|
-
|
|
110
|
-
runner = Bibliothecary.runner
|
|
111
|
-
pms = runner.package_managers
|
|
112
|
-
|
|
113
|
-
# Test with a simple package.json
|
|
114
|
-
test_file = { file_path: "package.json", contents: '{"dependencies":{}}' }
|
|
115
|
-
info = Bibliothecary::FileInfo.new(nil, test_file[:file_path], test_file[:contents])
|
|
116
|
-
|
|
117
|
-
# Benchmark match_info? across all parsers
|
|
118
|
-
time = Benchmark.measure do
|
|
119
|
-
@iterations.times do
|
|
120
|
-
pms.each { |pm| pm.match_info?(info) }
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
printf " match_info? x %d parsers: %.4f ms/file\n",
|
|
124
|
-
pms.length, (time.real / @iterations) * 1000
|
|
125
|
-
|
|
126
|
-
# Benchmark just the npm parser's match_info?
|
|
127
|
-
npm = pms.find { |pm| pm.platform_name == "npm" }
|
|
128
|
-
time = Benchmark.measure do
|
|
129
|
-
@iterations.times { npm.match_info?(info) }
|
|
130
|
-
end
|
|
131
|
-
printf " npm.match_info? alone: %.4f ms/call\n",
|
|
132
|
-
(time.real / @iterations) * 1000
|
|
133
|
-
|
|
134
|
-
# Benchmark first_matching_mapping_details (called multiple times per file)
|
|
135
|
-
time = Benchmark.measure do
|
|
136
|
-
@iterations.times do
|
|
137
|
-
npm.send(:first_matching_mapping_details, info)
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
printf " first_matching_mapping_details: %.4f ms/call\n",
|
|
141
|
-
(time.real / @iterations) * 1000
|
|
142
|
-
|
|
143
|
-
puts
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
class ParserBenchmark
|
|
148
|
-
FIXTURES_DIR = File.expand_path("../spec/fixtures", __dir__)
|
|
149
|
-
|
|
150
|
-
# Parser methods that require remote services
|
|
151
|
-
REMOTE_PARSERS = {
|
|
152
|
-
"swiftpm" => [:parse_package_swift],
|
|
153
|
-
"hackage" => [:parse_cabal],
|
|
154
|
-
"hex" => [:parse_mix, :parse_mix_lock],
|
|
155
|
-
"carthage" => [:parse_cartfile, :parse_cartfile_private, :parse_cartfile_resolved],
|
|
156
|
-
"clojars" => [:parse_manifest],
|
|
157
|
-
}.freeze
|
|
158
|
-
|
|
159
|
-
# Multi-parser methods shared across many package managers
|
|
160
|
-
MULTI_PARSER_METHODS = %i[
|
|
161
|
-
parse_cyclonedx_json
|
|
162
|
-
parse_cyclonedx_xml
|
|
163
|
-
parse_spdx_json
|
|
164
|
-
parse_spdx_tag_value
|
|
165
|
-
parse_dependencies_csv
|
|
166
|
-
].freeze
|
|
167
|
-
|
|
168
|
-
def initialize(options = {})
|
|
169
|
-
@iterations = options.fetch(:iterations, 100)
|
|
170
|
-
@parser_filter = options[:parser]
|
|
171
|
-
@verbose = options[:verbose]
|
|
172
|
-
@native_only = options[:native_only]
|
|
173
|
-
@results = {}
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def run
|
|
177
|
-
puts "Bibliothecary Parser Benchmark"
|
|
178
|
-
puts "=" * 60
|
|
179
|
-
puts "Iterations per file: #{@iterations}"
|
|
180
|
-
puts "Fixtures directory: #{FIXTURES_DIR}"
|
|
181
|
-
puts
|
|
182
|
-
|
|
183
|
-
parsers = filtered_parsers
|
|
184
|
-
puts "Running benchmarks for #{parsers.length} parser(s)..."
|
|
185
|
-
puts
|
|
186
|
-
|
|
187
|
-
parsers.each do |parser|
|
|
188
|
-
benchmark_parser(parser)
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
print_summary
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def filtered_parsers
|
|
195
|
-
all_parsers = Bibliothecary.package_managers
|
|
196
|
-
return all_parsers unless @parser_filter
|
|
197
|
-
|
|
198
|
-
matching = all_parsers.select do |pm|
|
|
199
|
-
pm.platform_name.downcase.include?(@parser_filter.downcase)
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
if matching.empty?
|
|
203
|
-
puts "No parser matching '#{@parser_filter}' found."
|
|
204
|
-
puts "Available parsers: #{all_parsers.map(&:platform_name).join(', ')}"
|
|
205
|
-
exit 1
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
matching
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def benchmark_parser(parser)
|
|
212
|
-
platform = parser.platform_name
|
|
213
|
-
mapping = parser.mapping
|
|
214
|
-
fixtures = find_fixtures_for_parser(mapping, platform)
|
|
215
|
-
|
|
216
|
-
if fixtures.empty?
|
|
217
|
-
puts "#{platform}: no matching fixtures found"
|
|
218
|
-
puts if @verbose
|
|
219
|
-
return
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
puts "#{platform} (#{fixtures.length} files)"
|
|
223
|
-
puts "-" * 40
|
|
224
|
-
|
|
225
|
-
parser_total = 0
|
|
226
|
-
file_results = []
|
|
227
|
-
|
|
228
|
-
fixtures.each do |fixture_path, mapping_entry|
|
|
229
|
-
contents = File.read(fixture_path)
|
|
230
|
-
filename = File.basename(fixture_path)
|
|
231
|
-
relative = fixture_path.sub("#{FIXTURES_DIR}/", "")
|
|
232
|
-
|
|
233
|
-
begin
|
|
234
|
-
time = Benchmark.measure do
|
|
235
|
-
@iterations.times do
|
|
236
|
-
parser.send(mapping_entry[:parser], contents, options: { filename: filename })
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
avg_ms = (time.real / @iterations) * 1000
|
|
241
|
-
parser_total += time.real
|
|
242
|
-
|
|
243
|
-
file_results << {
|
|
244
|
-
file: relative,
|
|
245
|
-
total: time.real,
|
|
246
|
-
avg_ms: avg_ms,
|
|
247
|
-
kind: mapping_entry[:kind],
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if @verbose
|
|
251
|
-
printf " %-40s %8.3f ms/call (%s)\n", relative, avg_ms, mapping_entry[:kind]
|
|
252
|
-
end
|
|
253
|
-
rescue Bibliothecary::RemoteParsingError => e
|
|
254
|
-
puts " #{relative}: skipped (remote parser unavailable)"
|
|
255
|
-
rescue => e
|
|
256
|
-
puts " #{relative}: error - #{e.class}: #{e.message}"
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
unless @verbose
|
|
261
|
-
file_results.sort_by { |r| -r[:avg_ms] }.first(3).each do |r|
|
|
262
|
-
printf " %-40s %8.3f ms/call\n", r[:file], r[:avg_ms]
|
|
263
|
-
end
|
|
264
|
-
puts " ..." if file_results.length > 3
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
avg_total = (parser_total / fixtures.length / @iterations) * 1000
|
|
268
|
-
printf " Total: %.3f ms avg per file\n", avg_total
|
|
269
|
-
puts
|
|
270
|
-
|
|
271
|
-
@results[platform] = {
|
|
272
|
-
files: fixtures.length,
|
|
273
|
-
total_time: parser_total,
|
|
274
|
-
avg_per_file: avg_total,
|
|
275
|
-
file_results: file_results,
|
|
276
|
-
}
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
def find_fixtures_for_parser(mapping, platform_name)
|
|
280
|
-
fixtures = []
|
|
281
|
-
remote_methods = REMOTE_PARSERS[platform_name] || []
|
|
282
|
-
|
|
283
|
-
all_fixtures.each do |fixture_path|
|
|
284
|
-
filename = File.basename(fixture_path)
|
|
285
|
-
relative_path = fixture_path.sub("#{FIXTURES_DIR}/", "")
|
|
286
|
-
|
|
287
|
-
mapping.each do |matcher, entry|
|
|
288
|
-
next unless entry[:parser]
|
|
289
|
-
next if remote_methods.include?(entry[:parser])
|
|
290
|
-
next if @native_only && MULTI_PARSER_METHODS.include?(entry[:parser])
|
|
291
|
-
|
|
292
|
-
if matcher_matches?(matcher, filename, fixture_path)
|
|
293
|
-
fixtures << [fixture_path, entry]
|
|
294
|
-
break
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
fixtures
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
def matcher_matches?(matcher, filename, full_path)
|
|
303
|
-
relative_path = full_path.sub("#{FIXTURES_DIR}/", "")
|
|
304
|
-
|
|
305
|
-
case matcher
|
|
306
|
-
when Regexp
|
|
307
|
-
filename.match?(matcher)
|
|
308
|
-
when String
|
|
309
|
-
filename == matcher
|
|
310
|
-
when Proc
|
|
311
|
-
matcher.call(relative_path)
|
|
312
|
-
else
|
|
313
|
-
false
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
def all_fixtures
|
|
318
|
-
@all_fixtures ||= Dir.glob("#{FIXTURES_DIR}/**/*")
|
|
319
|
-
.select { |f| File.file?(f) }
|
|
320
|
-
.reject { |f| f.include?("/broken/") }
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def print_summary
|
|
324
|
-
return if @results.empty?
|
|
325
|
-
|
|
326
|
-
puts "=" * 60
|
|
327
|
-
puts "Summary (sorted by avg time per file)"
|
|
328
|
-
puts "=" * 60
|
|
329
|
-
|
|
330
|
-
sorted = @results.sort_by { |_, v| -v[:avg_per_file] }
|
|
331
|
-
|
|
332
|
-
printf "%-20s %10s %12s\n", "Parser", "Files", "Avg ms/file"
|
|
333
|
-
printf "%-20s %10s %12s\n", "-" * 20, "-" * 10, "-" * 12
|
|
334
|
-
|
|
335
|
-
sorted.each do |platform, data|
|
|
336
|
-
printf "%-20s %10d %12.3f\n", platform, data[:files], data[:avg_per_file]
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
puts
|
|
340
|
-
total_files = @results.values.sum { |v| v[:files] }
|
|
341
|
-
total_time = @results.values.sum { |v| v[:total_time] }
|
|
342
|
-
puts "Total: #{total_files} files, #{(total_time * 1000).round(1)} ms total time"
|
|
343
|
-
end
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
options = {
|
|
347
|
-
iterations: 100,
|
|
348
|
-
verbose: false,
|
|
349
|
-
mode: :parsers,
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
OptionParser.new do |opts|
|
|
353
|
-
opts.banner = "Usage: bin/benchmark [options]"
|
|
354
|
-
|
|
355
|
-
opts.on("-p", "--parser NAME", "Only benchmark parsers matching NAME") do |p|
|
|
356
|
-
options[:parser] = p
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
opts.on("-n", "--iterations N", Integer, "Number of iterations per file (default: 100)") do |n|
|
|
360
|
-
options[:iterations] = n
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
opts.on("-v", "--verbose", "Show all files, not just slowest") do
|
|
364
|
-
options[:verbose] = true
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
opts.on("--native-only", "Exclude shared multi-parsers (CycloneDX, SPDX, CSV)") do
|
|
368
|
-
options[:native_only] = true
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
opts.on("--infra", "Benchmark infrastructure (load_file_info_list, etc)") do
|
|
372
|
-
options[:mode] = :infra
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
opts.on("-h", "--help", "Show this help") do
|
|
376
|
-
puts opts
|
|
377
|
-
exit
|
|
378
|
-
end
|
|
379
|
-
end.parse!
|
|
380
|
-
|
|
381
|
-
case options[:mode]
|
|
382
|
-
when :infra
|
|
383
|
-
InfrastructureBenchmark.new(iterations: options[:iterations]).run
|
|
384
|
-
else
|
|
385
|
-
ParserBenchmark.new(options).run
|
|
386
|
-
end
|
data/bin/console
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require "bundler/setup"
|
|
5
|
-
require "bibliothecary"
|
|
6
|
-
|
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
-
|
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
-
# require "pry"
|
|
12
|
-
# Pry.start
|
|
13
|
-
|
|
14
|
-
require "pry"
|
|
15
|
-
Pry.start
|
data/bin/setup
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Bibliothecary
|
|
4
|
-
module MultiParsers
|
|
5
|
-
module BundlerLikeManifest
|
|
6
|
-
# this takes parsed Bundler and Bundler-like (CocoaPods)
|
|
7
|
-
# manifests and turns them into a list of dependencies.
|
|
8
|
-
def parse_ruby_manifest(manifest, platform, source = nil)
|
|
9
|
-
manifest.dependencies.inject([]) do |deps, dep|
|
|
10
|
-
deps.push(Dependency.new(
|
|
11
|
-
platform: platform,
|
|
12
|
-
name: dep.name,
|
|
13
|
-
requirement: dep
|
|
14
|
-
.requirement
|
|
15
|
-
.requirements
|
|
16
|
-
.sort_by(&:last)
|
|
17
|
-
.map { |op, version| "#{op} #{version}" }
|
|
18
|
-
.join(", "),
|
|
19
|
-
type: dep.type.to_s,
|
|
20
|
-
source: source
|
|
21
|
-
))
|
|
22
|
-
end.uniq
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|