bundler 4.1.0.beta3 → 4.1.1
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/bundler.gemspec +5 -3
- data/lib/bundler/build_metadata.rb +2 -2
- data/lib/bundler/checksum.rb +17 -2
- data/lib/bundler/cli/clean.rb +19 -3
- data/lib/bundler/cli/exec.rb +1 -1
- data/lib/bundler/cli/install.rb +1 -1
- data/lib/bundler/cli/lock.rb +12 -0
- data/lib/bundler/cli/outdated.rb +1 -4
- data/lib/bundler/cli/update.rb +1 -1
- data/lib/bundler/cli.rb +2 -0
- data/lib/bundler/definition.rb +152 -7
- data/lib/bundler/dependency.rb +17 -2
- data/lib/bundler/dsl.rb +9 -2
- data/lib/bundler/errors.rb +8 -0
- data/lib/bundler/fetcher/downloader.rb +7 -3
- data/lib/bundler/index.rb +7 -2
- data/lib/bundler/injector.rb +1 -1
- data/lib/bundler/inline.rb +19 -9
- data/lib/bundler/installer.rb +19 -0
- data/lib/bundler/lazy_specification.rb +46 -25
- data/lib/bundler/lockfile_generator.rb +21 -9
- data/lib/bundler/lockfile_parser.rb +21 -5
- data/lib/bundler/man/bundle-lock.1 +8 -2
- data/lib/bundler/man/bundle-lock.1.ronn +15 -1
- data/lib/bundler/man/bundle-plugin.1 +61 -0
- data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
- data/lib/bundler/man/gemfile.5 +3 -1
- data/lib/bundler/man/gemfile.5.ronn +11 -3
- data/lib/bundler/match_platform.rb +3 -3
- data/lib/bundler/match_remote_metadata.rb +6 -0
- data/lib/bundler/mirror.rb +7 -5
- data/lib/bundler/plugin/index.rb +14 -11
- data/lib/bundler/remote_specification.rb +5 -0
- data/lib/bundler/resolver/candidate.rb +5 -0
- data/lib/bundler/resolver.rb +89 -7
- data/lib/bundler/ruby_dsl.rb +2 -1
- data/lib/bundler/rubygems_ext.rb +54 -9
- data/lib/bundler/rubygems_integration.rb +2 -4
- data/lib/bundler/runtime.rb +29 -11
- data/lib/bundler/settings.rb +2 -3
- data/lib/bundler/source/git/git_proxy.rb +18 -6
- data/lib/bundler/source/git.rb +0 -2
- data/lib/bundler/spec_set.rb +54 -14
- data/lib/bundler/stub_specification.rb +4 -0
- data/lib/bundler/vendored_securerandom.rb +5 -2
- data/lib/bundler/vendored_uri.rb +18 -3
- data/lib/bundler/version.rb +1 -1
- data/lib/bundler/worker.rb +4 -0
- data/lib/bundler.rb +1 -1
- data/lib/rubygems/compact_index_client/http_fetcher.rb +3 -1
- data/lib/rubygems/vendor/pub_grub/lib/pub_grub/term.rb +1 -1
- data/lib/rubygems/yaml_serializer/builder.rb +261 -0
- data/lib/rubygems/yaml_serializer/core.rb +41 -0
- data/lib/rubygems/yaml_serializer/emitter.rb +197 -0
- data/lib/rubygems/yaml_serializer/nodes.rb +10 -0
- data/lib/rubygems/yaml_serializer/parser.rb +531 -0
- data/lib/rubygems/yaml_serializer/psych_errors.rb +11 -0
- metadata +8 -4
- data/lib/rubygems/vendor/uri/lib/uri.rb +0 -108
- data/lib/rubygems/yaml_serializer.rb +0 -908
data/lib/bundler/spec_set.rb
CHANGED
|
@@ -63,7 +63,7 @@ module Bundler
|
|
|
63
63
|
invalid_platforms
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
def add_extra_platforms!(platforms)
|
|
66
|
+
def add_extra_platforms!(platforms, prefer_local: false)
|
|
67
67
|
if @specs.empty?
|
|
68
68
|
platforms.concat([Gem::Platform::RUBY]).uniq
|
|
69
69
|
return
|
|
@@ -73,26 +73,48 @@ module Bundler
|
|
|
73
73
|
next if platforms.include?(platform)
|
|
74
74
|
next unless Gem::Platform.generic(platform) == Gem::Platform::RUBY
|
|
75
75
|
|
|
76
|
-
complete_platform(platform)
|
|
76
|
+
complete_platform(platform, prefer_local: prefer_local && platform === Bundler.local_platform)
|
|
77
77
|
end
|
|
78
78
|
return if new_platforms.empty?
|
|
79
79
|
|
|
80
80
|
platforms.concat(new_platforms)
|
|
81
81
|
return if new_platforms.include?(Bundler.local_platform)
|
|
82
|
+
return if prefer_local && @specs.any? {|spec| spec.platform == Bundler.local_platform }
|
|
82
83
|
|
|
83
84
|
less_specific_platform = new_platforms.find {|platform| platform != Gem::Platform::RUBY && Bundler.local_platform === platform && platform === Bundler.local_platform }
|
|
84
85
|
platforms.delete(Bundler.local_platform) if less_specific_platform
|
|
85
86
|
end
|
|
86
87
|
|
|
88
|
+
def assign_content_addresses!(ruby_abis, normalize: false, local: false)
|
|
89
|
+
@specs.each do |spec|
|
|
90
|
+
next unless spec.source.is_a?(Source::Rubygems)
|
|
91
|
+
next unless Gem::ContentAddress.platform_eligible?(spec.platform)
|
|
92
|
+
|
|
93
|
+
offered = spec.source.specs.search([spec.name, spec.version]).filter_map do |gem|
|
|
94
|
+
next unless gem.platform.to_s == spec.platform.to_s && Gem::ContentAddress.content_addressed?(gem)
|
|
95
|
+
|
|
96
|
+
[gem.content_address, Gem::ContentAddress.ruby_abi_for(gem.required_ruby_version)]
|
|
97
|
+
end.to_h
|
|
98
|
+
|
|
99
|
+
locked = normalize ? {} : spec.content_addresses
|
|
100
|
+
locked = locked.reject {|_, ruby_abi| ruby_abi.nil? } unless local
|
|
101
|
+
spec.content_addresses = locked.merge(offered).select {|_, ruby_abi| ruby_abi.nil? || ruby_abis.include?(ruby_abi) }
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def content_addresses_cover?(ruby_abi)
|
|
106
|
+
@specs.all? {|spec| !spec.is_a?(LazySpecification) || spec.content_addresses.empty? || spec.content_addresses.value?(ruby_abi) }
|
|
107
|
+
end
|
|
108
|
+
|
|
87
109
|
def validate_deps(s, overrides = s.is_a?(LazySpecification) ? Array(s.overrides) : [])
|
|
88
110
|
Override.rewrite_dependencies(overrides, s.name, s.runtime_dependencies).each do |dep|
|
|
89
111
|
next if dep.name == "bundler"
|
|
90
112
|
|
|
91
|
-
return :missing unless
|
|
113
|
+
return :missing unless lookup.key?(dep.name)
|
|
92
114
|
|
|
93
115
|
override = Override.find_for(overrides, dep.name, :version)
|
|
94
116
|
dep = Gem::Dependency.new(dep.name, override.apply_to(dep.requirement)) if override
|
|
95
|
-
return :invalid if none? {|spec| dep.matches_spec?(spec) }
|
|
117
|
+
return :invalid if Array(lookup[dep.name]).none? {|spec| dep.matches_spec?(spec) }
|
|
96
118
|
end
|
|
97
119
|
|
|
98
120
|
:valid
|
|
@@ -134,23 +156,21 @@ module Bundler
|
|
|
134
156
|
# Materialize for all the specs in the spec set, regardless of what platform they're for
|
|
135
157
|
# @return [Array<Gem::Specification>]
|
|
136
158
|
def materialized_for_all_platforms
|
|
137
|
-
@specs.
|
|
138
|
-
next s unless s.is_a?(LazySpecification)
|
|
139
|
-
|
|
140
|
-
raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec
|
|
141
|
-
spec
|
|
159
|
+
@specs.flat_map do |s|
|
|
160
|
+
next [s] unless s.is_a?(LazySpecification)
|
|
161
|
+
s.materialize_for_cache
|
|
142
162
|
end
|
|
143
163
|
end
|
|
144
164
|
|
|
145
165
|
def incomplete_for_platform?(deps, platform)
|
|
166
|
+
return false if @specs.empty?
|
|
167
|
+
|
|
146
168
|
incomplete_specs_for_platform(deps, platform).any?
|
|
147
169
|
end
|
|
148
170
|
|
|
149
171
|
def incomplete_specs_for_platform(deps, platform)
|
|
150
|
-
return [] if @specs.empty?
|
|
151
|
-
|
|
152
172
|
validation_set = self.class.new(@specs)
|
|
153
|
-
validation_set.for(deps, [platform])
|
|
173
|
+
validation_set.for(deps.select {|dep| dep.should_include?(platform) }, [platform])
|
|
154
174
|
validation_set.incomplete_specs
|
|
155
175
|
end
|
|
156
176
|
|
|
@@ -272,7 +292,7 @@ module Bundler
|
|
|
272
292
|
@materializations.filter_map(&:materialized_spec)
|
|
273
293
|
end
|
|
274
294
|
|
|
275
|
-
def complete_platform(platform)
|
|
295
|
+
def complete_platform(platform, prefer_local: false)
|
|
276
296
|
new_specs = []
|
|
277
297
|
|
|
278
298
|
valid_platform = lookup.all? do |_, specs|
|
|
@@ -283,7 +303,7 @@ module Bundler
|
|
|
283
303
|
# the same overrides the install/resolve path already applies.
|
|
284
304
|
overrides = spec.is_a?(LazySpecification) ? Array(spec.overrides) : []
|
|
285
305
|
matching_specs = spec.source.specs.search([spec.name, spec.version])
|
|
286
|
-
platform_spec =
|
|
306
|
+
platform_spec = find_platform_spec(matching_specs, platform, prefer_local) do |s|
|
|
287
307
|
s.matches_current_metadata_with_overrides?(overrides) && validate_deps(s, overrides) == :valid
|
|
288
308
|
end
|
|
289
309
|
|
|
@@ -309,6 +329,26 @@ module Bundler
|
|
|
309
329
|
valid_platform
|
|
310
330
|
end
|
|
311
331
|
|
|
332
|
+
def find_platform_spec(specs, platform, prefer_local, &valid)
|
|
333
|
+
if prefer_local
|
|
334
|
+
local_specs = specs.select {|s| s.is_a?(StubSpecification) || s.instance_of?(Gem::Specification) }
|
|
335
|
+
local_matches = local_specs.select {|s| covers_platform?(s.platform, platform) && valid.call(s) }
|
|
336
|
+
return MatchPlatform.select_best_platform_match(local_matches, platform).first if local_matches.any?
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
MatchPlatform.select_best_platform_match(specs, platform).find(&valid)
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def covers_platform?(gem_platform, platform)
|
|
343
|
+
return true if gem_platform == Gem::Platform::RUBY
|
|
344
|
+
return false unless gem_platform === platform
|
|
345
|
+
# A versioned or CPU-specific binary cannot cover a wildcard in the lockfile.
|
|
346
|
+
return false if platform.version.nil? && gem_platform.version
|
|
347
|
+
return false if [nil, "universal"].include?(platform.cpu) && ![nil, "universal"].include?(gem_platform.cpu)
|
|
348
|
+
|
|
349
|
+
true
|
|
350
|
+
end
|
|
351
|
+
|
|
312
352
|
def all_platforms
|
|
313
353
|
@specs.flat_map {|spec| spec.source.specs.search([spec.name, spec.version]).map(&:platform) }.uniq
|
|
314
354
|
end
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
# Reuse RubyGems' vendored SecureRandom (Gem::SecureRandom). The Bundler gem
|
|
4
4
|
# ships a copy under lib/rubygems/vendor, so this resolves even on RubyGems
|
|
5
5
|
# versions that predate it. Fall back to the stdlib only when no vendored copy
|
|
6
|
-
# is available at all.
|
|
6
|
+
# is available at all. RubyGems' own file is required by path for the reason
|
|
7
|
+
# given in vendored_uri.rb.
|
|
7
8
|
|
|
8
9
|
unless defined?(Gem::SecureRandom)
|
|
10
|
+
rubygems_securerandom = File.join(Gem::RUBYGEMS_DIR, "rubygems/vendor/securerandom/lib/securerandom.rb")
|
|
11
|
+
|
|
9
12
|
begin
|
|
10
|
-
require "rubygems/vendor/securerandom/lib/securerandom"
|
|
13
|
+
require File.exist?(rubygems_securerandom) ? rubygems_securerandom : "rubygems/vendor/securerandom/lib/securerandom"
|
|
11
14
|
rescue LoadError
|
|
12
15
|
require "securerandom"
|
|
13
16
|
Gem::SecureRandom = SecureRandom
|
data/lib/bundler/vendored_uri.rb
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Reuse RubyGems' vendored URI (Gem::URI). The Bundler gem ships a copy under
|
|
4
|
-
# lib/rubygems/vendor
|
|
5
|
-
#
|
|
4
|
+
# lib/rubygems/vendor without its entry file, which Bundler 2.5.6 to 4.0.x
|
|
5
|
+
# require by name on RubyGems older than 3.5.6 (see
|
|
6
|
+
# lib/rubygems/yaml_serializer/core.rb), so this loads the files that entry file
|
|
7
|
+
# loads on RubyGems versions that predate it. Fall back to the stdlib only when
|
|
8
|
+
# no vendored copy is available at all.
|
|
9
|
+
#
|
|
10
|
+
# RubyGems requires its own copy with require_relative, so require that same
|
|
11
|
+
# file when it exists. Older RubyGems versions, whose copy has no double load
|
|
12
|
+
# guard, would otherwise load the library a second time.
|
|
6
13
|
|
|
7
14
|
unless defined?(Gem::URI)
|
|
15
|
+
rubygems_uri = File.join(Gem::RUBYGEMS_DIR, "rubygems/vendor/uri/lib/uri.rb")
|
|
16
|
+
|
|
8
17
|
begin
|
|
9
|
-
|
|
18
|
+
if File.exist?(rubygems_uri)
|
|
19
|
+
require rubygems_uri
|
|
20
|
+
else
|
|
21
|
+
%w[version common generic file ftp http https ldap ldaps mailto ws wss].each do |file|
|
|
22
|
+
require_relative "../rubygems/vendor/uri/lib/uri/#{file}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
10
25
|
rescue LoadError
|
|
11
26
|
require "uri"
|
|
12
27
|
Gem::URI = URI
|
data/lib/bundler/version.rb
CHANGED
data/lib/bundler/worker.rb
CHANGED
|
@@ -93,6 +93,10 @@ module Bundler
|
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def create_threads
|
|
96
|
+
# Jobs use FileUtils, and TruffleRuby shows other threads an autoloaded
|
|
97
|
+
# constant while its file is still loading.
|
|
98
|
+
require_relative "vendored_fileutils"
|
|
99
|
+
|
|
96
100
|
creation_errors = []
|
|
97
101
|
|
|
98
102
|
@threads = Array.new(@size) do |i|
|
data/lib/bundler.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "bundler/rubygems_ext"
|
|
4
|
-
require_relative "bundler/vendored_fileutils"
|
|
5
4
|
autoload :Pathname, "pathname" unless defined?(Pathname)
|
|
6
5
|
require "rbconfig"
|
|
7
6
|
|
|
@@ -43,6 +42,7 @@ module Bundler
|
|
|
43
42
|
autoload :CIDetector, File.expand_path("bundler/ci_detector", __dir__)
|
|
44
43
|
autoload :Definition, File.expand_path("bundler/definition", __dir__)
|
|
45
44
|
autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
|
|
45
|
+
autoload :FileUtils, File.expand_path("bundler/vendored_fileutils", __dir__)
|
|
46
46
|
autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__)
|
|
47
47
|
autoload :Digest, File.expand_path("bundler/digest", __dir__)
|
|
48
48
|
autoload :Dsl, File.expand_path("bundler/dsl", __dir__)
|
|
@@ -9,6 +9,8 @@ class Gem::CompactIndexClient
|
|
|
9
9
|
# Gem::CompactIndexClient: #call(path, headers) returning a
|
|
10
10
|
# Gem::Net::HTTP response.
|
|
11
11
|
class HTTPFetcher
|
|
12
|
+
include Gem::Text
|
|
13
|
+
|
|
12
14
|
REDIRECT_LIMIT = 10
|
|
13
15
|
private_constant :REDIRECT_LIMIT
|
|
14
16
|
|
|
@@ -79,7 +81,7 @@ class Gem::CompactIndexClient
|
|
|
79
81
|
end
|
|
80
82
|
|
|
81
83
|
def bad_response(response, uri)
|
|
82
|
-
detail = response["X-Error-Message"] || response.message
|
|
84
|
+
detail = clean_text(response["X-Error-Message"] || response.message)
|
|
83
85
|
Gem::RemoteFetcher::FetchError.new("bad response #{detail} #{response.code}", uri)
|
|
84
86
|
end
|
|
85
87
|
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gem
|
|
4
|
+
module YAMLSerializer
|
|
5
|
+
class Builder
|
|
6
|
+
VALID_OPS = %w[= != > < >= <= ~>].freeze
|
|
7
|
+
ARRAY_FIELDS = %w[files test_files executables extra_rdoc_files].freeze
|
|
8
|
+
MAX_ALIAS_EXPANSION = 100_000
|
|
9
|
+
|
|
10
|
+
def initialize(permitted_classes: [], permitted_symbols: [], aliases: true)
|
|
11
|
+
@permitted_classes = permitted_classes.map {|c| "!ruby/object:#{c}" }
|
|
12
|
+
@permitted_symbols = permitted_symbols
|
|
13
|
+
@aliases = aliases
|
|
14
|
+
@anchor_values = {}
|
|
15
|
+
@anchor_sizes = {}
|
|
16
|
+
@expanded_size = 0
|
|
17
|
+
@alias_expansion = 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def build(node)
|
|
21
|
+
return nil if node.nil?
|
|
22
|
+
|
|
23
|
+
result = build_node(node)
|
|
24
|
+
|
|
25
|
+
if result.is_a?(Hash) && result[:tag] == "!ruby/object:Gem::Specification"
|
|
26
|
+
build_specification(result)
|
|
27
|
+
else
|
|
28
|
+
result
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def build_node(node)
|
|
35
|
+
start = @expanded_size
|
|
36
|
+
case node
|
|
37
|
+
when nil then nil
|
|
38
|
+
when AliasRef then resolve_alias(node)
|
|
39
|
+
when Scalar then store_anchor(node.anchor, node.value, start)
|
|
40
|
+
when Mapping then store_anchor(node.anchor, build_mapping(node), start)
|
|
41
|
+
when Sequence then store_anchor(node.anchor, node.items.map {|item| build_node(item) }, start)
|
|
42
|
+
else node # already a Ruby object
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def resolve_alias(node)
|
|
47
|
+
raise Psych::AliasesNotEnabled unless @aliases
|
|
48
|
+
unless @anchor_values.key?(node.name)
|
|
49
|
+
raise Psych::AnchorNotDefined, node.name if defined?(Psych::AnchorNotDefined)
|
|
50
|
+
raise Psych::BadAlias, "An alias referenced an unknown anchor: #{node.name}"
|
|
51
|
+
end
|
|
52
|
+
# Charge the expanded size of the anchor, weighing scalars by length,
|
|
53
|
+
# so neither nested aliases nor aliases to a long string blow up.
|
|
54
|
+
size = @anchor_sizes.fetch(node.name)
|
|
55
|
+
@expanded_size += size
|
|
56
|
+
@alias_expansion += size
|
|
57
|
+
if @alias_expansion > MAX_ALIAS_EXPANSION
|
|
58
|
+
raise Psych::BadAlias, "exceeded maximum alias expansion (#{MAX_ALIAS_EXPANSION})"
|
|
59
|
+
end
|
|
60
|
+
@anchor_values.fetch(node.name)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def store_anchor(name, value, start)
|
|
64
|
+
@expanded_size += value.is_a?(String) ? 1 + value.bytesize : 1
|
|
65
|
+
if name
|
|
66
|
+
@anchor_values[name] = value
|
|
67
|
+
@anchor_sizes[name] = @expanded_size - start
|
|
68
|
+
end
|
|
69
|
+
value
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build_mapping(node)
|
|
73
|
+
validate_tag!(node.tag) if node.tag
|
|
74
|
+
|
|
75
|
+
result = case node.tag
|
|
76
|
+
when "!ruby/object:Gem::Version"
|
|
77
|
+
build_version(node)
|
|
78
|
+
when "!ruby/object:Gem::Platform"
|
|
79
|
+
build_platform(node)
|
|
80
|
+
when "!ruby/object:Gem::Requirement", "!ruby/object:Gem::Version::Requirement"
|
|
81
|
+
build_requirement(node)
|
|
82
|
+
when "!ruby/object:Gem::Dependency"
|
|
83
|
+
build_dependency(node)
|
|
84
|
+
when nil
|
|
85
|
+
build_hash(node)
|
|
86
|
+
when "!ruby/object:Gem::Specification"
|
|
87
|
+
hash = build_hash(node)
|
|
88
|
+
hash[:tag] = node.tag
|
|
89
|
+
hash
|
|
90
|
+
else
|
|
91
|
+
raise ArgumentError, "undefined class/module #{node.tag.sub("!ruby/object:", "")}"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
result
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def build_hash(node)
|
|
98
|
+
result = {}
|
|
99
|
+
each_pair(node) do |key, value_node|
|
|
100
|
+
value = build_node(value_node)
|
|
101
|
+
|
|
102
|
+
if ARRAY_FIELDS.include?(key)
|
|
103
|
+
value = normalize_array_field(value)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
result[key] = value
|
|
107
|
+
end
|
|
108
|
+
result
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def build_version(node)
|
|
112
|
+
hash = pairs_to_hash(node)
|
|
113
|
+
Gem::Version.new((hash["version"] || hash["value"]).to_s)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
PLATFORM_FIELDS = %w[cpu os version].freeze
|
|
117
|
+
PLATFORM_ALLOWED_IVARS = %w[cpu os version value].freeze
|
|
118
|
+
|
|
119
|
+
def build_platform(node)
|
|
120
|
+
hash = pairs_to_hash(node)
|
|
121
|
+
if (hash.keys & PLATFORM_FIELDS).any?
|
|
122
|
+
Gem::Platform.new([hash["cpu"], hash["os"], hash["version"]])
|
|
123
|
+
elsif hash["value"].is_a?(Array)
|
|
124
|
+
# Malformed platform (e.g. sequence instead of mapping).
|
|
125
|
+
# Return the raw value so yaml_initialize handles it like Psych does.
|
|
126
|
+
hash["value"]
|
|
127
|
+
else
|
|
128
|
+
plat = Gem::Platform.allocate
|
|
129
|
+
hash.each do |k, v|
|
|
130
|
+
plat.instance_variable_set(:"@#{k}", v) if PLATFORM_ALLOWED_IVARS.include?(k)
|
|
131
|
+
end
|
|
132
|
+
plat
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def build_requirement(node)
|
|
137
|
+
r = Gem::Requirement.allocate
|
|
138
|
+
hash = pairs_to_hash(node)
|
|
139
|
+
reqs = hash["requirements"] || hash["value"]
|
|
140
|
+
|
|
141
|
+
if reqs.is_a?(Array) && !reqs.empty?
|
|
142
|
+
safe_reqs = []
|
|
143
|
+
reqs.each do |item|
|
|
144
|
+
if item.is_a?(Array) && item.size == 2
|
|
145
|
+
op = item[0].to_s
|
|
146
|
+
ver = item[1]
|
|
147
|
+
if VALID_OPS.include?(op)
|
|
148
|
+
version_obj = ver.is_a?(Gem::Version) ? ver : Gem::Version.new(ver.to_s)
|
|
149
|
+
safe_reqs << [op, version_obj]
|
|
150
|
+
end
|
|
151
|
+
elsif item.is_a?(String)
|
|
152
|
+
parsed = Gem::Requirement.parse(item)
|
|
153
|
+
safe_reqs << parsed
|
|
154
|
+
end
|
|
155
|
+
rescue Gem::Requirement::BadRequirementError, Gem::Version::BadVersionError
|
|
156
|
+
# Skip malformed items silently
|
|
157
|
+
end
|
|
158
|
+
reqs = safe_reqs unless safe_reqs.empty?
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
r.instance_variable_set(:@requirements, reqs)
|
|
162
|
+
r
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def build_dependency(node)
|
|
166
|
+
hash = pairs_to_hash(node)
|
|
167
|
+
d = Gem::Dependency.allocate
|
|
168
|
+
d.instance_variable_set(:@name, hash["name"])
|
|
169
|
+
|
|
170
|
+
d.instance_variable_set(:@requirement, hash["requirement"] || hash["version_requirements"])
|
|
171
|
+
|
|
172
|
+
raw_type = hash["type"]
|
|
173
|
+
if raw_type
|
|
174
|
+
name = raw_type.to_s.sub(/^:/, "")
|
|
175
|
+
validate_symbol!(name)
|
|
176
|
+
type = name.to_sym
|
|
177
|
+
else
|
|
178
|
+
type = :runtime
|
|
179
|
+
end
|
|
180
|
+
d.instance_variable_set(:@type, type)
|
|
181
|
+
|
|
182
|
+
d.instance_variable_set(:@prerelease, ["true", true].include?(hash["prerelease"]))
|
|
183
|
+
d.instance_variable_set(:@version_requirements, d.instance_variable_get(:@requirement))
|
|
184
|
+
d
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def build_specification(hash)
|
|
188
|
+
spec = Gem::Specification.allocate
|
|
189
|
+
|
|
190
|
+
normalize_specification_version!(hash)
|
|
191
|
+
normalize_array_fields!(hash)
|
|
192
|
+
|
|
193
|
+
spec.yaml_initialize("!ruby/object:Gem::Specification", hash)
|
|
194
|
+
spec
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def pairs_to_hash(node)
|
|
198
|
+
result = {}
|
|
199
|
+
each_pair(node) do |key, value_node|
|
|
200
|
+
result[key] = build_node(value_node)
|
|
201
|
+
end
|
|
202
|
+
result
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def each_pair(node)
|
|
206
|
+
pairs = node.pairs
|
|
207
|
+
i = 0
|
|
208
|
+
while i < pairs.size
|
|
209
|
+
yield pairs[i], pairs[i + 1]
|
|
210
|
+
i += 2
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def validate_tag!(tag)
|
|
215
|
+
return if @permitted_classes.include?(tag)
|
|
216
|
+
raise_disallowed_class!(tag)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def raise_disallowed_class!(tag)
|
|
220
|
+
if defined?(Psych::VERSION)
|
|
221
|
+
raise Psych::DisallowedClass.new("load", tag)
|
|
222
|
+
else
|
|
223
|
+
raise Psych::DisallowedClass, "Tried to load unspecified class: #{tag}"
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def validate_symbol!(name)
|
|
228
|
+
return if @permitted_symbols.empty? || @permitted_symbols.include?(name)
|
|
229
|
+
|
|
230
|
+
label = ":#{name}"
|
|
231
|
+
if defined?(Psych::VERSION)
|
|
232
|
+
raise Psych::DisallowedClass.new("load", label)
|
|
233
|
+
else
|
|
234
|
+
raise Psych::DisallowedClass, "Tried to load unspecified class: #{label}"
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def normalize_specification_version!(hash)
|
|
239
|
+
val = hash["specification_version"]
|
|
240
|
+
return unless val && !val.is_a?(Integer)
|
|
241
|
+
hash["specification_version"] = val.to_i if val.is_a?(String) && /\A\d+\z/.match?(val)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def normalize_array_fields!(hash)
|
|
245
|
+
ARRAY_FIELDS.each do |field|
|
|
246
|
+
hash[field] = normalize_array_field(hash[field]) if hash[field]
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def normalize_array_field(value)
|
|
251
|
+
if value.is_a?(Hash)
|
|
252
|
+
value.values.flatten.compact
|
|
253
|
+
elsif !value.is_a?(Array) && value
|
|
254
|
+
[value].flatten.compact
|
|
255
|
+
else
|
|
256
|
+
value
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The Bundler gem ships this directory but not rubygems/yaml_serializer.rb, and
|
|
4
|
+
# requires this file directly. Bundler 2.4.21 to 4.0.x require
|
|
5
|
+
# "rubygems/yaml_serializer" by name and fall back to their own copy when it is
|
|
6
|
+
# missing. On RubyGems older than 3.4.21, a file under that name in an
|
|
7
|
+
# installed Bundler gem would answer that require instead, and RubyGems would
|
|
8
|
+
# activate that gem under the running Bundler.
|
|
9
|
+
|
|
10
|
+
# Skip reloading when an identical copy (e.g. the one shipped inside the Bundler
|
|
11
|
+
# gem) was already required from a different path, to avoid redefinition warnings.
|
|
12
|
+
return if defined?(Gem::YAMLSerializer)
|
|
13
|
+
|
|
14
|
+
require_relative "psych_errors"
|
|
15
|
+
require_relative "nodes"
|
|
16
|
+
require_relative "parser"
|
|
17
|
+
require_relative "builder"
|
|
18
|
+
require_relative "emitter"
|
|
19
|
+
|
|
20
|
+
module Gem
|
|
21
|
+
module YAMLSerializer
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
def dump(obj)
|
|
25
|
+
Emitter.new.emit(obj)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def load(str, permitted_classes: [], permitted_symbols: [], aliases: true)
|
|
29
|
+
ast = Parser.new(str).parse
|
|
30
|
+
result = Builder.new(
|
|
31
|
+
permitted_classes: permitted_classes,
|
|
32
|
+
permitted_symbols: permitted_symbols,
|
|
33
|
+
aliases: aliases
|
|
34
|
+
).build(ast)
|
|
35
|
+
# Bundler 4.0 and older call Hash methods on what this returns for
|
|
36
|
+
# .bundle/config, which is just "---" once its last key is unset, so
|
|
37
|
+
# nil stays a Hash here as it did in RubyGems 4.0.
|
|
38
|
+
result.nil? ? {} : result
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|