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"  "$@"
This commit is contained in:
Carlo Cabrera 2021-10-27 15:01:17 +08:00
parent ed07132a3c
commit 91e425f7dd
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 19 additions and 0 deletions

View File

@ -172,6 +172,12 @@ class Keg
end
relocation.add_replacement_pair(:perl, PERL_PLACEHOLDER, perl_path)
openjdk = openjdk_dep_name_if_applicable
if openjdk
openjdk_path = HOMEBREW_PREFIX/"opt"/openjdk/"libexec/openjdk.jdk/Contents/Home"
relocation.add_replacement_pair(:java, JAVA_PLACEHOLDER, openjdk_path.to_s)
end
relocation
end

View File

@ -7,6 +7,7 @@ class Keg
REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@"
LIBRARY_PLACEHOLDER = "@@HOMEBREW_LIBRARY@@"
PERL_PLACEHOLDER = "@@HOMEBREW_PERL@@"
JAVA_PLACEHOLDER = "@@HOMEBREW_JAVA@@"
class Relocation
extend T::Sig
@ -82,6 +83,8 @@ class Keg
[]
end
JAVA_REGEX = %r{#{HOMEBREW_PREFIX}/opt/openjdk(@\d+(\.\d+)*)?/libexec(/openjdk\.jdk/Contents/Home)?}.freeze
def prepare_relocation_to_placeholders
relocation = Relocation.new
relocation.add_replacement_pair(:prefix, HOMEBREW_PREFIX.to_s, PREFIX_PLACEHOLDER, path: true)
@ -95,6 +98,7 @@ class Keg
relocation.add_replacement_pair(:perl,
%r{\A#!(?:/usr/bin/perl\d\.\d+|#{HOMEBREW_PREFIX}/opt/perl/bin/perl)( |$)}o,
"#!#{PERL_PLACEHOLDER}\\1")
relocation.add_replacement_pair(:java, JAVA_REGEX, JAVA_PLACEHOLDER)
relocation
end
alias generic_prepare_relocation_to_placeholders prepare_relocation_to_placeholders
@ -112,6 +116,9 @@ class Keg
relocation.add_replacement_pair(:repository, REPOSITORY_PLACEHOLDER, HOMEBREW_REPOSITORY.to_s)
relocation.add_replacement_pair(:library, LIBRARY_PLACEHOLDER, HOMEBREW_LIBRARY.to_s)
relocation.add_replacement_pair(:perl, PERL_PLACEHOLDER, "#{HOMEBREW_PREFIX}/opt/perl/bin/perl")
openjdk = openjdk_dep_name_if_applicable
relocation.add_replacement_pair(:java, JAVA_PLACEHOLDER, "#{HOMEBREW_PREFIX}/opt/#{openjdk}/libexec") if openjdk
relocation
end
alias generic_prepare_relocation_to_locations prepare_relocation_to_locations
@ -122,6 +129,12 @@ class Keg
replace_text_in_files(relocation, files: files)
end
def openjdk_dep_name_if_applicable
runtime_dependencies.find do |dep|
dep["full_name"].match? Version.formula_optionally_versioned_regex(:openjdk)
end&.fetch("full_name")
end
def replace_text_in_files(relocation, files: nil)
files ||= text_files | libtool_files