Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support of formulae aliases in taps #16637

Conversation

sjorek
Copy link
Contributor

@sjorek sjorek commented Feb 11, 2024

Resolves: #16636

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
    • … but I have the same failures in master and my PR (49 failures)

Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this fix looks correct. Thanks for taking the initiative to open a PR. However the regex should not get moved as mentioned in my comments.

Library/Homebrew/formulary.rb Show resolved Hide resolved
Library/Homebrew/formulary.rb Show resolved Hide resolved
@sjorek sjorek force-pushed the issue-16636-fix-support-of-formulae-aliases-in-taps branch from 38f3ea7 to d01de75 Compare February 11, 2024 10:41
@@ -949,6 +950,7 @@ def self.tap_loader_for(tapped_name, warn:)
end
end

name = name.split("/").last if name != :nil && type == :alias
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in #16623 (comment), this is the exact same fix. Can you move the split into the conditional above to avoid checking another condition here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, your suggestion is simpler than what I proposed earlier. Using String#split should avoid the nil type errors entirely too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apainintheneck I'm not sure who is targeted by @reitermarkus's wish to move the split - shall I do it?
And if yes; I'm not sure where exactly to move it to?

So like this?

diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 9a1a7cc2c..cabc1f74a 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -909,7 +909,7 @@ module Formulary
     alias_name = tap.core_tap? ? name : "#{tap}/#{name}"
 
     if (possible_alias = tap.alias_table[alias_name].presence)
-      name = possible_alias
+      name = tap.core_tap? ? possible_alias : possible_alias.split("/").last
       type = :alias
     elsif (new_name = tap.formula_renames[name].presence)
       old_name = name
@@ -950,7 +950,6 @@ module Formulary
       end
     end
 
-    name = name.split("/").last if name != :nil && type == :alias
     path = find_formula_in_tap(name, tap)
     TapLoader.new(name, path, tap: tap)
   end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or like this?

diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 9a1a7cc2c..952ee50fd 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -948,9 +948,10 @@ module Formulary
       elsif Homebrew::API::Formula.all_formulae.key?(name)
         return FormulaAPILoader.new(name)
       end
+    elsif name != :nil && type == :alias
+      name = name.split("/").last
     end
 
-    name = name.split("/").last if name != :nil && type == :alias
     path = find_formula_in_tap(name, tap)
     TapLoader.new(name, path, tap: tap)
   end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter seems to be error-prone … eg. when tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api? is true and the API-lookup Homebrew::API::Formula.all_formulae.key?(name) is false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apainintheneck I'm not sure who is targeted by @reitermarkus's wish to move the split - shall I do it? And if yes; I'm not sure where exactly to move it to?

So like this?

diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 9a1a7cc2c..cabc1f74a 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -909,7 +909,7 @@ module Formulary
     alias_name = tap.core_tap? ? name : "#{tap}/#{name}"
 
     if (possible_alias = tap.alias_table[alias_name].presence)
-      name = possible_alias
+      name = tap.core_tap? ? possible_alias : possible_alias.split("/").last
       type = :alias
     elsif (new_name = tap.formula_renames[name].presence)
       old_name = name
@@ -950,7 +950,6 @@ module Formulary
       end
     end
 
-    name = name.split("/").last if name != :nil && type == :alias
     path = find_formula_in_tap(name, tap)
     TapLoader.new(name, path, tap: tap)
   end

This is pretty much what I was thinking. I'll update it now and test it locally to make sure it works.

@apainintheneck
Copy link
Contributor

I'm also not sure why this test didn't catch this problem.

it "returns a Formula from an Alias path" do
alias_dir = tap.path/"Aliases"
alias_dir.mkpath
FileUtils.ln_s formula_path, alias_dir/"bar"
expect(described_class.factory("bar")).to be_a(Formula)
end

@sjorek
Copy link
Contributor Author

sjorek commented Feb 11, 2024

I'm also not sure why this test didn't catch this problem.

it "returns a Formula from an Alias path" do
alias_dir = tap.path/"Aliases"
alias_dir.mkpath
FileUtils.ln_s formula_path, alias_dir/"bar"
expect(described_class.factory("bar")).to be_a(Formula)
end

… I think because the spec just asks for formula-name and not for a tap/formula-name.

@apainintheneck
Copy link
Contributor

I'm also not sure why this test didn't catch this problem.

it "returns a Formula from an Alias path" do
alias_dir = tap.path/"Aliases"
alias_dir.mkpath
FileUtils.ln_s formula_path, alias_dir/"bar"
expect(described_class.factory("bar")).to be_a(Formula)
end

… I think because the spec just asks for formula-name and not for a tap/formula-name.

That's exactly it. I added a regression test that checks for that and it fails on the master branch and works on this one.

@apainintheneck
Copy link
Contributor

/u/l/Homebrew (issue-16636-fix-support-of-formulae-aliases-in-taps|✚2) $ brew info yaml@8.3
==> shivammathur/extensions/yaml@8.3: stable 2.2.3, HEAD
Yaml PHP extension
https://github.com/php/pecl-file_formats-yaml
Not installed
From: https://github.com/shivammathur/homebrew-extensions/blob/HEAD/Formula/yaml@8.3.rb
License: PHP-3.01
==> Dependencies
Build: autoconf ✔, pkg-config ✔, shivammathur/php/php@8.3 ✘
Required: libyaml ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
To finish installing yaml for PHP 8.3:
  * /usr/local/etc/php/8.3/conf.d/20-yaml.ini was created,"
    do not forget to remove it upon extension removal."
  * Validate installation by running php -m
/u/l/Homebrew (issue-16636-fix-support-of-formulae-aliases-in-taps|✔) $ brew info shivammathur/extensions/yaml@8.3
==> shivammathur/extensions/yaml@8.3: stable 2.2.3, HEAD
Yaml PHP extension
https://github.com/php/pecl-file_formats-yaml
Not installed
From: https://github.com/shivammathur/homebrew-extensions/blob/HEAD/Formula/yaml@8.3.rb
License: PHP-3.01
==> Dependencies
Build: autoconf ✔, pkg-config ✔, shivammathur/php/php@8.3 ✘
Required: libyaml ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
To finish installing yaml for PHP 8.3:
  * /usr/local/etc/php/8.3/conf.d/20-yaml.ini was created,"
    do not forget to remove it upon extension removal."
  * Validate installation by running php -m

It seems to work now.

Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help with fixing this bug @sjorek!

Closes #16636

@apainintheneck apainintheneck added the critical Critical change which should be shipped as soon as possible. label Feb 11, 2024
@apainintheneck apainintheneck merged commit ac7e759 into Homebrew:master Feb 11, 2024
25 checks passed
@reitermarkus
Copy link
Member

Thanks for adding the test here, @apainintheneck!

@MikeMcQuaid
Copy link
Member

Thanks for this @sjorek and for the review and merge @apainintheneck and @reitermarkus!

@github-actions github-actions bot added the outdated PR was locked due to age label Mar 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support of formulae aliases in taps is broken
4 participants