Revert "language/java: use shortened brew paths"

This reverts commits 318175cfe2b23328f1b5f13812fd59cfd45fe1dc,
e7ab760392b9691a6c730b7e0d660b7874969e70 and
3b35af63f608438b1882756feca94a6ebdd0d6a3 (PR #11537).
This commit is contained in:
Misty De Meo 2021-06-17 20:29:43 -07:00
parent 1cb0f0fbf2
commit c0a02442d9
No known key found for this signature in database
GPG Key ID: 76CF846A2F674B2C
6 changed files with 3 additions and 133 deletions

View File

@ -365,7 +365,7 @@ class Pathname
target = Pathname.new(target) # allow pathnames or strings target = Pathname.new(target) # allow pathnames or strings
join(target.basename).write <<~SH join(target.basename).write <<~SH
#!/bin/bash #!/bin/bash
exec "#{Utils.shortened_brew_path(target)}" "$@" exec "#{target}" "$@"
SH SH
end end
end end
@ -381,7 +381,7 @@ class Pathname
dirname.mkpath dirname.mkpath
write <<~SH write <<~SH
#!/bin/bash #!/bin/bash
#{env_export}exec "#{Utils.shortened_brew_path(target)}" #{args} "$@" #{env_export}exec "#{target}" #{args} "$@"
SH SH
end end
@ -410,7 +410,7 @@ class Pathname
mkpath mkpath
(self/script_name).write <<~EOS (self/script_name).write <<~EOS
#!/bin/bash #!/bin/bash
export JAVA_HOME="#{Language::Java.overridable_short_java_home_env(java_version)[:JAVA_HOME]}" export JAVA_HOME="#{Language::Java.overridable_java_home_env(java_version)[:JAVA_HOME]}"
exec "${JAVA_HOME}/bin/java" #{java_opts} -jar "#{target_jar}" "$@" exec "${JAVA_HOME}/bin/java" #{java_opts} -jar "#{target_jar}" "$@"
EOS EOS
end end

View File

@ -36,26 +36,13 @@ module Language
end end
private_class_method :java_home_shell private_class_method :java_home_shell
def self.short_java_home_shell(version = nil)
Utils.shortened_brew_path(java_home(version))
end
private_class_method :short_java_home_shell
def self.java_home_env(version = nil) def self.java_home_env(version = nil)
{ JAVA_HOME: java_home_shell(version) } { JAVA_HOME: java_home_shell(version) }
end end
def self.short_java_home_env(version = nil)
{ JAVA_HOME: short_java_home_shell(version) }
end
def self.overridable_java_home_env(version = nil) def self.overridable_java_home_env(version = nil)
{ JAVA_HOME: "${JAVA_HOME:-#{java_home_shell(version)}}" } { JAVA_HOME: "${JAVA_HOME:-#{java_home_shell(version)}}" }
end end
def self.overridable_short_java_home_env(version = nil)
{ JAVA_HOME: "${JAVA_HOME:-#{short_java_home_shell(version)}}" }
end
end end
end end

View File

@ -19,14 +19,6 @@ describe Language::Java do
end end
end end
let(:expected_short_home) do
if OS.mac?
"$(brew --prefix)/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
else
"$(brew --prefix)/opt/openjdk/libexec"
end
end
before do before do
allow(Formula).to receive(:[]).and_return(f) allow(Formula).to receive(:[]).and_return(f)
allow(f).to receive(:any_version_installed?).and_return(true) allow(f).to receive(:any_version_installed?).and_return(true)
@ -57,18 +49,6 @@ describe Language::Java do
end end
end end
describe "::short_java_home_env" do
it "returns short java_home path if version specified" do
short_java_home_env = described_class.short_java_home_env("1.8+")
expect(short_java_home_env[:JAVA_HOME]).to eql(expected_short_home)
end
it "returns short java_home path if version is not specified" do
short_java_home_env = described_class.short_java_home_env
expect(short_java_home_env[:JAVA_HOME]).to eql(expected_short_home)
end
end
describe "::overridable_java_home_env" do describe "::overridable_java_home_env" do
it "returns java_home path if version specified" do it "returns java_home path if version specified" do
overridable_java_home_env = described_class.overridable_java_home_env("1.8+") overridable_java_home_env = described_class.overridable_java_home_env("1.8+")
@ -80,16 +60,4 @@ describe Language::Java do
expect(overridable_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_home}}") expect(overridable_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_home}}")
end end
end end
describe "::overridable_short_java_home_env" do
it "returns short java_home path if version specified" do
overridable_short_java_home_env = described_class.overridable_short_java_home_env("1.8+")
expect(overridable_short_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_short_home}}")
end
it "returns short java_home path if version is not specified" do
overridable_short_java_home_env = described_class.overridable_short_java_home_env
expect(overridable_short_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_short_home}}")
end
end
end end

