Skip to content

Commit c9059ed

Browse files
ntkmehsbt
authored andcommitted
Refactor windows toolchain selection
1 parent 78c62f2 commit c9059ed

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

‎generate-windows-versions.rb‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ def validate(versions, allowed_urls_regexps)
8181
base_url = 'https://github.com/ruby/setup-msys2-gcc/releases/latest/download/windows-toolchain.json'
8282
windows_toolchain = JSON.parse(URI.open(base_url, &:read), symbolize_names: true)
8383

84+
find_toolchain = -> platform, version {
85+
toolchain = windows_toolchain.select do |pkg|
86+
pkg[:platform] == platform && pkg[:required_ruby_version].any? do |requirement|
87+
Gem::Requirement.new(requirement).satisfied_by?(version)
88+
end
89+
end
90+
91+
unless toolchain.one?
92+
raise "#{toolchain.empty? ? 'no' : 'multiple'} toolchains found for #{platform} #{version}: #{toolchain}"
93+
end
94+
95+
toolchain.first
96+
}
97+
8498
versions.each do |raw_version, archs|
8599
version = Gem::Version.correct?(raw_version) ? Gem::Version.new(raw_version) : head_version
86100

@@ -103,18 +117,9 @@ def validate(versions, allowed_urls_regexps)
103117
end
104118
end
105119

106-
toolchain =
107-
windows_toolchain.select do |pkg|
108-
pkg[:platform] == platform && pkg[:required_ruby_version].any? do |requirement|
109-
Gem::Requirement.new(requirement).satisfied_by?(version)
110-
end
111-
end
112-
113-
unless toolchain.one?
114-
raise "#{toolchain.empty? ? 'no' : 'multiple'} toolchains found for #{raw_version} #{raw_arch}: #{toolchain}"
115-
end
120+
toolchain = find_toolchain.(platform, version)
116121

117-
archs[raw_arch] = URI.join(base_url, toolchain.first[:href]).to_s
122+
archs[raw_arch] = URI.join(base_url, toolchain[:href]).to_s
118123
end
119124
end
120125

0 commit comments

Comments
 (0)