diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index d62fc83069..eee9f31c5b 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -254,7 +254,6 @@ module Homebrew tar_path = Pathname.pwd/tar_filename prefix = HOMEBREW_PREFIX.to_s - repository = HOMEBREW_REPOSITORY.to_s cellar = HOMEBREW_CELLAR.to_s ohai "Bottling #{filename}..." @@ -326,13 +325,24 @@ module Homebrew ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d.]+/libexec} end + repository_reference = if HOMEBREW_PREFIX == HOMEBREW_REPOSITORY + HOMEBREW_LIBRARY + else + HOMEBREW_REPOSITORY + end.to_s + if keg_contain?(repository_reference, keg, ignores, args: args) + odie "Bottle contains non-relocatable reference to #{repository_reference}!" + end + relocatable = true if args.skip_relocation? skip_relocation = true else relocatable = false if keg_contain?(prefix_check, keg, ignores, formula_and_runtime_deps_names, args: args) - relocatable = false if keg_contain?(repository, keg, ignores, args: args) relocatable = false if keg_contain?(cellar, keg, ignores, formula_and_runtime_deps_names, args: args) + if keg_contain?(HOMEBREW_LIBRARY.to_s, keg, ignores, formula_and_runtime_deps_names, args: args) + relocatable = false + end if prefix != prefix_check relocatable = false if keg_contain_absolute_symlink_starting_with?(prefix, keg, args: args) relocatable = false if keg_contain?("#{prefix}/etc", keg, ignores, args: args) diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index cd568a8466..f896caaf47 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -7,10 +7,6 @@ require "utils/shell" # # @api private module FormulaCellarChecks - # If the location of HOMEBREW_LIBRARY changes - # keg_relocate.rb, test/global_spec.rb, and this constant need to change. - REPOSITORY_AND_NOT_LIBRARY_REGEX = %r{#{HOMEBREW_REPOSITORY}(?!/Library/)}.freeze - def check_env_path(bin) # warn the user if stuff was installed outside of their PATH return unless bin.directory? @@ -211,26 +207,6 @@ module FormulaCellarChecks EOS end - def check_repository_references(prefix) - return if HOMEBREW_PREFIX != HOMEBREW_REPOSITORY - return unless prefix.directory? - - keg = Keg.new(prefix) - - matches = [] - keg.each_unique_file_matching(HOMEBREW_REPOSITORY) do |f| - matches << f.relative_path_from(keg.to_path) if f.read.match? REPOSITORY_AND_NOT_LIBRARY_REGEX - end - - return if matches.empty? - - <<~EOS - Files were found with references to the Homebrew repository directory - that are outside of the Library directory. The offending files are: - #{matches * "\n "} - EOS - end - def check_shim_references(prefix) return unless prefix.directory? @@ -316,7 +292,6 @@ module FormulaCellarChecks problem_if_output(check_elisp_dirname(formula.share, formula.name)) problem_if_output(check_elisp_root(formula.share, formula.name)) problem_if_output(check_python_packages(formula.lib, formula.deps)) - problem_if_output(check_repository_references(formula.prefix)) problem_if_output(check_shim_references(formula.prefix)) problem_if_output(check_plist(formula.prefix, formula.plist)) problem_if_output(check_python_symlinks(formula.name, formula.keg_only?)) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index d7983462ca..5a3a38ff8e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -175,6 +175,7 @@ class FormulaInstaller bottle = formula.bottle_specification unless bottle.compatible_locations? + # TODO: delete HOMEBREW_REPOSITORY reference after Homebrew 2.7.0 is released. if output_warning opoo <<~EOS Building #{formula.full_name} from source as the bottle needs: diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index a10ebe27b2..1456854222 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -5,13 +5,15 @@ class Keg PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@" CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@" REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@" + LIBRARY_PLACEHOLDER = "@@HOMEBREW_LIBRARY@@" - # If the location of HOMEBREW_LIBRARY changes - # formula_cellar_checks.rb, test/global_spec.rb, and this constant need to change. - LIBRARY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@/Library" + # TODO: delete this after Homebrew 2.7.0 is released. + REPOSITORY_LIBRARY_PLACEHOLDER = "#{REPOSITORY_PLACEHOLDER}/Library" Relocation = Struct.new(:old_prefix, :old_cellar, :old_repository, :old_library, - :new_prefix, :new_cellar, :new_repository, :new_library) do + :new_prefix, :new_cellar, :new_repository, :new_library, + # TODO: delete these after Homebrew 2.7.0 is released. + :old_repository_library, :new_repository_library) do # Use keyword args instead of positional args for initialization. def initialize(**kwargs) super(*members.map { |k| kwargs[k] }) @@ -43,12 +45,16 @@ class Keg relocation = Relocation.new( old_prefix: HOMEBREW_PREFIX.to_s, old_cellar: HOMEBREW_CELLAR.to_s, - old_repository: HOMEBREW_REPOSITORY.to_s, - old_library: HOMEBREW_LIBRARY.to_s, new_prefix: PREFIX_PLACEHOLDER, new_cellar: CELLAR_PLACEHOLDER, + # TODO: delete these after Homebrew 2.7.0 is released. + old_library: HOMEBREW_LIBRARY.to_s, + new_library: REPOSITORY_LIBRARY_PLACEHOLDER, + old_repository: HOMEBREW_REPOSITORY.to_s, new_repository: REPOSITORY_PLACEHOLDER, - new_library: LIBRARY_PLACEHOLDER, + # TODO: add these after Homebrew 2.7.0 is released. + # old_library: HOMEBREW_LIBRARY.to_s, + # new_library: LIBRARY_PLACEHOLDER, ) relocate_dynamic_linkage(relocation) replace_text_in_files(relocation) @@ -56,14 +62,17 @@ class Keg def replace_placeholders_with_locations(files, skip_linkage: false) relocation = Relocation.new( - old_prefix: PREFIX_PLACEHOLDER, - old_cellar: CELLAR_PLACEHOLDER, - old_repository: REPOSITORY_PLACEHOLDER, - old_library: LIBRARY_PLACEHOLDER, - new_prefix: HOMEBREW_PREFIX.to_s, - new_cellar: HOMEBREW_CELLAR.to_s, - new_repository: HOMEBREW_REPOSITORY.to_s, - new_library: HOMEBREW_LIBRARY.to_s, + old_prefix: PREFIX_PLACEHOLDER, + old_cellar: CELLAR_PLACEHOLDER, + old_repository: REPOSITORY_PLACEHOLDER, + old_library: LIBRARY_PLACEHOLDER, + new_prefix: HOMEBREW_PREFIX.to_s, + new_cellar: HOMEBREW_CELLAR.to_s, + new_repository: HOMEBREW_REPOSITORY.to_s, + new_library: HOMEBREW_LIBRARY.to_s, + # TODO: delete these after Homebrew 2.7.0 is released. + old_repository_library: REPOSITORY_LIBRARY_PLACEHOLDER, + new_repository_library: HOMEBREW_LIBRARY.to_s, ) relocate_dynamic_linkage(relocation) unless skip_linkage replace_text_in_files(relocation, files: files) @@ -77,16 +86,15 @@ class Keg s = first.open("rb", &:read) replacements = { - relocation.old_prefix => relocation.new_prefix, - relocation.old_cellar => relocation.new_cellar, - } + relocation.old_prefix => relocation.new_prefix, + relocation.old_cellar => relocation.new_cellar, + relocation.old_library => relocation.new_library, + # TODO: delete this after Homebrew 2.7.0 is released. + relocation.old_repository_library => relocation.new_repository_library, + }.compact # when HOMEBREW_PREFIX == HOMEBREW_REPOSITORY we should use HOMEBREW_PREFIX for all relocations to avoid # being unable to differentiate between them. - if HOMEBREW_PREFIX == HOMEBREW_REPOSITORY - replacements[relocation.old_library] = relocation.new_library - else - replacements[relocation.old_repository] = relocation.new_repository - end + replacements[relocation.old_repository] = relocation.new_repository if HOMEBREW_PREFIX != HOMEBREW_REPOSITORY changed = s.gsub!(Regexp.union(replacements.keys.sort_by(&:length).reverse), replacements) next unless changed diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index a85287fab5..b5a5542a34 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -389,6 +389,7 @@ class BottleSpecification # Only check the repository matches if the prefix is the default. # This is because the bottle DSL does not allow setting a custom repository # but does allow setting a custom prefix. + # TODO: delete this after Homebrew 2.7.0 is released. compatible_repository = if Homebrew.default_prefix?(prefix) repository == HOMEBREW_REPOSITORY.to_s else diff --git a/Library/Homebrew/test/global_spec.rb b/Library/Homebrew/test/global_spec.rb index 644c32bd16..6c34ca8838 100644 --- a/Library/Homebrew/test/global_spec.rb +++ b/Library/Homebrew/test/global_spec.rb @@ -8,10 +8,4 @@ describe "brew", :integration_test do .and not_to_output.to_stderr .and be_a_success end - - # If the location of HOMEBREW_LIBRARY changes - # keg_relocate.rb, formula_cellar_checks.rb, and this test need to change. - it "ensures that HOMEBREW_LIBRARY=HOMEBREW_REPOSITORY/Library" do - expect(HOMEBREW_LIBRARY.to_s).to eq("#{HOMEBREW_REPOSITORY}/Library") - end end