Skip to content

Commit b7e1411

Browse files
committed
Fix: Use shell cp to stage binaries between SPM product builds
Swift 6's new build system removes previous binaries when building a different --product. Use system 'cp' (shell command, not Ruby method) to immediately stage each binary after its build completes.
1 parent 2290115 commit b7e1411

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

Formula/wwk.rb

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,45 @@ def install
2323
}
2424
SWIFT
2525

26-
# Swift 6 / new build system requires --product to place each
27-
# executable in the output directory. Build all three products,
28-
# then resolve the bin path and install.
29-
swift_flags = %w[
30-
--configuration release
31-
--disable-sandbox
32-
-Xswiftc -cross-module-optimization
33-
]
34-
system "swift", "build", *swift_flags, "--product", "wwk"
35-
system "swift", "build", *swift_flags, "--product", "wwkd"
36-
system "swift", "build", *swift_flags, "--product", "WellWhaddyaKnow"
37-
38-
# Resolve the actual bin path (triple-specific, e.g.
39-
# .build/arm64-apple-macosx/release).
40-
bin_path = Utils.safe_popen_read(
26+
# Swift 6 new build system only keeps the last --product binary
27+
# in the output directory. Build each product and immediately
28+
# move it to a staging area using shell cp (Homebrew's Ruby cp
29+
# does not execute between system calls in a loop).
30+
swift_flags = "--configuration release --disable-sandbox -Xswiftc -cross-module-optimization"
31+
32+
staging = buildpath/"staged_binaries"
33+
staging.mkpath
34+
35+
# Build wwk, stage it
36+
system "swift", "build",
37+
"--configuration", "release",
38+
"--disable-sandbox",
39+
"-Xswiftc", "-cross-module-optimization",
40+
"--product", "wwk"
41+
bp = Utils.safe_popen_read(
4142
"swift", "build", "--show-bin-path", "--configuration", "release"
4243
).chomp
44+
system "cp", "#{bp}/wwk", staging.to_s
45+
46+
# Build wwkd, stage it
47+
system "swift", "build",
48+
"--configuration", "release",
49+
"--disable-sandbox",
50+
"-Xswiftc", "-cross-module-optimization",
51+
"--product", "wwkd"
52+
system "cp", "#{bp}/wwkd", staging.to_s
53+
54+
# Build WellWhaddyaKnow, stage it
55+
system "swift", "build",
56+
"--configuration", "release",
57+
"--disable-sandbox",
58+
"-Xswiftc", "-cross-module-optimization",
59+
"--product", "WellWhaddyaKnow"
60+
system "cp", "#{bp}/WellWhaddyaKnow", staging.to_s
4361

4462
# Install CLI and agent binaries
45-
bin.install "#{bin_path}/wwk"
46-
bin.install "#{bin_path}/wwkd"
63+
bin.install staging/"wwk"
64+
bin.install staging/"wwkd"
4765

4866
# Construct WellWhaddyaKnow.app bundle
4967
app_bundle = prefix/"WellWhaddyaKnow.app"
@@ -56,8 +74,8 @@ def install
5674
resources.mkpath
5775
la_dir.mkpath
5876

59-
cp "#{bin_path}/WellWhaddyaKnow", macos_dir/"WellWhaddyaKnow"
60-
cp "#{bin_path}/wwkd", macos_dir/"wwkd"
77+
cp staging/"WellWhaddyaKnow", macos_dir/"WellWhaddyaKnow"
78+
cp staging/"wwkd", macos_dir/"wwkd"
6179

6280
# Embed launchd plist (required for SMAppService)
6381
cp "Sources/WellWhaddyaKnowApp/LaunchAgents/com.daylily.wellwhaddyaknow.agent.plist",

0 commit comments

Comments
 (0)