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
2 changes: 1 addition & 1 deletion Sources/SWBApplePlatform/AssetCatalogCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class ActoolCompilerSpec : GenericCompilerSpec, SpecIdentifierType,
}

private func assetTagCombinations(catalogInputs inputs: [FileToBuild], _ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async throws -> Set<Set<String>> {
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
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
struct AssetCatalogToolOutput: Decodable {
struct Diagnostic: Decodable {
let description: String
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBApplePlatform/InterfaceBuilderCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ public final class IbtoolCompilerSpecStoryboard: IbtoolCompilerSpec, SpecIdentif
}
}

override public func commandLineFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> [CommandLineArgument] {
var commandLine = super.commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup)
override public func commandLineFromTemplate(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, optionContext: (any DiscoveredCommandLineToolSpecInfo)?, specialArgs: [String] = [], lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) async -> [CommandLineArgument] {
var commandLine = await super.commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup)
guard let primaryOutput = evaluatedOutputs(cbc, delegate)?.first else {
delegate.error("Unable to determine primary output for storyboard compilation")
return []
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBApplePlatform/MiGCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class MigCompilerSpec : CompilerSpec, SpecIdentifierType, @unchecke
return cbc.scope.migExecutablePath().str
}

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

Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBApplePlatform/OpenCLCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class OpenCLCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible

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

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

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

var commandLine = [resolveExecutablePath(cbc, Path(openclc)).str]
var commandLine = [await resolveExecutablePath(cbc, Path(openclc), delegate: delegate).str]
commandLine += ["-x", "cl", compilerVersionFlag]
if scope.evaluate(BuiltinMacros.OPENCL_MAD_ENABLE) {
commandLine.append("-cl-mad-enable")
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBApplePlatform/ResMergerLinkerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class ResMergerLinkerSpec : GenericLinkerSpec, SpecIdentifierType,

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

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

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

commandLine += BuiltinMacros.ifSet(BuiltinMacros.MACOS_TYPE, in: cbc.scope) { ["-fileType", $0] }
Expand Down
6 changes: 3 additions & 3 deletions Sources/SWBApplePlatform/XCStringsCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class XCStringsCompilerSpec: GenericCompilerSpec, SpecIdentifierTyp
}

if shouldGenerateSymbols(cbc) {
constructSymbolGenerationTask(cbc, delegate)
await constructSymbolGenerationTask(cbc, delegate)
}

if shouldCompileCatalog(cbc) {
Expand Down Expand Up @@ -138,10 +138,10 @@ public final class XCStringsCompilerSpec: GenericCompilerSpec, SpecIdentifierTyp
}

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

// For now shouldGenerateSymbols only returns true if there are Swift sources.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBCore/PlannedTaskAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public struct FileCopyTaskActionContext {
extension FileCopyTaskActionContext {
public init(_ cbc: CommandBuildContext) {
let compilerPath = cbc.producer.clangSpec.resolveExecutablePath(cbc, forLanguageOfFileType: cbc.producer.lookupFileType(languageDialect: .c))
let linkerPath = cbc.producer.ldLinkerSpec.resolveExecutablePath(cbc, Path(cbc.producer.ldLinkerSpec.computeExecutablePath(cbc)))
let lipoPath = cbc.producer.lipoSpec.resolveExecutablePath(cbc, Path(cbc.producer.lipoSpec.computeExecutablePath(cbc)))
let linkerPath = cbc.producer.ldLinkerSpec.resolveExecutablePath(cbc.producer, Path(cbc.producer.ldLinkerSpec.computeExecutablePath(cbc)))
let lipoPath = cbc.producer.lipoSpec.resolveExecutablePath(cbc.producer, Path(cbc.producer.lipoSpec.computeExecutablePath(cbc)))

// 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.
if compilerPath.isEmpty || !compilerPath.isAbsolute || cbc.scope.evaluate(BuiltinMacros.BUILD_COMPONENTS).contains("installLoc") {
Expand Down
20 changes: 13 additions & 7 deletions Sources/SWBCore/SpecImplementations/CommandLineToolSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,13 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
let optionContext = await discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate)

// Compute the command line arguments from the template.
let commandLine = commandLine ?? commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup).map(\.asString)
let providedCommandLine = commandLine
let commandLine: [String]
if let providedCommandLine {
commandLine = providedCommandLine
} else {
commandLine = await commandLineFromTemplate(cbc, delegate, optionContext: optionContext, specialArgs: specialArgs, lookup: lookup).map(\.asString)
}

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

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

Expand Down Expand Up @@ -1185,14 +1191,14 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
return executionDescription
}

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

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

Expand Down Expand Up @@ -1239,13 +1245,13 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
// Resolve the executable path.
//
// 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).
args[0] = { path in
args[0] = await { path in
if path.asString.hasPrefix("builtin-") || (path.asString.hasPrefix("<") && path.asString.hasSuffix(">")) {
return path
}

// Otherwise, look up the path if necessary.
return .path(resolveExecutablePath(cbc, Path(path.asString)))
return .path(await resolveExecutablePath(cbc, Path(path.asString), delegate: delegate))
}(args[0])

return args
Expand Down
10 changes: 5 additions & 5 deletions Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible

// Start with the executable.
let compilerExecPath = resolveExecutablePath(cbc, forLanguageOfFileType: resolvedInputFileType)
let launcher = resolveCompilerLauncher(cbc, compilerPath: compilerExecPath, delegate: delegate)
let launcher = await resolveCompilerLauncher(cbc, compilerPath: compilerExecPath, delegate: delegate)
if let launcher {
commandLine += [launcher.str]
}
Expand Down Expand Up @@ -1114,7 +1114,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
}

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

// Add dependencies on the SDK used.

Expand Down Expand Up @@ -1426,7 +1426,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
}

/// Adds the arguments to use the prefix header, in the appropriate manner for the target.
private func addPrefixHeaderArgs(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, inputFileType: FileTypeSpec, perFileFlags: [String], inputDeps: inout [Path], commandLine: inout [String], clangInfo: DiscoveredClangToolSpecInfo?) -> ClangPrefixInfo? {
private func addPrefixHeaderArgs(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, inputFileType: FileTypeSpec, perFileFlags: [String], inputDeps: inout [Path], commandLine: inout [String], clangInfo: DiscoveredClangToolSpecInfo?) async -> ClangPrefixInfo? {
// Don't use the prefix header if the input file opted out.
guard cbc.inputs[0].shouldUsePrefixHeader else {
return nil
Expand Down Expand Up @@ -1824,11 +1824,11 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
private func resolveCompilerLauncher(_ cbc: CommandBuildContext, compilerPath: Path, delegate: any TaskGenerationDelegate) -> Path? {
let value = cbc.scope.evaluate(BuiltinMacros.C_COMPILER_LAUNCHER)
if !value.isEmpty {
return resolveExecutablePath(cbc, Path(value))
return resolveExecutablePath(cbc.producer, Path(value))
}
if cbc.scope.evaluate(BuiltinMacros.CLANG_CACHE_ENABLE_LAUNCHER) {
let name = Path("clang-cache")
let resolved = resolveExecutablePath(cbc, name)
let resolved = resolveExecutablePath(cbc.producer, name)
// Only set it as launcher if it has been found and is next to the compiler.
if resolved != name && resolved.dirname == compilerPath.dirname {
return resolved
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/SpecImplementations/Tools/CodeSign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class CodesignToolSpec : CommandLineToolSpec, SpecIdentifierType, @
codesign = Path("/usr/bin/codesign")
}
if !codesign.isAbsolute {
codesign = resolveExecutablePath(cbc, codesign)
codesign = resolveExecutablePath(cbc.producer, codesign)
}
return codesign.str
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/SpecImplementations/Tools/CopyTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public final class CopyToolSpec : CompilerSpec, SpecIdentifierType, @unchecked S
// FIXME: The same comment above (w.r.t. how to bind this logic) applies here.
if cbc.scope.evaluate(BuiltinMacros.PBXCP_STRIP_UNSIGNED_BINARIES, lookup: lookup) || !cbc.scope.evaluate(BuiltinMacros.PBXCP_STRIP_SUBPATHS, lookup: lookup).isEmpty {
let insertIndex = commandLine.firstIndex(of: "-resolve-src-symlinks") ?? commandLine.endIndex
commandLine.replaceSubrange(insertIndex..<insertIndex, with: ["-strip-tool", resolveExecutablePath(cbc, Path("strip")).str])
commandLine.replaceSubrange(insertIndex..<insertIndex, with: ["-strip-tool", resolveExecutablePath(cbc.producer, Path("strip")).str])
}

// Skip the copy without erroring if the input item is missing. This is used for handling embedded bundles with the installloc action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ final public class DocumentationCompilerSpec: GenericCompilerSpec, SpecIdentifie
return nil
}

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

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