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
shebang: raise error if no rewriting #12820
Conversation
Review period will end on 2022-02-02 at 05:20:28 UTC. |
Makes sense to me, thanks @branchvincent! |
Review period skipped due to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @branchvincent! Looks good to me too!
I nominate this PR for the "best Homebrew feature of February 2022 award" :) |
thanks everyone! |
Perhaps I'm doing something wrong, but after this PR hit, a |
For anyone getting the error:
You can fix this by locally by temporarily reverting this commit: 4c65c27cff75a92d2a20a1f56e51f9f91f4da4e1 #12826 |
@meissnem @joshgoebel thanks for the heads up, this was fixed by reverting in #12828. sorry for the breakage |
I'm still not entirely sure this is PR is wrong. It seems reasonable to have an error when there's no replacement, although maybe a warning is a better option so it doesn't break things. How often do we use a single If that's not worth the effort, we can use RuboCop to ensure that you don't pass a wildcard path (e.g. I guess another option is Homebrew/homebrew-core#94328 — just avoid putting |
I'm just a user and formula-dabbler with homebrew so I might be way off base -- but the postgresql formula is not calling |
@meissnem what was the text of the warning you received when you tried to install? |
But as I said, the return code was As a work-around, I added everything that is installed to |
Gotcha. I think that would be handled by raising a |
Agreed on this point. The PR was trying to do a good thing (report errors with re-writing), just didn't take these loop cases into account.
I think there is a potential issue with wildcards in general... but I'm not sure how you fix it... being more general can make the formulas more resilient. For example consider something like: This works (if you add more scripts)... until someone adds a Python script with no extension
|
Personally, I'd opt for a simpler approach: add an argument to We can then disable the check for any Either that or we fix all the |
If it doesn't break backward compatibility too much, I'd like to see the error message shown by default but I won't complain if we need to do it the other way. |
Yea, my idea was for Alternatively, we could probably just check for a shebang here before attempting to rewrite it: brew/Library/Homebrew/cleaner.rb Lines 130 to 141 in 8e97f60
Reading the first two bytes should be enough. No strong preference between the two, although I suspect avoiding the file system when it isn't really needed is a good idea. |
As it's currently written we shouldn't really need to do anything there. |
found = T.let(false, T::Boolean) | ||
paths.each do |f| | ||
f = Pathname(f) | ||
next unless f.file? | ||
next unless rewrite_info.regex.match?(f.read(rewrite_info.max_length)) | ||
|
||
Utils::Inreplace.inreplace f.to_s, rewrite_info.regex, "#!#{rewrite_info.replacement}" | ||
found = true | ||
end | ||
|
||
raise "No matching files found to rewrite shebang" unless found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found = T.let(false, T::Boolean) | |
paths.each do |f| | |
f = Pathname(f) | |
next unless f.file? | |
next unless rewrite_info.regex.match?(f.read(rewrite_info.max_length)) | |
Utils::Inreplace.inreplace f.to_s, rewrite_info.regex, "#!#{rewrite_info.replacement}" | |
found = true | |
end | |
raise "No matching files found to rewrite shebang" unless found | |
found = paths.all? do |f| | |
f = Pathname(f) | |
next false unless f.file? | |
next true unless rewrite_info.regex.match?(f.read(rewrite_info.max_length)) | |
Utils::Inreplace.inreplace f.to_s, rewrite_info.regex, "#!#{rewrite_info.replacement}" | |
true | |
end | |
raise "No matching files found to rewrite shebang" unless found |
@Rylan12 maybe something like this then?
#all?
probably doesn't work though, since I suspect it is greedy (bails out of the iterator as soon as it sees false
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that looks like it would work (I think you're right about #all?
though so we might have to write that ourselves).
We also might want to change the error message since it's not necessarily that no files were found just that one file wasn't.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?In Homebrew/homebrew-core#94202, we encountered a bug where
rewrite_shebang
wasn't actually rewriting any shebang due to a misspelled filename. This change prevents this class of bugs by erroring when no replacement occurs.This is my first PR here, so any feedback is greatly appreciated 😄