60 Commits

Author SHA1 Message Date
Shaun Jackman
a4033c7196 Do not specify absolute paths to utilities
Specifying an absolute path to utilities is no longer needed,
since environment filtering uses a default PATH.
2017-12-12 09:25:16 -08:00
Shaun Jackman
03ae6aae3b text_files: Skip the formula in .brew/formula.rb 2017-10-01 18:27:05 -07:00
ilovezfs
01f52f54e3 keg_relocate: treat .lai files as libtool files.
Previously .lai files only had their locations replaced with
placeholders if /usr/bin/file recognized them as ASCII files, which is
only the case on macOS Sierra and above.
2017-09-16 07:04:26 -07:00
Markus Reiter
2d6ae61314 Re-revert "Fix operator spacing." 2017-06-02 19:22:05 +02:00
Tim D. Smith
8db2998819 Merge pull request #2598 from tdsmith/relocate-virtualenv-orig-prefix
Relocate virtualenv orig-prefix
2017-05-24 10:41:47 -07:00
Shaun Jackman
175c2e9303 replace_text_in_files: Regex match is greedy
The regex matches the longest possible string. Order does not matter.
2017-05-17 23:55:29 -07:00
Tim D. Smith
22d3a67b73 Relocate virtualenv orig-prefix.txt
Virtualenvs remember the path to the stdlib in a file named
orig_prefix.txt. This file wasn't being relocated because Homebrew skips
files that look like they're intended for human consumption by matching
against the list of metafile extensions. This led to the bug described
in https://github.com/Homebrew/homebrew-core/issues/12869. This fixes
relocation by creating an exception for orig-prefix.txt.
2017-05-06 15:56:55 -07:00
Mike McQuaid
2144c35539 keg_relocate: slim long lines. 2017-04-05 09:00:11 +01:00
Tim D. Smith
3b75075727 rubocop 2017-04-02 10:26:05 -07:00
Tim D. Smith
2f4eaf26a0 Use extend/OS mechanism for grep args 2017-04-02 09:04:49 -07:00
Tim D. Smith
d0feae0632 Unlink before rewriting link
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.
2017-04-02 08:19:29 -07:00
Tim D. Smith
51c4c84a3f Don't follow symlinks when hunting for strings
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.
2017-04-02 08:17:07 -07:00
Viktor Szakats
cc8f029f22 secure urls + remove -k from in-doc curl command 2017-03-14 17:27:11 +00:00
Alyssa Ross
9e97eadccb rubocop: trailing comma in multiline method calls
Discussed in
https://github.com/Homebrew/brew/pull/1987/files#r100693581.

