Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/SWBCore/SpecImplementations/Tools/DsymutilTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

public import SWBUtil
import SWBMacro
public import SWBMacro

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

public override func environmentFromSpec(_ cbc: CommandBuildContext, _ delegate: any DiagnosticProducingDelegate, lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> [(String, String)] {
var env: [(String, String)] = super.environmentFromSpec(cbc, delegate, lookup: lookup)
// dsymutil may need to lookup lipo, which is not necessarily in the same toolchain.
env.append(("PATH", cbc.producer.executableSearchPaths.environmentRepresentation))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this particular PR is about lipo but note that PATH is usually spelled Path on Windows -- this might be a good opportunity to switch out String for EnvironmentKey in a few more places, though I can understand if that's too far outside the scope of what you're aiming to fix right now.

return env
}

/// Override construction to patch the inputs.
public func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, dsymBundle: Path, buildVariant: String = "", dsymSearchPaths: [String] = [], quietOperation: Bool = false) async {
let output = cbc.output
Expand Down Expand Up @@ -51,6 +58,6 @@ public final class DsymutilToolSpec : GenericCommandLineToolSpec, SpecIdentifier

let inputs: [any PlannedNode] = cbc.inputs.map({ delegate.createNode($0.absolutePath) }) + cbc.commandOrderingInputs
let outputs: [any PlannedNode] = [delegate.createNode(output), orderingOutputNode] + cbc.commandOrderingOutputs
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)
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)
}
}
37 changes: 37 additions & 0 deletions Tests/SWBTaskConstructionTests/DebugInformationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,41 @@ fileprivate struct DebugInformationTests: CoreBasedTests {
}
}

@Test(.requireSDKs(.macOS))
func dsymutilEnvironment() async throws {
let testProject = TestProject(
"aProject",
groupTree: TestGroup(
"SomeFiles", path: "Sources",
children: [
TestFile("main.c"),
]),
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"GENERATE_INFOPLIST_FILE": "YES",
"PRODUCT_NAME": "$(TARGET_NAME)",
"ALWAYS_SEARCH_USER_PATHS": "NO",
"DEBUG_INFORMATION_FORMAT": "dwarf-with-dsym",
]),
],
targets: [
TestStandardTarget(
"CoreFoo", type: .framework,
buildPhases: [
TestSourcesBuildPhase(["main.c"])]),
])
let tester = try await TaskConstructionTester(getCore(), testProject)

let buildParameters = BuildParameters(configuration: "Debug")

await tester.checkBuild(buildParameters, runDestination: .macOS) { results in
results.checkTask(.matchRuleType("GenerateDSYMFile"), .matchRuleItemBasename("CoreFoo")) { task in
results.checkNoDiagnostics()
// Ensure PATH is set in the dsymutil environment.
task.checkEnvironment(["PATH": .any])
}
}
}
}