From 40e49fa0d8c4e8b27cfd8eba3eb6c9ffcdaabef7 Mon Sep 17 00:00:00 2001 From: danielnachun Date: Mon, 6 Dec 2021 02:10:55 -0800 Subject: [PATCH] software_spec.rb: change compatible_location --- Library/Homebrew/software_spec.rb | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 85012c9b4f..e7270754de 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -347,6 +347,11 @@ class Bottle @spec.compatible_locations?(tag: @tag) end + # Should the build prefix be relocated? + def skip_prefix_relocation? + @spec.skip_prefix_relocation?(tag: @tag) + end + # Does the bottle need to be relocated? def skip_relocation? @spec.skip_relocation?(tag: @tag) @@ -473,6 +478,8 @@ class Bottle end class BottleSpecification + RELOCATABLE_CELLARS = [:any, :any_skip_relocation].freeze + extend T::Sig attr_rw :rebuild @@ -513,7 +520,30 @@ class BottleSpecification tag.default_cellar end - return true if [:any, :any_skip_relocation].include?(cellar) + return true if RELOCATABLE_CELLARS.include?(cellar) + + prefix = Pathname(cellar).parent.to_s + + cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"] + prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"] + + compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable + compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable + + compatible_cellar && compatible_prefix + end + + # Should the build prefix for the {Bottle} this {BottleSpecification} belongs to be relocated? + sig { params(tag: Utils::Bottles::Tag).returns(T::Boolean) } + def skip_prefix_relocation?(tag: Utils::Bottles.tag) + spec = collector.specification_for(tag) + cellar = if spec.present? + spec.cellar + else + tag.default_cellar + end + + return true if RELOCATABLE_CELLARS.include?(cellar) prefix = Pathname(cellar).parent.to_s