Merge pull request #11259 from bluelabsio/bottle-root-url-specs

dev-cmd/bottle: Support adding root_url specs to bottle spec
This commit is contained in:
Mike McQuaid 2021-04-29 19:54:53 +01:00 committed by GitHub
commit 2fa973bb3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 6 deletions

View File

@ -16,7 +16,9 @@ BOTTLE_ERB = <<-EOS
bottle do
<% if [HOMEBREW_BOTTLE_DEFAULT_DOMAIN.to_s,
"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles"].exclude?(root_url) %>
root_url "<%= root_url %>"
root_url "<%= root_url %>"<% if root_url_using.present? %>,
using: <%= root_url_using %>
<% end %>
<% end %>
<% if rebuild.positive? %>
rebuild <%= rebuild %>
@ -75,6 +77,9 @@ module Homebrew
description: "Specify a committer name and email in `git`'s standard author format."
flag "--root-url=",
description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default."
flag "--root-url-using=",
description: "Use the specified download strategy class for downloading the bottle's URL instead of "\
"Homebrew's default."
conflicts "--no-rebuild", "--keep-old"
@ -221,7 +226,7 @@ module Homebrew
%Q(#{line}"#{digest}")
end
def bottle_output(bottle)
def bottle_output(bottle, root_url_using)
cellars = bottle.checksums.map do |checksum|
cellar = checksum["cellar"]
next unless cellar_parameter_needed? cellar
@ -244,6 +249,7 @@ module Homebrew
end
erb_binding = bottle.instance_eval { binding }
erb_binding.local_variable_set(:sha256_lines, sha256_lines)
erb_binding.local_variable_set(:root_url_using, root_url_using)
erb = ERB.new BOTTLE_ERB
erb.result(erb_binding).gsub(/^\s*$\n/, "")
end
@ -529,7 +535,7 @@ module Homebrew
end
end
output = bottle_output bottle
output = bottle_output(bottle, args.root_url_using)
puts "./#{local_filename}"
puts output
@ -641,7 +647,7 @@ module Homebrew
end
unless args.write?
puts bottle_output(bottle)
puts bottle_output(bottle, args.root_url_using)
next
end
@ -720,7 +726,7 @@ module Homebrew
update_or_add = checksums.nil? ? "add" : "update"
checksums&.each(&bottle.method(:sha256))
output = bottle_output(bottle)
output = bottle_output(bottle, args.root_url_using)
puts output
case update_or_add

View File

@ -61,6 +61,9 @@ module Homebrew
description: "Target tap repository (default: `homebrew/core`)."
flag "--root-url=",
description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default."
flag "--root-url-using=",
description: "Use the specified download strategy class for downloading the bottle's URL instead of "\
"Homebrew's default."
flag "--bintray-mirror=",
description: "Use the specified Bintray repository to automatically mirror stable URLs "\
"defined in the formulae (default: `mirror`)."
@ -443,6 +446,7 @@ module Homebrew
upload_args << "--warn-on-upload-failure" if args.warn_on_upload_failure?
upload_args << "--committer=#{args.committer}" if args.committer
upload_args << "--root-url=#{args.root_url}" if args.root_url
upload_args << "--root-url-using=#{args.root_url_using}" if args.root_url_using
upload_args << if archive_item.present?
"--archive-item=#{archive_item}"
else

View File

@ -40,6 +40,9 @@ module Homebrew
description: "Upload to the specified GitHub organisation's GitHub Packages (default: `homebrew`)."
flag "--root-url=",
description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default."
flag "--root-url-using=",
description: "Use the specified download strategy class for downloading the bottle's URL instead of "\
"Homebrew's default."
named_args :none
end
@ -114,6 +117,7 @@ module Homebrew
bottle_args << "--root-url=#{args.root_url}" if args.root_url
bottle_args << "--committer=#{args.committer}" if args.committer
bottle_args << "--no-commit" if args.no_commit?
bottle_args << "--root-url-using=#{args.root_url_using}" if args.root_url_using
bottle_args += json_files
if args.dry_run?

View File

@ -624,6 +624,39 @@ describe "brew bottle" do
end
end
end
describe "::bottle_output" do
it "includes a custom root_url" do
bottle = BottleSpecification.new
bottle.root_url("https://example.com")
bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
expect(homebrew.bottle_output(bottle, nil)).to eq(
<<~RUBY.indent(2),
bottle do
root_url "https://example.com"
sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e"
end
RUBY
)
end
it "includes download strategy for custom root_url" do
bottle = BottleSpecification.new
bottle.root_url("https://example.com")
bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
expect(homebrew.bottle_output(bottle, "ExampleStrategy")).to eq(
<<~RUBY.indent(2),
bottle do
root_url "https://example.com",
using: ExampleStrategy
sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e"
end
RUBY
)
end
end
end
end
@ -636,7 +669,7 @@ def stub_hash(parameters)
"path":"#{parameters[:path]}"
},
"bottle":{
"root_url":"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}",
"root_url":"#{parameters[:root_url] || HOMEBREW_BOTTLE_DEFAULT_DOMAIN}",
"prefix":"/usr/local",
"cellar":"#{parameters[:cellar]}",
"rebuild":0,