@@ -776,7 +776,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
776
776
let scope = cbc. scope
777
777
let inputFileType = cbc. inputs. first? . fileType
778
778
let lookup = { self . lookup ( $0, cbc, delegate) }
779
- for buildOption in self . flattenedOrderedBuildOptions {
779
+ for buildOption in cbc . producer . effectiveFlattenedOrderedBuildOptions ( self ) {
780
780
guard let dependencyFormat = buildOption. dependencyFormat else {
781
781
continue
782
782
}
@@ -910,7 +910,12 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
910
910
911
911
// Add the additional outputs defined by the spec. These are not declared as outputs but should be processed by the tool separately.
912
912
let additionalEvaluatedOutputsResult = await additionalEvaluatedOutputs ( cbc, delegate)
913
- outputs. append ( contentsOf: additionalEvaluatedOutputsResult. outputs. map ( { delegate. createNode ( $0) } ) )
913
+ outputs. append ( contentsOf: additionalEvaluatedOutputsResult. outputs. map { output in
914
+ if let fileTypeIdentifier = output. fileType, let fileType = cbc. producer. lookupFileType ( identifier: fileTypeIdentifier) {
915
+ delegate. declareOutput ( FileToBuild ( absolutePath: output. path, fileType: fileType) )
916
+ }
917
+ return delegate. createNode ( output. path)
918
+ } )
914
919
915
920
if let infoPlistContent = additionalEvaluatedOutputsResult. generatedInfoPlistContent {
916
921
delegate. declareGeneratedInfoPlistContent ( infoPlistContent)
@@ -972,7 +977,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
972
977
}
973
978
974
979
public struct AdditionalEvaluatedOutputsResult {
975
- public var outputs = [ Path] ( )
980
+ public var outputs = [ ( path : Path, fileType : String ? ) ] ( )
976
981
public var generatedInfoPlistContent : Path ? = nil
977
982
}
978
983
@@ -988,20 +993,25 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
988
993
989
994
// FIXME: In Xcode, this is also marked as an "auxiliary output", which we use in conjunction with the "MightNotEmitAllOutput" flag to determine whether or not the tool needs to rerun if the output is missing.
990
995
991
- result. outputs. append ( output)
996
+ result. outputs. append ( ( output, nil ) )
992
997
}
993
998
994
999
let producer = cbc. producer
995
1000
let scope = cbc. scope
996
1001
let inputFileType = cbc. inputs. first? . fileType
997
1002
let lookup = { self . lookup ( $0, cbc, delegate) }
998
1003
let optionContext = await discoveredCommandLineToolSpecInfo ( producer, scope, delegate)
999
- result. outputs. append ( contentsOf: self . flattenedOrderedBuildOptions . flatMap { buildOption -> [ Path ] in
1004
+ result. outputs. append ( contentsOf: cbc . producer . effectiveFlattenedOrderedBuildOptions ( self , filter : . all ) . flatMap { buildOption -> [ ( Path , String ? ) ] in
1000
1005
// Check if the effective arguments for this build option were non-empty as a proxy for whether it got filtered out by architecture mismatch, etc.
1001
1006
guard let outputDependencies = buildOption. outputDependencies, !buildOption. getArgumentsForCommand ( producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext, lookup: lookup) . isEmpty else {
1002
1007
return [ ]
1003
1008
}
1004
- return outputDependencies. compactMap { Path ( scope. evaluate ( $0, lookup: lookup) ) . nilIfEmpty? . normalize ( ) }
1009
+ return outputDependencies. compactMap { outputDependency in
1010
+ guard let path = Path ( scope. evaluate ( outputDependency. path, lookup: lookup) ) . nilIfEmpty else {
1011
+ return nil
1012
+ }
1013
+ return ( path. normalize ( ) , outputDependency. fileType. map { scope. evaluate ( $0, lookup: lookup) . nilIfEmpty } ?? nil )
1014
+ }
1005
1015
} )
1006
1016
1007
1017
return result
@@ -1225,7 +1235,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
1225
1235
return cbc. scope. evaluate ( value, lookup: lookup) . map { . literal( ByteString ( encodingAsUTF8: $0) ) }
1226
1236
1227
1237
case . options:
1228
- return self . commandLineFromOptions ( cbc, delegate, optionContext: optionContext, lookup: lookup)
1238
+ return self . commandLineFromOptions ( cbc, delegate, optionContext: optionContext, buildOptionsFilter : . all , lookup: lookup)
1229
1239
1230
1240
case . output:
1231
1241
// We always resolve the Output via a recursive macro evaluation. See constructTasks() for more information.
@@ -1254,22 +1264,22 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
1254
1264
/// Creates and returns the command line arguments generated by the options of the specification.
1255
1265
///
1256
1266
/// - parameter lookup: An optional closure which functionally defined overriding values during build setting evaluation.
1257
- public func commandLineFromOptions( _ producer: any CommandProducer , scope: MacroEvaluationScope , inputFileType: FileTypeSpec ? , optionContext: ( any BuildOptionGenerationContext ) ? , lookup: ( ( MacroDeclaration ) -> MacroExpression ? ) ? = nil ) -> [ CommandLineArgument ] {
1258
- return self . flattenedOrderedBuildOptions . flatMap { $0. getArgumentsForCommand ( producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext, lookup: lookup) }
1267
+ public func commandLineFromOptions( _ producer: any CommandProducer , scope: MacroEvaluationScope , inputFileType: FileTypeSpec ? , optionContext: ( any BuildOptionGenerationContext ) ? , buildOptionsFilter : BuildOptionsFilter , lookup: ( ( MacroDeclaration ) -> MacroExpression ? ) ? = nil ) -> [ CommandLineArgument ] {
1268
+ return producer . effectiveFlattenedOrderedBuildOptions ( self , filter : buildOptionsFilter ) . flatMap { $0. getArgumentsForCommand ( producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext, lookup: lookup) }
1259
1269
}
1260
1270
1261
1271
/// Creates and returns the command line arguments generated by the options of the specification.
1262
1272
///
1263
1273
/// - parameter lookup: An optional closure which functionally defined overriding values during build setting evaluation.
1264
- public func commandLineFromOptions( _ cbc: CommandBuildContext , _ delegate: any DiagnosticProducingDelegate , optionContext: ( any BuildOptionGenerationContext ) ? , lookup: ( ( MacroDeclaration ) -> MacroExpression ? ) ? = nil ) -> [ CommandLineArgument ] {
1265
- return commandLineFromOptions ( cbc. producer, scope: cbc. scope, inputFileType: cbc. inputs. first? . fileType, optionContext: optionContext, lookup: { self . lookup ( $0, cbc, delegate, lookup) } )
1274
+ public func commandLineFromOptions( _ cbc: CommandBuildContext , _ delegate: any DiagnosticProducingDelegate , optionContext: ( any BuildOptionGenerationContext ) ? , buildOptionsFilter : BuildOptionsFilter = . all , lookup: ( ( MacroDeclaration ) -> MacroExpression ? ) ? = nil ) -> [ CommandLineArgument ] {
1275
+ return commandLineFromOptions ( cbc. producer, scope: cbc. scope, inputFileType: cbc. inputs. first? . fileType, optionContext: optionContext, buildOptionsFilter : buildOptionsFilter , lookup: { self . lookup ( $0, cbc, delegate, lookup) } )
1266
1276
}
1267
1277
1268
1278
/// Creates and returns the command line arguments generated by the specification's build setting corresponding to the given macro declaration.
1269
1279
///
1270
1280
/// - parameter lookup: An optional closure which functionally defined overriding values during build setting evaluation.
1271
1281
func commandLineFromMacroDeclaration( _ producer: any CommandProducer , optionContext: ( any BuildOptionGenerationContext ) ? , scope: MacroEvaluationScope , macro: MacroDeclaration , inputFileType: FileTypeSpec ? , lookup: ( ( MacroDeclaration ) -> MacroExpression ? ) ? = nil ) -> [ CommandLineArgument ] {
1272
- return buildOptions . first { $0. name == macro. name } ? . getArgumentsForCommand ( producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext, lookup: lookup) ?? [ ]
1282
+ return producer . effectiveBuildOptions ( self ) . first { $0. name == macro. name } ? . getArgumentsForCommand ( producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext, lookup: lookup) ?? [ ]
1273
1283
}
1274
1284
1275
1285
/// Creates and returns the command line arguments generated by the specification's build setting corresponding to the given macro declaration.
@@ -1285,7 +1295,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
1285
1295
let scope = cbc. scope
1286
1296
let inputFileType = cbc. inputs. first? . fileType
1287
1297
let lookup = { self . lookup ( $0, cbc, delegate, lookup) }
1288
- return self . flattenedOrderedBuildOptions . flatMap { buildOption -> [ Path ] in
1298
+ return cbc . producer . effectiveFlattenedOrderedBuildOptions ( self ) . flatMap { buildOption -> [ Path ] in
1289
1299
// Check if the effective arguments for this build option were non-empty as a proxy for whether it got filtered out by architecture mismatch, etc.
1290
1300
guard let inputInclusions = buildOption. inputInclusions, !buildOption. getArgumentsForCommand ( producer, scope: scope, inputFileType: inputFileType, optionContext: optionContext, lookup: lookup) . isEmpty else {
1291
1301
return [ ]
@@ -1297,7 +1307,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
1297
1307
/// Compute the list of additional linker arguments to use when this tool is used for building with the given scope.
1298
1308
public func computeAdditionalLinkerArgs( _ producer: any CommandProducer , scope: MacroEvaluationScope , inputFileTypes: [ FileTypeSpec ] , optionContext: ( any BuildOptionGenerationContext ) ? , delegate: any TaskGenerationDelegate ) async -> ( args: [ [ String ] ] , inputPaths: [ Path ] ) {
1299
1309
// FIXME: Optimize the list to search here.
1300
- return ( args: self . flattenedOrderedBuildOptions . map { $0. getAdditionalLinkerArgs ( producer, scope: scope, inputFileTypes: inputFileTypes) } , inputPaths: [ ] )
1310
+ return ( args: producer . effectiveFlattenedOrderedBuildOptions ( self ) . map { $0. getAdditionalLinkerArgs ( producer, scope: scope, inputFileTypes: inputFileTypes) } , inputPaths: [ ] )
1301
1311
}
1302
1312
1303
1313
// Creates and returns the environment from the specification. This includes both the 'EnvironmentVariables' property for this tool spec, and any build options which define that their value should be exported via their 'SetValueInEnvironmentVariable' property.
@@ -1313,7 +1323,7 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
1313
1323
1314
1324
// Add environment variables from build options which specify they should be added via a 'SetValueInEnvironmentVariable' property.
1315
1325
// FIXME: Optimize the list to search here.
1316
- for buildOption in self . flattenedOrderedBuildOptions {
1326
+ for buildOption in cbc . producer . effectiveFlattenedOrderedBuildOptions ( self ) {
1317
1327
if let assignment = buildOption. getEnvironmentAssignmentForCommand ( cbc, lookup: wrappedLookup) {
1318
1328
environment. append ( assignment)
1319
1329
}
0 commit comments