This was originally ommitted because it wasn't compatible with Ruby 1.8.
(See https://github.com/Homebrew/legacy-homebrew/pull/48144#r49928971).
2017-02-12 15:11:38 +00:00
Josh Hagins
e57d312ad1 keg_relocate: don't forget the hard links 2016-11-01 12:58:38 -04:00
Josh Hagins
d60020f1a9 keg_relocate: fix ordering of replacements 2016-11-01 12:07:14 -04:00
Josh Hagins
652c5bc865 formula_installer: fix regression in #1253
Apparently `cellar :any_skip_relocation` doesn't actually mean we
can skip relocation, at least for text files.
2016-10-25 03:41:37 -04:00
Josh Hagins
fab2cffe5d keg_relocate: wrap relocation locations in struct 2016-10-24 16:21:08 -04:00
Josh Hagins
adc4b1f0c7 keg_relocate: brew style fixes 2016-10-24 16:21:08 -04:00
Josh Hagins
9c519bbdbc keg_relocate: refactor relocate_text_files
Replace relocate_text_files with three methods that clarify intent:
replace_locations_with_placeholders, replace_placeholders_with_locations
and replace_text_in_files, the first two calling the third.
2016-10-24 16:21:08 -04:00
Josh Hagins
c46155aba4 keg_relocate: cache files rewritten during brew bottle
`brew bottle` replaces instances of the Homebrew prefix, cellar, and
repository with placeholders in all text files. Cache these files in
INSTALL_RECEIPT.json so that we don't have to check every single text
file for placeholders on install.
2016-10-24 16:21:08 -04:00
Tim D. Smith
22a64aa6c6 Explain why info could be nil 2016-10-15 23:52:55 -07:00
Tim D. Smith
371cd0dd3e Don't choke on invalid UTF-8 in file output
Sometimes `file` output contains data from the file under examination,
which may include binary data that does not represent valid UTF-8
codepoints. String#split dies if it doesn't understand the encoding, so
tell Ruby to treat `file` output as a bytestring.
2016-10-15 21:21:08 -07:00
Josh Hagins
24c2d0b3c2 keg_relocate: fix for multiline /usr/bin/file output 2016-10-12 11:53:06 -04:00
Mike McQuaid
2e306bcde0 keg_relocate: relocate text_executable? files.
This was omitted from #1258, incorrectly fixed in #1267, reverted in
 #1268 and re-applied in this commit.
2016-10-12 11:35:37 +01:00
Mike McQuaid
02c567cb12 Revert "keg_relocate: left out text_executable? check in #1258" 2016-10-12 11:29:33 +01:00
Josh Hagins
6cecc4c03e keg_relocate: left out text_executable? check in #1258 2016-10-12 04:02:47 -04:00
Josh Hagins
d8a6863283 keg_relocate: use xargs to batch file arguments 2016-10-11 21:19:08 -04:00
Markus Reiter
e851c9bf6c Style/Alias: Prefer alias. 2016-09-23 18:19:53 +02:00
Mike McQuaid
997ccb044d Relocate HOMEBREW_REPOSITORY when necessary.
Now that the default from the installer, our CI and soon all users
is `/usr/local/Homebrew` it's a lot easier to check if there's
references to it (as we cannot look for `/usr/local` as it's a too
commonly hardcoded path).
2016-09-18 16:31:58 +01:00
Mike McQuaid
3982950e61 rubocop --auto-correct all hash-rocket usage. 2016-09-17 16:14:13 +01:00
Mike McQuaid
6693915399 rubocop --auto-correct all remaining files.
But remove some manual `.freeze`s on constants that shouldn't be
constants.
2016-09-17 16:14:13 +01:00
Dominyk Tiller
604f4b6a07
keg_relocate: refactor path.find change for performance
Closes #616.

Signed-off-by: Dominyk Tiller <dominyktiller@gmail.com>
2016-08-02 03:50:50 +01:00
Dominyk Tiller
196a6946e1
keg_relocate: work around file bug
There's an old bug in `file` which means it can't read certain files under a
non-C locale. This has been fixed upstream for some time, but Apple hasn't
picked that fix up & even on OS X El Capitan the `file` is ancient.

This is currently causing a lot of false positives in our bottle code around
relocating things like manpages translated into non-English languages, because
currently the test does:

```
pn = "/usr/local/Cellar/vim/7.4.2109/share/man/fr/man1/vim.1"
Utils.popen_read("/usr/bin/file", "--brief", pn).include?("text")
```
Which returns `false`. But it isn't returning `false` because the actual result
is false, but because `file` panics & fails, which for us equals a `false`. The
actual output when accessed is:
```
pn = "/usr/local/Cellar/vim/7.4.2109/share/man/fr/man1/vim.1"
Utils.popen_read("/usr/bin/file", "--brief", pn)
"ERROR: line 22: regexec error 17, (illegal byte sequence)\n"
```
Forcing this check to be done under a "C" locale eliminates this particular false
positive for strings we can't relocate & consequently things such as NLS may
prove to be more portable in some formulae than is currently the case.

Using `vim` again for the example:
```
pn = "/usr/local/Cellar/vim/7.4.2109/share/man/fr/man1/vim.1"
Utils.popen_read("/usr/bin/file", "--brief", pn).include?("text")
true
```
This reduces the flagged strings from `vim` from 4 issues to 2, the remaining
two with the `vim` executable itself which "remembers" the full path to perl,
python, ruby, etc during build & vomits that information out when requested
by the user. Both the manpages flagged before this change are no longer flagged
as unrelocatable.

This won't entirely resolve the NLS problem because some things hardcode in
a locale path, which will be stored in the executable, but at the very least it
should reduce the number of false positives & may enable relocation where that
locale path hasn't been burnt in.
2016-08-02 03:50:49 +01:00
Mike McQuaid
a1a8b3faa7 keg_relocate: don't relocate text files without /usr/bin/file. 2016-07-29 21:21:02 -06:00
Mike McQuaid
f1c4141885 keg_relocate: port to generic OS. (#453) 2016-07-09 13:52:05 +01:00
William Woodruff
d3ef56425a keg_relocate: Exclude hardlinks from mach_o_files. 2016-06-29 14:34:08 +02:00
Tim D. Smith
cab97cf4d7 Revert "keg_relocate: Exclude hardlinks from mach_o_files."
This reverts commit 3e5e14a59580325faf397b48d62a52f0013a17f2.
2016-06-27 23:25:15 -07:00
William Woodruff
3e5e14a595 keg_relocate: Exclude hardlinks from mach_o_files. 2016-06-27 22:56:12 -07:00
Mike McQuaid
663f51b88e keg_relocate: don't assume .la files are in lib.
Sometimes they are in e.g. libexec but there's no real reason to assume
they are anywhere; we want to relocate them regardless.
2016-04-24 22:06:14 +01:00
William Woodruff
afe0fde49c os/mac: optionally use ruby_macho.
- and branch for dylib_id_and_dylibs
- add branches for dylib id changing and change_install_name
- rename MachO module to HomebrewMachO to prevent namespace clashes
  with MachO in ruby-macho. this will eventually be replaced entirely
  with direct calls to ruby-macho methods
- break ruby-macho implementation out into separate RubyMachO module,
  and include either RubyMachO or CctoolsMachO (the original
  implementation) based on the HOMEBREW_RUBY_MACHO env var
- move ArchitectureListExtension and RubyMachO into separate files
- create {ruby_,cctools_,,}relocate.rb for isolation of different
  methods of mach-o relocation (ruby-macho vs. cctools)
- fill in require_install_name_tool? for ruby_relocate.rb
- rename {ruby_,cctools_,,}relocate.rb to keg, isolate requires in
  os/mac

Closes Homebrew/homebrew#45001.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2016-02-03 21:25:40 +00:00
Syed Humza Shah
5e09a6a743 keg_relocate: replaced 'if' with guard clause
Closes Homebrew/homebrew#46211.
2015-11-24 10:48:28 +00:00
Martin Afanasjew
6f5307fbd9 keg_relocate: fix relocation of frameworks
When fixing references to regular dylibs, it is sufficient to search for
a file with the same base name, e.g., `libpoppler.56.dylib`. However, if
the broken reference is to a framework, we also have to take into
account preceding path components to find a suitable match. Framework
references (according to the `dyld` man page) come in two flavors:

- `XXX.framework/Versions/YYY/XXX` (with version)
- `XXX.framework/XXX` (without version)

The change here is to detect these patterns and to make sure that the
fixed library reference has the same suffix as the broken one.

Prior to this fix, a broken framework reference (if originating in a
sister framework) to `QtXml.framework/Versions/5/QtXml` would have been
rewritten to `<qt5-keg>/lib/QtXml.framework/QtXml`. In practice, this
mostly works, but is technically incorrect and thus creates problems
like in Homebrew/homebrew#42191. With this fix, the framework reference is correctly
rewritten to `<qt5-keg>/lib/QtXml.framework/Versions/5/QtXml`.

Closes Homebrew/homebrew#45494.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2015-11-19 08:54:58 +00:00
Martin Afanasjew
4d772042f7 keg_relocate: remove options from Keg#dylib_id_for
No longer used since commit 3b0cbe6a56d9133941482a9e2d033ad86cdb5e79.

Closes Homebrew/homebrew#45835.

Signed-off-by: Xu Cheng <xucheng@me.com>
2015-11-11 14:23:59 +08:00
Mike McQuaid
f59ad1c9e9 Revert "keg_relocate: fix relocation of frameworks"
This reverts commit 14ce4027ae5b8aa994f4bdf0b8160bbc4994948b.
2015-11-08 14:00:27 -08:00
Martin Afanasjew
06634edab7 keg_relocate: fix relocation of frameworks
When fixing references to regular dylibs, it is sufficient to search for
a file with the same base name, e.g., `libpoppler.56.dylib`. However, if
the broken reference is to a framework, we also have to take into
account preceding path components to find a suitable match. Framework
references (according to the `dyld` man page) come in two flavors:

- `XXX.framework/Versions/YYY/XXX` (with version)
- `XXX.framework/XXX` (without version)

The change here is to detect these patterns and to make sure that the
fixed library reference has the same suffix as the broken one.

Prior to this fix, a broken framework reference (if originating in a
sister framework) to `QtXml.framework/Versions/5/QtXml` would have been
rewritten to `<qt5-keg>/lib/QtXml.framework/QtXml`. In practice, this
mostly works, but is technically incorrect and thus creates problems
like in Homebrew/homebrew#42191. With this fix, the framework reference is correctly
rewritten to `<qt5-keg>/lib/QtXml.framework/Versions/5/QtXml`.

Closes Homebrew/homebrew#45494.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2015-11-08 13:27:03 -08:00
Tim D. Smith
f81d561b67 always use opt_prefix in install_name
dylib install_names are presently rewritten relative to HOMEBREW_PREFIX,
except for keg-only formulas, which are rewritten relative to
opt_prefix.

If we make a formula keg_only, all of its dependents need to be bumped,
since it will no longer exist in HOMEBREW_PREFIX and all of the links
will be written incorrectly.

If we always use opt_prefix, we avoid that dilemma, and make installed
packages more robust if a dependency is `brew unlink`ed.

Closes Homebrew/homebrew#43518.

Signed-off-by: Dominyk Tiller <dominyktiller@gmail.com>
2015-10-16 17:22:35 +01:00
Xu Cheng
e23cca8d84 bottle: auto detect any_skip_relocation 2015-09-12 01:39:00 +08:00
Xu Cheng
d911b5689a keg_relocate: split relocate_install_names and relocate_text_files
For bottle with `:any_skip_relocation`, relocating text files is
required.
2015-09-12 01:38:59 +08:00
Xu Cheng
5241932b45 keg_relocate: fix absolute symlink 2015-09-11 18:32:35 +08:00