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

Virtualenv relocation fixes #2442

Merged
merged 5 commits into from
Apr 5, 2017

Conversation

tdsmith
Copy link
Contributor

@tdsmith tdsmith commented Apr 2, 2017

Fix a couple of issues discovered in Homebrew/homebrew-core#9424 that affect the relocatability of virtualenv formulae.

When we're assessing whether a bottle is relocatable, we shouldn't have
to descend into symlink paths we encounter. This is supposed to be the
default behavior but it doesn't appear to be (perhaps because we pass a
symlink to the keg on the command line?).

All of the switches that control this behavior differ between BSD and
GNU grep, so sniff the grep flavor first.
ln_sf does the right thing when `dest` is a symlink pointing to a file:
the symlink gets overwritten with a link pointing to the new src. But
when dest points to a directory, we create a new symlink inside the
folder dest points to, which doesn't help us at all.
@@ -97,7 +99,12 @@ def detect_cxx_stdlibs(_options = {})
end

def each_unique_file_matching(string)
Utils.popen_read("/usr/bin/fgrep", "-lr", string, to_s) do |io|
bsd = `/usr/bin/fgrep -V`.include?("BSD grep")
Copy link
Member

Choose a reason for hiding this comment

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

Favour Utils.popen_read over backticks.

Copy link
Member

Choose a reason for hiding this comment

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

Also I reckon BSD grep logic should live in https://github.com/Homebrew/brew/blob/master/Library/Homebrew/extend/os/mac/keg_relocate.rb or the converse in os/linux

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'd have to copy the body of the method into both os/mac/keg_relocate.rb and os/linux/keg_relocate.rb and just change the arguments that are being passed to grep. Is that right? It feels repetitive.

Why not backticks, out of curiosity? Consistency or something more subtle?

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 do I want to write e.g. a private each_unique_file_matching_grep_args method for each OS?)

Copy link
Member

Choose a reason for hiding this comment

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

Why not backticks, out of curiosity? Consistency or something more subtle?

I dunno, it's just a pattern we've been following here for a while. I think we handle them slightly differently. I don't care enormously, to be honest.

I think I'd have to copy the body of the method into both os/mac/keg_relocate.rb and os/linux/keg_relocate.rb and just change the arguments that are being passed to grep. Is that right? It feels repetitive.

Ideally use a separate grep_arguments method for just getting the arguments which should make it pretty small. Up to you to decide what the generic_grep_arguments version should be but I think there's only a need for a single override e.g. assume BSD here and override in os/linux or assume GNU here and override in os/mac.

FileUtils.ln_sf(link.relative_path_from(file.parent), file)
new_src = link.relative_path_from(file.parent)
file.unlink
FileUtils.ln_s(new_src, file)
Copy link
Member

Choose a reason for hiding this comment

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

How does this differ from before? Not disagreeing, just wanting to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I mentioned in the commit message; shoulda copied it into the PR body:

ln_sf does the right thing when `dest` is a symlink pointing to a file:
the symlink gets overwritten with a link pointing to the new src. But
when dest points to a directory, we create a new symlink inside the
folder dest points to, which doesn't help us at all.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, cheers 👍

@tdsmith
Copy link
Contributor Author

tdsmith commented Apr 2, 2017

Need to look at the tests:

Failures:

  1) brew bottle builds a bottle for the given Formula
     Failure/Error:
       expect { brew "bottle", "--no-rebuild", "testball" }
         .to output(/testball-0\.1.*\.bottle\.tar\.gz/).to_stdout
         .and not_to_output.to_stderr
         .and be_a_success

          expected block to not output to stderr, but output "Error: No such file or directory - /usr/bin/fgrep\n"

if link.to_s.start_with?(HOMEBREW_CELLAR.to_s) || link.to_s.start_with?(HOMEBREW_PREFIX.to_s)
FileUtils.ln_sf(link.relative_path_from(file.parent), file)
end
next unless link.to_s.start_with?(HOMEBREW_CELLAR.to_s) || link.to_s.start_with?(HOMEBREW_PREFIX.to_s)
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this two next unlesss for line length and for stupid Mike who can't handle unless ||.

Last thing and otherwise looks 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I can; next if a || b can be written next if a; next if b and next unless a && b can be written next unless a; next unless b but I don't see what to do here. My boolean logic or my imagination might be failing me.

Copy link

Choose a reason for hiding this comment

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

next if !a && !b would work and is maybe easier

Copy link
Member

Choose a reason for hiding this comment

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

My boolean logic or my imagination might be failing me.

No but mine was which is why I had unless || 😁

Yeh, next if !a && !b and perhaps putting them into variables for length is a little easier to follow.

@MikeMcQuaid MikeMcQuaid merged commit d84655e into Homebrew:master Apr 5, 2017
@MikeMcQuaid
Copy link
Member

Thanks @tdsmith!

@tdsmith tdsmith deleted the fix-symlink-relocation branch April 10, 2017 04:50
@Homebrew Homebrew locked and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants