57 Commits

Author SHA1 Message Date
danielnachun
a9dd3a76eb
extend/os/mac/keg_relocate: change egrep_args 2022-03-09 13:33:50 -08:00
danielnachun
94e22d49fa
os/mac/keg_relocate.rb: override grep args 2022-02-28 08:59:33 -08:00
Mike McQuaid
a37f24f439
Revert "Binary patching of build prefixes" 2022-02-14 10:55:08 +00:00
danielnachun
ebea3175f1
extend/os/mac/keg_relocate.rb: override egrep_args 2022-02-10 22:48:45 -08:00
Carlo Cabrera
568bc94f3e
os/mac/keg: use MachOFile#delete_rpath instead of MachO::Tools
This will allow us to avoid keeping track of the number of `RPATH`s
while trying to delete duplicates.

See discussion at #12745.
2022-01-19 00:34:39 +08:00
Carlo Cabrera
ffb3c9cff9
Fuse the rpath loops.
We previously looped twice over the `rpath`s, but we actually only need
to do that once.
2022-01-18 19:29:58 +08:00
Carlo Cabrera
57fae524de
extend/os/mac/keg_relocate: fix duplicate RPATH handling
ruby-macho chokes on changing duplicate RPATHs, so we need to strip the
duplicates before trying to relocate them.

This continues #11405. We need this to unblock
Homebrew/homebrew-core#91224.

While we're here, let's get rid of `HOMEBREW_RELOCATE_RPATHS`. We've
been using it for nearly a year with essentially no problems (barring
`pdnsrec`), so I think it is safe to do unconditionally.
2022-01-18 15:21:05 +08:00
Carlo Cabrera
e4e3b8ad2d
Revert "extend/os/mac/keg_relocate: fix relocation of duplicate RPATHs"
Upon reflection, I realised that this is probably a bug in `ruby-macho`,
and should be fixed there instead.

Needs https://github.com/Homebrew/ruby-macho/pull/362.

This reverts commit e8b5eb7e42c925b7cc10c78a029b8c70e4d7965b.
2022-01-18 13:07:44 +08:00
Carlo Cabrera
457de40117
Apply suggestions from code review
These are just a few style improvements.

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2021-10-27 20:11:47 +08:00
Carlo Cabrera
91e425f7dd
keg_relocate: handle JAVA_HOME
Java-dependent formulae produce different bottles on macOS and Linux
because they have different values for `JAVA_HOME` (`opt_libexec` vs
`opt_libexec/"openjdk.jdk/Contents/Home"`).

Let's handle this difference by using the placeholder
`@@HOMEBREW_JAVA@@` in a bottle, like so:

    #!/bin/bash
    JAVA_HOME="${JAVA_HOME:-@@HOMEBREW_JAVA@@}" exec "@@HOMEBREW_CELLAR@@/clojure/1.10.3.998/libexec/bin/clojure"  "$@"
2021-10-27 20:11:46 +08:00
Mike McQuaid
41e94afda5
Fix brew style
Fixes for https://github.com/Homebrew/brew/pull/12152.

Extracted into a separate PR so this can be merged immediately.
2021-09-30 10:13:53 +01:00
Bo Anderson
1fc39d2d0d
os/mac/keg_relocate: add fallback to default Perl version when using tab
While this should never be necessary for per-OS bottles, this could be useful for :all bottles where the OS it was built on uses a Perl version that doesn't exist on all macOS versions.
2021-05-31 16:31:26 +01:00
Carlo Cabrera
ada399c7db
Fix perl shebang rewriting for perl formula
See

    https://github.com/Homebrew/homebrew-core/issues/77797
    https://github.com/Homebrew/brew/issues/11275#issuecomment-846522409
2021-05-23 11:05:17 +01:00
Carlo Cabrera
e8b5eb7e42
extend/os/mac/keg_relocate: fix relocation of duplicate RPATHs
Homebrew/homebrew-core#77623 revealed two bugs. One in `ruby-macho`,
which turns out to be unable to delete duplicated `RPATH`s. This was
fixed with `ruby-macho` 2.5.1.

The second, which this commit fixes, is in our handling of duplicate
`RPATH`s. Since we iterate over each `RPATH`, attempting to relocate the
first duplicate fails since it will no longer exist after having
relocated the original.
2021-05-17 00:14:46 +01:00
Carlo Cabrera
28c0caae4d
extend/os/mac/keg_relocate: remove RPATHs rooted in build directory
Keeping dangling `RPATH`s is a security risk, and is bad for build
reproducibility.
2021-05-14 01:07:14 +01:00
Carlo Cabrera
dd199901e7
Merge pull request #11370 from carlocab/relocate-metavars 2021-05-13 07:02:25 +01:00
Carlo Cabrera
c7de544fe8
extend/os/mac/keg_relocate: fix post-bottling dylib ID relocation
Running `brew bottle` changes dylib IDs, install names, and rpaths into
placeholders for the bottle, creates a bottle tarball, and then changes
the placeholders back to their correct values.

With my refactoring in #11358, the behaviour of this relocation changed:
dylib IDs would no longer be changed back from placeholders into their
correct values after the creation of the bottle tarball.
2021-05-12 21:37:33 +01:00
Carlo Cabrera
4b6f7aaa5b
extend/os/mac/keg_relocate: remove HOMEBREW_RELOCATE_METAVARS
It's not being used, and it breaks formulae when it is.

Plus do some extra refactoring.
2021-05-12 04:08:41 +01:00
Carlo Cabrera
a1c4243dd7
extend/os/mac/keg_relocate: refactor relocate_dynamic_linkage
Following feedback from #11331.
2021-05-10 17:42:35 +01:00
Bo Anderson
ae49b06600
keg_relocate: replace Perl shebangs 2021-05-10 06:13:54 +01:00
Carlo Cabrera
dec7b97342
keg_relocate: style improvements
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2021-05-06 12:01:51 +01:00
Carlo Cabrera
8f1cd1288d
extend/os/mac/keg_relocate: relocate rpaths on macOS 2021-05-05 23:43:43 +01:00
Mike McQuaid
04abc51d1f
Cleanup use of CxxStdlib
- remove usage on macOS as we don't care about it there
- don't error out on incompatibility but still store stdlib on Linux
- remove (now) unused methods
2021-04-02 13:55:29 +01:00
Seeker
b9854bd4cf rubocops: add unless_multiple_conditions 2021-01-08 10:33:54 -08:00
Rylan Polster
dda0dc72a7 format note comments 2020-11-16 02:02:52 +01:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Mike McQuaid
3663e9d5d1
os/mac/keg_relocate: handle libexec/lib.
We can fix up libraries in `lib` not `libexec/lib` so add an extra check
for that case.

Inspired by https://github.com/Homebrew/homebrew-core/pull/53790#issuecomment-637622329
2020-06-02 16:35:36 +01:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
Shaun Jackman
59ee097f8d fix_dynamic_linkage: Check HOMEBREW_RELOCATE_METAVARS
Only remove RPATH when HOMEBREW_RELOCATE_METAVARS is set.

See PR https://github.com/Homebrew/brew/pull/5413
2019-03-19 08:29:45 -07:00
William Woodruff
02216eedaf
mac/keg_relocate: Don't relocate loader_paths 2019-03-11 20:59:11 -04:00
William Woodruff
82dd5011e2
mac/keg_relocate: Delete loader_paths
Fix the call to expand_rpath.
2019-03-10 21:29:59 -04:00
William Woodruff
54aca0d14f
os/mac: Flush RPATHs from Mach-Os when possible 2019-03-10 21:07:04 -04:00
William Woodruff
2e2dea6131
mac/keg_relocate: Style nit 2019-03-10 21:07:04 -04:00
William Woodruff
d2dc4e5599
mac/keg_relocate: Drop unnecessary parens 2019-03-10 21:07:04 -04:00
William Woodruff
c4363e8c58
mac/keg_relocate: Remove short-circuit, cleanup 2019-03-10 21:07:04 -04:00
William Woodruff
a6bcbdb20d
mac/keg_relocate: Prefer String#/, add ENV check 2019-03-10 21:07:04 -04:00
William Woodruff
27d6cfb12e
[WIP] mac/keg_relocate: Emulate dylinker behavior
Instead of assuming that #{lib} is the correct RPATH expansion,
test all RPATHS and substitute the first one that works.
2019-03-10 21:07:03 -04:00
William Woodruff
54e6cbb343
mac/keg_relocate: Rewrite rpaths in install names 2019-03-10 21:07:03 -04:00
Mike McQuaid
737b84b54b
brew style --fix fixes. 2018-11-02 17:29:23 +00:00
Markus Reiter
e9b9ea49a1 Update to RuboCop 0.59.1. 2018-09-17 03:45:59 +02:00
Mike McQuaid
9fca172d03 Fix HOMEBREW_RUBY_WARNINGS="-w"
Fix various circular requirements, method redefinitions, etc.
2018-04-07 20:28:56 +01:00
ilovezfs
e8da9613fb Revert "mach: Avoid reopening the file for relocation" 2017-09-27 02:08:23 -07:00
ilovezfs
0831f31e44 Revert "keg_relocate: use correct number of arguments in call to change_install_name" 2017-09-27 02:07:22 -07:00
Steven Peters
fc5b3778cb keg_relocate: fix call to change_install_name
During the changes to macho file relocation refactoring
in #3101, #3138, and #3139,
the number of arguments to the mach::change_install_name
function changed from 3 to 2, but
there was still an instance of the function being called
with the wrong number of arguments.
2017-09-26 17:30:28 -07:00
William Woodruff
d618e574fb
mach: Avoid reopening the file for relocation
This commit allows the relocation code to perform install name
and dylib ID changes without reopening the file separately.
2017-09-25 17:46:23 -04:00
Markus Reiter
2d6ae61314 Re-revert "Fix operator spacing." 2017-06-02 19:22:05 +02:00
Markus Reiter
5828eefd01 Remove to_s from some Pathnames. 2017-05-08 13:37:28 +02:00
Mike McQuaid
d84655efb9 Merge pull request #2442 from tdsmith/fix-symlink-relocation
Virtualenv relocation fixes
2017-04-05 09:32:52 +01:00
Mike McQuaid
715132642f Revert "keg_relocate: Don't relocate dylib IDs containing metavariables." 2017-04-04 13:29:27 +01:00