Skip to content

Commit 83f2b44

Browse files
committed
Correctly locate chown on all platforms
On Linux, chown is at /usr/bin/chown, while on BSDs it's at /usr/sbin/chown It was also being incorrectly located based on the target platform, which is incorrect. Only the host platform matters for this lookup. This meant macOS to Android or WebAssembly cross compilation, FreeBSD to Linux cross compilation, or FreeBSD native compilation could have failed if the build graph contained any chown commands. Also use a search path so we don't have to hardcode knowledge of any specific platform for this.
1 parent 4396e8a commit 83f2b44

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

Sources/SWBAndroidPlatform/Plugin.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ struct AndroidPlatformExtension: PlatformInfoExtension {
133133
"GENERATE_TEXT_BASED_STUBS": "NO",
134134
"GENERATE_INTERMEDIATE_TEXT_BASED_STUBS": "NO",
135135

136-
"CHOWN": "/usr/bin/chown",
137-
138136
"LIBTOOL": .plString(host.imageFormat.executableName(basename: "llvm-lib")),
139137
"AR": .plString(host.imageFormat.executableName(basename: "llvm-ar")),
140138
]

Sources/SWBCore/SpecImplementations/Tools/SetAttributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class SetAttributesSpec: CommandLineToolSpec, SpecImplementationTyp
5757
execDescription = "Set Group"
5858
}
5959

60-
let args = [cbc.scope.evaluate(BuiltinMacros.CHOWN).str, "-RH", attrs, input.absolutePath.str]
60+
let args = [resolveExecutablePath(cbc.producer, cbc.scope.evaluate(BuiltinMacros.CHOWN)).str, "-RH", attrs, input.absolutePath.str]
6161

6262
let commandOutput = delegate.createVirtualNode("SetOwner \(input.absolutePath.str)")
6363
let outputs: [any PlannedNode] = [delegate.createNode(input.absolutePath), commandOutput]

Sources/SWBCore/Specs/NativeBuildSystem.xcspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ When `GENERATE_INFOPLIST_FILE` is enabled, sets the value of the [CFBundleExecut
831831
},
832832
{ Name = CHOWN;
833833
Type = Path;
834-
DefaultValue = "/usr/sbin/chown";
834+
DefaultValue = "chown";
835835
},
836836
{ Name = CHMOD;
837837
Type = Path;

Sources/SWBGenericUnixPlatform/Plugin.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ struct GenericUnixSDKRegistryExtension: SDKRegistryExtension {
119119
"GENERATE_TEXT_BASED_STUBS": "NO",
120120
"GENERATE_INTERMEDIATE_TEXT_BASED_STUBS": "NO",
121121

122-
"CHOWN": "/usr/bin/chown",
123122
"AR": "llvm-ar",
124123
]
125124
default:

Sources/SWBWebAssemblyPlatform/Plugin.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ struct WebAssemblySDKRegistryExtension: SDKRegistryExtension {
6565
"GENERATE_TEXT_BASED_STUBS": "NO",
6666
"GENERATE_INTERMEDIATE_TEXT_BASED_STUBS": "NO",
6767

68-
"CHOWN": "/usr/bin/chown",
69-
7068
"LIBTOOL": .plString(host.imageFormat.executableName(basename: "llvm-lib")),
7169
"AR": .plString(host.imageFormat.executableName(basename: "llvm-ar")),
7270
]

Tests/SWBTaskConstructionTests/PostprocessingTaskConstructionTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ fileprivate struct PostprocessingTaskConstructionTests: CoreBasedTests {
6565

6666
let tester = try await TaskConstructionTester(getCore(), testProject)
6767

68+
let fs = PseudoFS()
69+
try fs.createDirectory(.root.join("usr").join("sbin"), recursive: true)
70+
try fs.write(.root.join("usr").join("sbin").join("chown"), contents: "")
71+
6872
let installParameters = BuildParameters(action: .install, configuration: "Debug")
69-
await tester.checkBuild(installParameters, runDestination: .macOS) { results in
73+
await tester.checkBuild(installParameters, runDestination: .macOS, processEnvironment: ["PATH": "/usr/bin:/usr/sbin"], fs: fs) { results in
7074
results.checkNoDiagnostics()
7175

7276
results.checkTarget("Library") { target in

Tests/SWBTaskConstructionTests/TaskConstructionTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,11 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
204204

205205
try await fs.writePlist(Path(SRCROOT).join("Entitlements.plist"), .plDict([:]))
206206

207+
try fs.createDirectory(.root.join("usr").join("sbin"), recursive: true)
208+
try fs.write(.root.join("usr").join("sbin").join("chown"), contents: "")
209+
207210
// Check the debug build.
208-
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["INFOPLIST_PREPROCESS": "YES", "COMBINE_HIDPI_IMAGES": "YES"]), runDestination: .macOS, fs: fs) { results -> Void in
211+
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["INFOPLIST_PREPROCESS": "YES", "COMBINE_HIDPI_IMAGES": "YES"]), runDestination: .macOS, processEnvironment: ["PATH": "/usr/bin:/usr/sbin"], fs: fs) { results -> Void in
209212
// There should be two warnings about our custom output files, since we won't reprocess the custom file it generates with the same name.
210213
results.checkWarning(.prefix("no rule to process file '\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/DerivedSources-normal/\(results.runDestinationTargetArchitecture)/Custom.fake-lang'"))
211214
results.checkWarning(.prefix("no rule to process file '\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/DerivedSources-normal/\(results.runDestinationTargetArchitecture)/en.lproj/Standard.fake-lang'"))
@@ -836,7 +839,7 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
836839
try await localFS.writePlist(Path(SRCROOT).join("Entitlements.plist"), .plDict([:]))
837840

838841
// Check an install release build.
839-
try await tester.checkBuild(BuildParameters(action: .install, configuration: "Release"), runDestination: .macOS, fs: localFS) { results -> Void in
842+
try await tester.checkBuild(BuildParameters(action: .install, configuration: "Release"), runDestination: .macOS, processEnvironment: ["PATH": "/usr/bin:/usr/sbin"], fs: localFS) { results -> Void in
840843
try results.checkTarget("AppTarget") { target -> Void in
841844
// There should be a symlink task.
842845
try results.checkTask(.matchTarget(target), .matchRuleType("SymLink")) { task in

0 commit comments

Comments
 (0)