View File

@ -1,33 +0,0 @@
# typed: false
# frozen_string_literal: true
require "utils/path"
describe Utils do
describe "::path_is_parent_of?" do
it "returns true when child path is a descendant of the parent" do
expect(described_class.path_is_parent_of?("/foo", "/foo/bar/baz")).to eq(true)
end
it "returns false when child path is not a descendant of the parent" do
expect(described_class.path_is_parent_of?("/foo/bar/baz/qux", "/foo/bar")).to eq(false)
end
end
describe "::shortened_brew_path" do
it "returns shortened path when the path can be expressed with the output of a brew command" do
expect(described_class.shortened_brew_path("#{HOMEBREW_PREFIX}/foo/bar")).to eq("$(brew --prefix)/foo/bar")
end
it "returns shortened path with $(brew --prefix <formula>) when path is in a linked keg", :integration_test do
install_test_formula "testball"
f = Formula["testball"]
expect(described_class.shortened_brew_path("#{f.opt_prefix}/main.c")).to eq("$(brew --prefix testball)/main.c")
end
it "returns the original path when the path cannot be shortened" do
expect(described_class.shortened_brew_path("/foo/bar/baz")).to eq("/foo/bar/baz")
end
end
end

View File

@ -13,7 +13,6 @@ require "utils/git_repository"
require "utils/github" require "utils/github"
require "utils/inreplace" require "utils/inreplace"
require "utils/link" require "utils/link"
require "utils/path"
require "utils/popen" require "utils/popen"
require "utils/repology" require "utils/repology"
require "utils/svn" require "utils/svn"

View File

@ -1,51 +0,0 @@
# typed: strict
# frozen_string_literal: true
# Helper functions for working with paths
module Utils
extend T::Sig
# Checks if a a child path is a descendant of a given parent path
sig { params(parent_path: T.any(String, Pathname), child_path: T.any(String, Pathname)).returns(T::Boolean) }
def self.path_is_parent_of?(parent_path, child_path)
parent_component_array = Pathname(parent_path).each_filename.to_a
child_component_array = Pathname(child_path).each_filename.to_a
child_component_array.first(parent_component_array.length) == parent_component_array
end
# Gets a condensed short brew path for a given path, or the original path if it cannot be condensed
sig { params(long_path: T.any(String, Pathname)).returns(String) }
def self.shortened_brew_path(long_path)
short_path = long_path.to_s
long_path = Pathname(long_path)
if long_path.exist?
begin
k = Keg.for(long_path)
opt_record = k.opt_record
formula_name = k.to_formula.name
rescue FormulaUnavailableError, NotAKegError
nil
else
short_path = short_path.sub(/\A#{Regexp.escape(opt_record.to_s)}/, "$(brew --prefix #{formula_name})")
end
end
try_paths = {
HOMEBREW_CACHE => "--cache",
HOMEBREW_CELLAR => "--cellar",
HOMEBREW_REPOSITORY => "--repository",
HOMEBREW_PREFIX => "--prefix",
}
try_paths.each do |try_path, flag|
if path_is_parent_of?(try_path, long_path)
short_path = short_path.sub(/\A#{Regexp.escape(try_path.to_s)}/, "$(brew #{flag})")
break
end
end
short_path
end
end