Skip to content

Commit bcf1cfc

Browse files
authored
Merge pull request #23043 from Homebrew/no-clt-cask-installs
Allow no-CLT cask installs
2 parents 9604f84 + 436ddf4 commit bcf1cfc

9 files changed

Lines changed: 98 additions & 7 deletions

File tree

Library/Homebrew/extend/os/mac/development_tools.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def locate(tool)
1717
@locate.fetch(tool) do |key|
1818
@locate[key] = if (located_tool = super(tool))
1919
located_tool
20-
else
20+
elsif installed?
2121
path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool.to_s, err: :close).chomp
2222
::Pathname.new(path) if File.executable?(path)
2323
end

Library/Homebrew/extend/os/mac/diagnostic.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ def fatal_preinstall_checks
6464
check_access_directories
6565
]
6666

67-
# We need the developer tools for `codesign`.
68-
checks << "check_for_installed_developer_tools" if ::Hardware::CPU.arm?
69-
67+
# Developer tools are checked when building from source.
7068
checks.freeze
7169
end
7270

7371
sig { returns(T::Array[String]) }
7472
def fatal_build_from_source_checks
7573
%w[
74+
check_for_installed_developer_tools
7675
check_xcode_license_approved
7776
check_xcode_minimum_version
7877
check_clt_minimum_version

Library/Homebrew/extend/os/mac/formula_installer.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ def fresh_install?(formula)
1313
!::Homebrew::EnvConfig.developer? && !OS::Mac.version.outdated_release? &&
1414
(installed_on_request? || !formula.any_version_installed?)
1515
end
16+
17+
sig { void }
18+
def check_developer_tools_for_bottle_pour
19+
return unless ::Hardware::CPU.arm?
20+
return if formula.bottle_specification.skip_relocation?
21+
22+
# We need the developer tools for `codesign` when relocating bottles.
23+
require "diagnostic"
24+
unless (developer_tools_warning = ::Homebrew::Diagnostic::Checks.new.check_for_installed_developer_tools)
25+
return
26+
end
27+
28+
ofail developer_tools_warning
29+
exit 1
30+
end
1631
end
1732
end
1833
end

Library/Homebrew/formula_installer.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,9 @@ def install
554554
lock
555555

556556
start_time = Time.now
557-
if !pour_bottle? && DevelopmentTools.installed?
557+
if pour_bottle?
558+
check_developer_tools_for_bottle_pour
559+
else
558560
require "install"
559561
Homebrew::Install.perform_build_from_source_checks
560562
end
@@ -1634,6 +1636,9 @@ def problem_if_output(output)
16341636
@show_summary_heading = true
16351637
end
16361638

1639+
sig { void }
1640+
def check_developer_tools_for_bottle_pour; end
1641+
16371642
sig { void }
16381643
def audit_installed
16391644
unless formula.keg_only?

Library/Homebrew/shims/shared/git

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ then
4444
# /usr/bin/<tool> will be a popup stub under such configuration.
4545
# xcrun hangs if xcode-select is set to "/"
4646
xcode_path="$(/usr/bin/xcode-select -print-path 2>/dev/null)"
47-
if [[ -z "${xcode_path}" ]]
47+
if [[ -z "${xcode_path}" || ! -d "${xcode_path}" ]]
4848
then
4949
popup_stub=1
5050
fi

Library/Homebrew/test/formula_installer_bottle_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_basic_formula_setup(formula)
113113

114114
expect do
115115
described_class.new(formula).install
116-
end.to raise_error(UnbottledError)
116+
end.to raise_error(SystemExit)
117117

118118
expect(formula).not_to be_latest_version_installed
119119
end

Library/Homebrew/test/formula_installer_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ def temporary_install(formula, **options)
8787
end
8888
end
8989

90+
specify "relocated bottle install requires developer tools on Apple Silicon", :needs_macos do
91+
formula = TestballBottle.new
92+
installer = described_class.new(formula)
93+
94+
allow(installer).to receive_messages(lock: nil, pour_bottle?: true)
95+
allow(Hardware::CPU).to receive(:arm?).and_return(true)
96+
allow(formula.bottle_specification).to receive(:skip_relocation?).and_return(false)
97+
allow_any_instance_of(Homebrew::Diagnostic::Checks)
98+
.to receive(:check_for_installed_developer_tools)
99+
.and_return("No developer tools installed.")
100+
101+
expect do
102+
installer.install
103+
end.to raise_error(SystemExit)
104+
end
105+
90106
describe "#finish" do
91107
it "runs post-install steps before the remaining `post_install` hook" do
92108
formula = formula "finish-install-steps" do
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
require "development_tools"
5+
6+
RSpec.describe DevelopmentTools, :needs_macos do
7+
describe ".locate" do
8+
before do
9+
described_class.remove_instance_variable(:@locate) if described_class.instance_variable_defined?(:@locate)
10+
end
11+
12+
it "doesn't call xcrun when Xcode and the CLT are not installed" do
13+
allow(File).to receive(:executable?).and_call_original
14+
allow(File).to receive(:executable?).with("/usr/bin/missing-tool").and_return(false)
15+
allow(OS::Mac::Xcode).to receive(:installed?).and_return(false)
16+
allow(OS::Mac::CLT).to receive(:installed?).and_return(false)
17+
18+
expect(Utils).not_to receive(:popen_read)
19+
20+
expect(described_class.locate("missing-tool")).to be_nil
21+
end
22+
23+
it "uses xcrun when developer tools are installed" do
24+
allow(File).to receive(:executable?).and_call_original
25+
allow(File).to receive(:executable?).with("/usr/bin/xcode-tool").and_return(false)
26+
allow(File).to receive(:executable?).with("/Xcode/usr/bin/xcode-tool").and_return(true)
27+
allow(OS::Mac::Xcode).to receive(:installed?).and_return(true)
28+
allow(OS::Mac::CLT).to receive(:installed?).and_return(false)
29+
expect(Utils).to receive(:popen_read)
30+
.with("/usr/bin/xcrun", "-no-cache", "-find", "xcode-tool", err: :close)
31+
.and_return("/Xcode/usr/bin/xcode-tool\n")
32+
33+
expect(described_class.locate("xcode-tool")).to eq(Pathname("/Xcode/usr/bin/xcode-tool"))
34+
end
35+
end
36+
end

Library/Homebrew/test/os/mac/diagnostic_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@
6262
.to match("Xcode alone is not sufficient on Big Sur")
6363
end
6464

65+
describe "#fatal_preinstall_checks" do
66+
it "doesn't require developer tools on Apple Silicon" do
67+
allow(Hardware::CPU).to receive(:arm?).and_return(true)
68+
69+
expect(checks.fatal_preinstall_checks).not_to include("check_for_installed_developer_tools")
70+
end
71+
end
72+
73+
describe "#fatal_build_from_source_checks" do
74+
it "requires developer tools" do
75+
expect(checks.fatal_build_from_source_checks).to include("check_for_installed_developer_tools")
76+
end
77+
end
78+
79+
describe "#build_from_source_checks" do
80+
it "warns about missing developer tools" do
81+
expect(checks.build_from_source_checks).to include("check_for_installed_developer_tools")
82+
end
83+
end
84+
6585
describe "#check_if_supported_sdk_available" do
6686
let(:macos_version) { MacOSVersion.new("11") }
6787

0 commit comments

Comments
 (0)