More bottling HOMEBREW_LIBRARY changes
- Refuse to create bottles which have non-relocatable references to `HOMEBREW_LIBRARY`. This allows us to make all bottles ignore where `HOMEBREW_REPOSITORY` is (even those that aren't `cellar :any`). I cannot see any circumstances in which any bottle should link to anything within `HOMEBREW_REPOSITORY`. - Remove audit that becomes unnecessary given the above change. - Relocate references to `@HOMEBREW_LIBRARY@` but don't actually write any references yet. This will allow us to move to using `@HOMEBREW_LIBRARY` and remove all relocation of `HOMEBREW_REPOSITORY` in a future release (2.7.1, most likely).
This commit is contained in:
parent
be893d5a56
commit
0bbf965807
@ -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)
|
||||
|
||||
@ -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?))
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -4,14 +4,17 @@
|
||||
class Keg
|
||||
PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@"
|
||||
CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@"
|
||||
LIBRARY_PLACEHOLDER = "@@HOMEBREW_LIBRARY@@"
|
||||
|
||||
# TODO: delete these after Homebrew 2.7.0 is released.
|
||||
REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@"
|
||||
REPOSITORY_LIBRARY_PLACEHOLDER = "#{REPOSITORY_PLACEHOLDER}/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"
|
||||
|
||||
Relocation = Struct.new(:old_prefix, :old_cellar, :old_repository, :old_library,
|
||||
:new_prefix, :new_cellar, :new_repository, :new_library) do
|
||||
Relocation = Struct.new(:old_prefix, :old_cellar, :old_library,
|
||||
:new_prefix, :new_cellar, :new_library,
|
||||
# TODO: delete these after Homebrew 2.7.0 is released.
|
||||
:old_repository, :new_repository,
|
||||
: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 +46,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 +63,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_library: LIBRARY_PLACEHOLDER,
|
||||
new_prefix: HOMEBREW_PREFIX.to_s,
|
||||
new_cellar: HOMEBREW_CELLAR.to_s,
|
||||
new_library: HOMEBREW_LIBRARY.to_s,
|
||||
# TODO: delete these after Homebrew 2.7.0 is released.
|
||||
old_repository: REPOSITORY_PLACEHOLDER,
|
||||
new_repository: HOMEBREW_REPOSITORY.to_s,
|
||||
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 +87,16 @@ 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
|
||||
# TODO: delete this after Homebrew 2.7.0 is released.
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user