diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 10f8f2c283..6d37cb4d30 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -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 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 diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index e55e2afa31..74ee7d8fed 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -61,6 +61,9 @@ module Homebrew description: "Target tap repository (default: `homebrew/core`)." flag "--root-url=", description: "Use the specified 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 diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index e21b98d9dd..41a1fd9227 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -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 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? diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb index c794479803..3564901578 100644 --- a/Library/Homebrew/test/dev-cmd/bottle_spec.rb +++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb @@ -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,