Skip to content

Commit f5e366e

Browse files
authored
Merge pull request #787 from owenv/owenv/dsymutil-path
Set PATH in the env when invoking dsymutil so it can find lipo in another toolchain
2 parents c8ed9f9 + aaa865c commit f5e366e

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

Sources/SWBCore/SpecImplementations/Tools/DsymutilTool.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
public import SWBUtil
14-
import SWBMacro
14+
public import SWBMacro
1515

1616
public final class DsymutilToolSpec : GenericCommandLineToolSpec, SpecIdentifierType, @unchecked Sendable {
1717
public static let identifier = "com.apple.tools.dsymutil"
@@ -21,6 +21,13 @@ public final class DsymutilToolSpec : GenericCommandLineToolSpec, SpecIdentifier
2121
fatalError("unexpected direct invocation")
2222
}
2323

24+
public override func environmentFromSpec(_ cbc: CommandBuildContext, _ delegate: any DiagnosticProducingDelegate, lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> [(String, String)] {
25+
var env: [(String, String)] = super.environmentFromSpec(cbc, delegate, lookup: lookup)
26+
// dsymutil may need to lookup lipo, which is not necessarily in the same toolchain.
27+
env.append(("PATH", cbc.producer.executableSearchPaths.environmentRepresentation))
28+
return env
29+
}
30+
2431
/// Override construction to patch the inputs.
2532
public func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, dsymBundle: Path, buildVariant: String = "", dsymSearchPaths: [String] = [], quietOperation: Bool = false) async {
2633
let output = cbc.output
@@ -51,6 +58,6 @@ public final class DsymutilToolSpec : GenericCommandLineToolSpec, SpecIdentifier
5158

5259
let inputs: [any PlannedNode] = cbc.inputs.map({ delegate.createNode($0.absolutePath) }) + cbc.commandOrderingInputs
5360
let outputs: [any PlannedNode] = [delegate.createNode(output), orderingOutputNode] + cbc.commandOrderingOutputs
54-
delegate.createTask(type: self, ruleInfo: ruleInfo, commandLine: commandLine, environment: EnvironmentBindings(), workingDirectory: cbc.producer.defaultWorkingDirectory, inputs: inputs, outputs: outputs, action: nil, execDescription: resolveExecutionDescription(templateBuildContext, delegate), enableSandboxing: enableSandboxing)
61+
delegate.createTask(type: self, ruleInfo: ruleInfo, commandLine: commandLine, environment: environmentFromSpec(cbc, delegate), workingDirectory: cbc.producer.defaultWorkingDirectory, inputs: inputs, outputs: outputs, action: nil, execDescription: resolveExecutionDescription(templateBuildContext, delegate), enableSandboxing: enableSandboxing)
5562
}
5663
}

Tests/SWBTaskConstructionTests/DebugInformationTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,41 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
329329
}
330330
}
331331

332+
@Test(.requireSDKs(.macOS))
333+
func dsymutilEnvironment() async throws {
334+
let testProject = TestProject(
335+
"aProject",
336+
groupTree: TestGroup(
337+
"SomeFiles", path: "Sources",
338+
children: [
339+
TestFile("main.c"),
340+
]),
341+
buildConfigurations: [
342+
TestBuildConfiguration(
343+
"Debug",
344+
buildSettings: [
345+
"GENERATE_INFOPLIST_FILE": "YES",
346+
"PRODUCT_NAME": "$(TARGET_NAME)",
347+
"ALWAYS_SEARCH_USER_PATHS": "NO",
348+
"DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym",
349+
]),
350+
],
351+
targets: [
352+
TestStandardTarget(
353+
"CoreFoo", type: .framework,
354+
buildPhases: [
355+
TestSourcesBuildPhase(["main.c"])]),
356+
])
357+
let tester = try await TaskConstructionTester(getCore(), testProject)
358+
359+
let buildParameters = BuildParameters(configuration: "Debug")
360+
361+
await tester.checkBuild(buildParameters, runDestination: .macOS) { results in
362+
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo")) { task in
363+
results.checkNoDiagnostics()
364+
// Ensure PATH is set in the dsymutil environment.
365+
task.checkEnvironment(["PATH": .any])
366+
}
367+
}
368+
}
332369
}

0 commit comments

Comments
 (0)