Remove the formula install-step var default

Formula install-step paths now serialise only a base that was explicitly
specified. RuboCop prevents relative official-tap paths from relying on the
current working directory.

Run structured-only API post-installs from the current JSON data so old
formula snapshots embedded in bottles cannot restore the removed default.
Keep using bottle snapshots for formulae that still have Ruby hooks.
This commit is contained in:
Mike McQuaid
2026-08-06 08:30:57 +01:00
parent 44f506abd4
commit 5e4dba4d6b
4 changed files with 53 additions and 8 deletions
-3
View File
@@ -4086,9 +4086,6 @@ class Formula
current_steps.concat(
if block
Homebrew::InstallSteps::DSL.build(
# TODO: Remove the undocumented `default_base: :var` compatibility default after official taps use
# explicit bases.
default_base: :var,
default_source_base: :prefix,
default_target_base: :prefix,
&block
+7 -3
View File
@@ -1354,10 +1354,10 @@ on_request: installed_on_request?, options:)
@show_summary_heading = true
end
sig { returns(Pathname) }
sig { returns(T.any(String, Pathname)) }
def post_install_formula_path
# Use the formula from the keg when any of the following is true:
# * We're installing from the JSON API
# * We're installing from the JSON API and it has a Ruby post-install hook
# * We're installing a local bottle file
# * We're building from source
# * The formula doesn't exist in the tap (or the tap isn't installed)
@@ -1372,7 +1372,11 @@ on_request: installed_on_request?, options:)
return tap_formula_path if installed_prefix.nil?
keg_formula_path = installed_prefix/".brew/#{formula.name}.rb"
return keg_formula_path if formula.loaded_from_api?
if formula.loaded_from_api?
return formula.full_name unless formula.post_install_defined?
return keg_formula_path
end
return keg_formula_path if formula.local_bottle_path
return keg_formula_path if build_from_source?
@@ -181,6 +181,35 @@ RSpec.describe FormulaInstaller do
end
end
describe "#post_install_formula_path" do
it "uses the API formula for structured-only post-installs" do
formula = formula("api-install-steps") do
T.bind(self, T.class_of(Formula))
url "foo-1.0"
end
installer = described_class.new(formula)
allow(formula).to receive_messages(any_installed_prefix: mktmpdir, loaded_from_api?: true,
post_install_defined?: false)
expect(installer.post_install_formula_path).to eq(formula.full_name)
end
it "uses the keg formula for API post-installs with Ruby hooks" do
formula = formula("api-post-install-hook") do
T.bind(self, T.class_of(Formula))
url "foo-1.0"
end
installer = described_class.new(formula)
installed_prefix = mktmpdir
allow(formula).to receive_messages(any_installed_prefix: installed_prefix, loaded_from_api?: true,
post_install_defined?: true)
expect(installer.post_install_formula_path).to eq(installed_prefix/".brew/api-post-install-hook.rb")
end
end
describe "#pour" do
let(:f) do
formula("missing-bottle-tab") do
+17 -2
View File
@@ -1193,8 +1193,8 @@ RSpec.describe Formula do
url "foo-1.0"
post_install_steps do
mkdir_p "log/foo"
touch "foo/marker"
mkdir_p "log/foo", base: :var
touch "foo/marker", base: :var
move "move-source", "move-target"
move_contents "children-source", "children-target"
symlink "move-target", "linked-target", source_base: :relative, remove_on_uninstall: true
@@ -1226,6 +1226,21 @@ RSpec.describe Formula do
expect(f.to_hash["post_install_steps"]).to eq(f.post_install_steps)
end
specify "#post_install_steps does not default paths to var" do
f = formula do
T.bind(self, T.class_of(Formula))
url "foo-1.0"
post_install_steps do
touch "foo/marker"
end
end
expect(f.post_install_steps).to eq([
{ "type" => "touch", "path" => { "path" => "foo/marker" } },
])
end
specify "#post_install_steps_defined? with an empty block" do
f = formula do
T.bind(self, T.class_of(Formula))