Skip to content

Commit f741881

Browse files
authored
Merge pull request #612 from swiftlang/owenv/digester-lookup
2 parents eb6551d + 035d5a6 commit f741881

24 files changed

+70
-46
lines changed

Sources/SWBApplePlatform/AssetCatalogCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public final class ActoolCompilerSpec : GenericCompilerSpec, SpecIdentifierType,
5555
}
5656

5757
private func assetTagCombinations(catalogInputs inputs: [FileToBuild], _ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async throws -> Set<Set<String>> {
58-
return try await executeExternalTool(cbc, delegate, commandLine: [resolveExecutablePath(cbc, cbc.scope.actoolExecutablePath()).str, "--print-asset-tag-combinations", "--output-format", "xml1"] + inputs.map { $0.absolutePath.str }, workingDirectory: cbc.producer.defaultWorkingDirectory, environment: environmentFromSpec(cbc, delegate).bindingsDictionary, executionDescription: "Compute asset tag combinations") { output in
58+
return try await executeExternalTool(cbc, delegate, commandLine: [resolveExecutablePath(cbc, cbc.scope.actoolExecutablePath(), delegate: delegate).str, "--print-asset-tag-combinations", "--output-format", "xml1"] + inputs.map { $0.absolutePath.str }, workingDirectory: cbc.producer.defaultWorkingDirectory, environment: environmentFromSpec(cbc, delegate).bindingsDictionary, executionDescription: "Compute asset tag combinations") { output in
5959
struct AssetCatalogToolOutput: Decodable {
6060
struct Diagnostic: Decodable {
6161
let description: String

Sources/SWBApplePlatform/InterfaceBuilderCompiler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ public final class IbtoolCompilerSpecStoryboard: IbtoolCompilerSpec, SpecIdentif
171171
}
172172
}
173173

174-
override public func commandLineFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> [CommandLineArgument] {
175-
var commandLine = super.commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup)
174+
override public func commandLineFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) async -> [CommandLineArgument] {
175+
var commandLine = await super.commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup)
176176
guard let primaryOutput = evaluatedOutputs(cbc, delegate)?.first else {
177177
delegate.error("Unable to determine primary output for storyboard compilation")
178178
return []

Sources/SWBApplePlatform/MiGCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public final class MigCompilerSpec : CompilerSpec, SpecIdentifierType, @unchecke
3838
return cbc.scope.migExecutablePath().str
3939
}
4040

41-
public override func resolveExecutablePath(_ cbc: CommandBuildContext, _ path: Path) -> Path {
41+
public override func resolveExecutablePath(_ cbc: CommandBuildContext, _ path: Path, delegate: any CoreClientTargetDiagnosticProducingDelegate) async -> Path {
4242
return resolveExecutablePath(cbc.producer, Path(computeExecutablePath(cbc)))
4343
}
4444

Sources/SWBApplePlatform/OpenCLCompiler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ final class OpenCLCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
6969

7070
let executionDescription = "Create \(arch) bitcode for \(filePath.basename)"
7171

72-
var commandLine = [resolveExecutablePath(cbc, Path(openclc)).str]
72+
var commandLine = [await resolveExecutablePath(cbc, Path(openclc), delegate: delegate).str]
7373
commandLine += ["-x", "cl", compilerVersionFlag]
7474
optimizationLevelFlag.map{ commandLine.append($0) }
7575
commandLine += preprocessorDefinitionsFlags
@@ -101,7 +101,7 @@ final class OpenCLCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
101101

102102
let ruleInfo = ["Compile", filePath.str]
103103

104-
var commandLine = [resolveExecutablePath(cbc, Path(openclc)).str]
104+
var commandLine = [await resolveExecutablePath(cbc, Path(openclc), delegate: delegate).str]
105105
commandLine += ["-x", "cl", compilerVersionFlag]
106106
if scope.evaluate(BuiltinMacros.OPENCL_MAD_ENABLE) {
107107
commandLine.append("-cl-mad-enable")

Sources/SWBApplePlatform/ResMergerLinkerSpec.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class ResMergerLinkerSpec : GenericLinkerSpec, SpecIdentifierType,
2424

2525
let environment: EnvironmentBindings = environmentFromSpec(cbc, delegate)
2626
do {
27-
var commandLine = [resolveExecutablePath(cbc, Path("ResMerger")).str]
27+
var commandLine = [await resolveExecutablePath(cbc, Path("ResMerger"), delegate: delegate).str]
2828

2929
commandLine += BuiltinMacros.ifSet(BuiltinMacros.MACOS_TYPE, in: cbc.scope) { ["-fileType", $0] }
3030
commandLine += BuiltinMacros.ifSet(BuiltinMacros.MACOS_CREATOR, in: cbc.scope) { ["-fileCreator", $0] }
@@ -64,7 +64,7 @@ public final class ResMergerLinkerSpec : GenericLinkerSpec, SpecIdentifierType,
6464
outputPath = outputPath.join(cbc.scope.evaluate(BuiltinMacros.PRODUCT_NAME) + ".rsrc")
6565
}
6666

67-
var commandLine = [resolveExecutablePath(cbc, Path("ResMerger")).str]
67+
var commandLine = [await resolveExecutablePath(cbc, Path("ResMerger"), delegate: delegate).str]
6868
commandLine.append(tmpOutputPath.str)
6969

7070
commandLine += BuiltinMacros.ifSet(BuiltinMacros.MACOS_TYPE, in: cbc.scope) { ["-fileType", $0] }

Sources/SWBApplePlatform/XCStringsCompiler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public final class XCStringsCompilerSpec: GenericCompilerSpec, SpecIdentifierTyp
4949
}
5050

5151
if shouldGenerateSymbols(cbc) {
52-
constructSymbolGenerationTask(cbc, delegate)
52+
await constructSymbolGenerationTask(cbc, delegate)
5353
}
5454

5555
if shouldCompileCatalog(cbc) {
@@ -138,10 +138,10 @@ public final class XCStringsCompilerSpec: GenericCompilerSpec, SpecIdentifierTyp
138138
}
139139

140140
/// Generates a task for generating code symbols for strings.
141-
private func constructSymbolGenerationTask(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) {
141+
private func constructSymbolGenerationTask(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async {
142142
// The template spec file contains fields suitable for the compilation step.
143143
// But here we construct a custom command line for symbol generation.
144-
let execPath = resolveExecutablePath(cbc, Path("xcstringstool"))
144+
let execPath = await resolveExecutablePath(cbc, Path("xcstringstool"), delegate: delegate)
145145
var commandLine = [execPath.str, "generate-symbols"]
146146

147147
// For now shouldGenerateSymbols only returns true if there are Swift sources.

Sources/SWBCore/PlannedTaskAction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ public struct FileCopyTaskActionContext {
264264
extension FileCopyTaskActionContext {
265265
public init(_ cbc: CommandBuildContext) {
266266
let compilerPath = cbc.producer.clangSpec.resolveExecutablePath(cbc, forLanguageOfFileType: cbc.producer.lookupFileType(languageDialect: .c))
267-
let linkerPath = cbc.producer.ldLinkerSpec.resolveExecutablePath(cbc, Path(cbc.producer.ldLinkerSpec.computeExecutablePath(cbc)))
268-
let lipoPath = cbc.producer.lipoSpec.resolveExecutablePath(cbc, Path(cbc.producer.lipoSpec.computeExecutablePath(cbc)))
267+
let linkerPath = cbc.producer.ldLinkerSpec.resolveExecutablePath(cbc.producer, Path(cbc.producer.ldLinkerSpec.computeExecutablePath(cbc)))
268+
let lipoPath = cbc.producer.lipoSpec.resolveExecutablePath(cbc.producer, Path(cbc.producer.lipoSpec.computeExecutablePath(cbc)))
269269

270270
// If we couldn't find clang, skip the special stub binary handling. We may be using an Open Source toolchain which only has Swift. Also skip it for installLoc builds.
271271
if compilerPath.isEmpty || !compilerPath.isAbsolute || cbc.scope.evaluate(BuiltinMacros.BUILD_COMPONENTS).contains("installLoc") {

Sources/SWBCore/SpecImplementations/CommandLineToolSpec.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,13 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
876876
let optionContext = await discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate)
877877

878878
// Compute the command line arguments from the template.
879-
let commandLine = commandLine ?? commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup).map(\.asString)
879+
let providedCommandLine = commandLine
880+
let commandLine: [String]
881+
if let providedCommandLine {
882+
commandLine = providedCommandLine
883+
} else {
884+
commandLine = await commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup).map(\.asString)
885+
}
880886

881887
// Compute the environment variables to set.
882888
var environment: [(String, String)] = environmentFromSpec(cbc, delegate, lookup: lookup)
@@ -1152,7 +1158,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
11521158
}
11531159

11541160
/// Resolve an executable path or name to an absolute path.
1155-
open func resolveExecutablePath(_ cbc: CommandBuildContext, _ path: Path) -> Path {
1161+
open func resolveExecutablePath(_ cbc: CommandBuildContext, _ path: Path, delegate: any CoreClientTargetDiagnosticProducingDelegate) async -> Path {
11561162
return resolveExecutablePath(cbc.producer, path)
11571163
}
11581164

@@ -1185,14 +1191,14 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
11851191
return executionDescription
11861192
}
11871193

1188-
open func commandLineFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> [CommandLineArgument] {
1189-
return commandLineArgumentsFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup)
1194+
open func commandLineFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) async -> [CommandLineArgument] {
1195+
return await commandLineArgumentsFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup)
11901196
}
11911197

11921198
/// Creates and returns the command line from the template provided by the specification.
11931199
/// - parameter specialArgs: Used to replace the `special-args` placeholder in the command line template.
11941200
/// - parameter lookup: An optional closure which functionally defined overriding values during build setting evaluation.
1195-
public func commandLineArgumentsFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> [CommandLineArgument] {
1201+
public func commandLineArgumentsFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) async -> [CommandLineArgument] {
11961202
let commandLineTemplate = self.commandLineTemplate!
11971203
let lookup = { self.lookup($0, cbc, delegate, lookup) }
11981204

@@ -1239,13 +1245,13 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
12391245
// Resolve the executable path.
12401246
//
12411247
// FIXME: It would be nice to just move this to a specific handler for this first item in the template array (we could generalize the existing ExecPath key for this purpose).
1242-
args[0] = { path in
1248+
args[0] = await { path in
12431249
if path.asString.hasPrefix("builtin-") || (path.asString.hasPrefix("<") && path.asString.hasSuffix(">")) {
12441250
return path
12451251
}
12461252

12471253
// Otherwise, look up the path if necessary.
1248-
return .path(resolveExecutablePath(cbc, Path(path.asString)))
1254+
return .path(await resolveExecutablePath(cbc, Path(path.asString), delegate: delegate))
12491255
}(args[0])
12501256

12511257
return args

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
10561056

10571057
// Start with the executable.
10581058
let compilerExecPath = resolveExecutablePath(cbc, forLanguageOfFileType: resolvedInputFileType)
1059-
let launcher = resolveCompilerLauncher(cbc, compilerPath: compilerExecPath, delegate: delegate)
1059+
let launcher = await resolveCompilerLauncher(cbc, compilerPath: compilerExecPath, delegate: delegate)
10601060
if let launcher {
10611061
commandLine += [launcher.str]
10621062
}
@@ -1114,7 +1114,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
11141114
}
11151115

11161116
// Add the prefix header arguments, if used.
1117-
let prefixInfo = addPrefixHeaderArgs(cbc, delegate, inputFileType: resolvedInputFileType, perFileFlags: perFileFlags, inputDeps: &inputDeps, commandLine: &commandLine, clangInfo: clangInfo)
1117+
let prefixInfo = await addPrefixHeaderArgs(cbc, delegate, inputFileType: resolvedInputFileType, perFileFlags: perFileFlags, inputDeps: &inputDeps, commandLine: &commandLine, clangInfo: clangInfo)
11181118

11191119
// Add dependencies on the SDK used.
11201120

@@ -1426,7 +1426,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
14261426
}
14271427

14281428
/// Adds the arguments to use the prefix header, in the appropriate manner for the target.
1429-
private func addPrefixHeaderArgs(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, inputFileType: FileTypeSpec, perFileFlags: [String], inputDeps: inout [Path], commandLine: inout [String], clangInfo: DiscoveredClangToolSpecInfo?) -> ClangPrefixInfo? {
1429+
private func addPrefixHeaderArgs(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, inputFileType: FileTypeSpec, perFileFlags: [String], inputDeps: inout [Path], commandLine: inout [String], clangInfo: DiscoveredClangToolSpecInfo?) async -> ClangPrefixInfo? {
14301430
// Don't use the prefix header if the input file opted out.
14311431
guard cbc.inputs[0].shouldUsePrefixHeader else {
14321432
return nil
@@ -1824,11 +1824,11 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
18241824
private func resolveCompilerLauncher(_ cbc: CommandBuildContext, compilerPath: Path, delegate: any TaskGenerationDelegate) -> Path? {
18251825
let value = cbc.scope.evaluate(BuiltinMacros.C_COMPILER_LAUNCHER)
18261826
if !value.isEmpty {
1827-
return resolveExecutablePath(cbc, Path(value))
1827+
return resolveExecutablePath(cbc.producer, Path(value))
18281828
}
18291829
if cbc.scope.evaluate(BuiltinMacros.CLANG_CACHE_ENABLE_LAUNCHER) {
18301830
let name = Path("clang-cache")
1831-
let resolved = resolveExecutablePath(cbc, name)
1831+
let resolved = resolveExecutablePath(cbc.producer, name)
18321832
// Only set it as launcher if it has been found and is next to the compiler.
18331833
if resolved != name && resolved.dirname == compilerPath.dirname {
18341834
return resolved

Sources/SWBCore/SpecImplementations/Tools/CodeSign.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public final class CodesignToolSpec : CommandLineToolSpec, SpecIdentifierType, @
2323
codesign = Path("/usr/bin/codesign")
2424
}
2525
if !codesign.isAbsolute {
26-
codesign = resolveExecutablePath(cbc, codesign)
26+
codesign = resolveExecutablePath(cbc.producer, codesign)
2727
}
2828
return codesign.str
2929
}

Sources/SWBCore/SpecImplementations/Tools/CopyTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public final class CopyToolSpec : CompilerSpec, SpecIdentifierType, @unchecked S
129129
// FIXME: The same comment above (w.r.t. how to bind this logic) applies here.
130130
if cbc.scope.evaluate(BuiltinMacros.PBXCP_STRIP_UNSIGNED_BINARIES, lookup: lookup) || !cbc.scope.evaluate(BuiltinMacros.PBXCP_STRIP_SUBPATHS, lookup: lookup).isEmpty {
131131
let insertIndex = commandLine.firstIndex(of: "-resolve-src-symlinks") ?? commandLine.endIndex
132-
commandLine.replaceSubrange(insertIndex..<insertIndex, with: ["-strip-tool", resolveExecutablePath(cbc, Path("strip")).str])
132+
commandLine.replaceSubrange(insertIndex..<insertIndex, with: ["-strip-tool", resolveExecutablePath(cbc.producer, Path("strip")).str])
133133
}
134134

135135
// Skip the copy without erroring if the input item is missing. This is used for handling embedded bundles with the installloc action.

Sources/SWBCore/SpecImplementations/Tools/DocumentationCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ final public class DocumentationCompilerSpec: GenericCompilerSpec, SpecIdentifie
222222
return nil
223223
}
224224

225-
let commandLine = commandLineFromTemplate(cbc, delegate, optionContext: specInfo, specialArgs: symbolGraphArgs + documentationKindArgs, lookup: lookup).map(\.asString)
225+
let commandLine = await commandLineFromTemplate(cbc, delegate, optionContext: specInfo, specialArgs: symbolGraphArgs + documentationKindArgs, lookup: lookup).map(\.asString)
226226

227227
// Attach a payload with information about what built documentation this task will output.
228228
let outputDir = cbc.scope.evaluate(BuiltinMacros.DOCC_ARCHIVE_PATH)

0 commit comments

Comments
 (0)