@@ -76,7 +76,7 @@ extension TargetGUIDSuffix? {
76
76
77
77
extension PackageModel . Module {
78
78
func pifTargetGUID( suffix: TargetGUIDSuffix ? = nil ) -> GUID {
79
- PIFPackageBuilder . targetGUID ( forModuleName: self . name, suffix: suffix)
79
+ PackagePIFBuilder . targetGUID ( forModuleName: self . name, suffix: suffix)
80
80
}
81
81
}
82
82
@@ -88,7 +88,7 @@ extension PackageGraph.ResolvedModule {
88
88
89
89
extension PackageModel . Product {
90
90
func pifTargetGUID( suffix: TargetGUIDSuffix ? = nil ) -> GUID {
91
- PIFPackageBuilder . targetGUID ( forProductName: self . name, suffix: suffix)
91
+ PackagePIFBuilder . targetGUID ( forProductName: self . name, suffix: suffix)
92
92
}
93
93
}
94
94
@@ -105,7 +105,7 @@ extension PackageGraph.ResolvedProduct {
105
105
}
106
106
}
107
107
108
- extension PIFPackageBuilder {
108
+ extension PackagePIFBuilder {
109
109
/// Helper function to consistently generate a PIF target identifier string for a module in a package.
110
110
///
111
111
/// This format helps make sure that there is no collision with any other PIF targets,
@@ -140,13 +140,13 @@ extension PackageModel.Package {
140
140
}
141
141
142
142
var packageBaseBuildSettings : ProjectModel . BuildSettings {
143
- var settings = SwiftBuild . ProjectModel . BuildSettings ( )
144
- settings. SDKROOT = " auto "
145
- settings. SDK_VARIANT = " auto "
143
+ var settings = BuildSettings ( )
144
+ settings [ . SDKROOT] = " auto "
145
+ settings [ . SDK_VARIANT] = " auto "
146
146
147
147
if self . manifest. toolsVersion >= ToolsVersion . v6_0 {
148
148
if let version = manifest. version, !version. isPrerelease && !version. hasBuildMetadata {
149
- settings. SWIFT_USER_MODULE_VERSION = version. stringRepresentation
149
+ settings [ . SWIFT_USER_MODULE_VERSION] = version. stringRepresentation
150
150
}
151
151
}
152
152
return settings
@@ -203,22 +203,22 @@ extension PackageModel.Platform {
203
203
}
204
204
205
205
extension Sequence < PackageModel . PackageCondition > {
206
- func toPlatformFilter( toolsVersion: ToolsVersion ) -> Set < SwiftBuild . ProjectModel . PlatformFilter > {
207
- let pifPlatforms = self . flatMap { packageCondition -> [ SwiftBuild . ProjectModel . BuildSettings . Platform ] in
206
+ func toPlatformFilter( toolsVersion: ToolsVersion ) -> Set < ProjectModel . PlatformFilter > {
207
+ let pifPlatforms = self . flatMap { packageCondition -> [ ProjectModel . BuildSettings . Platform ] in
208
208
guard let platforms = packageCondition. platformsCondition? . platforms else {
209
209
return [ ]
210
210
}
211
211
212
- var pifPlatformsForCondition : [ SwiftBuild . ProjectModel . BuildSettings . Platform ] = platforms
213
- . map { SwiftBuild . ProjectModel. BuildSettings. Platform ( from: $0) }
212
+ var pifPlatformsForCondition : [ ProjectModel . BuildSettings . Platform ] = platforms
213
+ . map { ProjectModel . BuildSettings. Platform ( from: $0) }
214
214
215
215
// Treat catalyst like macOS for backwards compatibility with older tools versions.
216
216
if pifPlatformsForCondition. contains ( . macOS) , toolsVersion < ToolsVersion . v5_5 {
217
217
pifPlatformsForCondition. append ( . macCatalyst)
218
218
}
219
219
return pifPlatformsForCondition
220
220
}
221
- return pifPlatforms. toPlatformFilter ( )
221
+ return Set ( pifPlatforms. flatMap { $0 . toPlatformFilter ( ) } )
222
222
}
223
223
224
224
var splitIntoConcreteConditions : (
@@ -290,7 +290,7 @@ extension PackageGraph.ResolvedPackage {
290
290
}
291
291
292
292
/// The options declared per platform.
293
- func sdkOptions( delegate: PIFPackageBuilder . BuildDelegate ) -> [ PackageModel . Platform : [ String ] ] {
293
+ func sdkOptions( delegate: PackagePIFBuilder . BuildDelegate ) -> [ PackageModel . Platform : [ String ] ] {
294
294
let platformDescriptionsByName : [ String : PlatformDescription ] = Dictionary (
295
295
uniqueKeysWithValues: self . manifest. platforms. map { platformDescription in
296
296
let key = platformDescription. platformName. lowercased ( )
@@ -313,7 +313,7 @@ extension PackageGraph.ResolvedPackage {
313
313
}
314
314
315
315
extension PackageGraph . ResolvedPackage {
316
- public var packageBaseBuildSettings : SwiftBuild . ProjectModel . BuildSettings {
316
+ public var packageBaseBuildSettings : ProjectModel . BuildSettings {
317
317
self . underlying. packageBaseBuildSettings
318
318
}
319
319
}
@@ -337,7 +337,7 @@ extension PackageGraph.ResolvedModule {
337
337
}
338
338
339
339
/// Minimum deployment targets for particular platforms, as declared in the manifest.
340
- func deploymentTargets( using delegate: PIFPackageBuilder . BuildDelegate ) -> [ PackageModel . Platform : String ] {
340
+ func deploymentTargets( using delegate: PackagePIFBuilder . BuildDelegate ) -> [ PackageModel . Platform : String ] {
341
341
let isUsingXCTest = ( self . type == . test)
342
342
let derivedSupportedPlatforms : [ SupportedPlatform ] = Platform . knownPlatforms. map {
343
343
self . getSupportedPlatform ( for: $0, usingXCTest: isUsingXCTest)
@@ -488,8 +488,7 @@ extension PackageGraph.ResolvedModule {
488
488
func productRepresentingDependencyOfBuildPlugin( in mainModuleProducts: [ ResolvedProduct ] ) -> ResolvedProduct ? {
489
489
mainModuleProducts. only { ( mainModuleProduct: ResolvedProduct ) -> Bool in
490
490
// NOTE: We can't use the 'id' here as we need to explicitly ignore the build triple because our build
491
- // triple
492
- // will be '.tools' while the target we want to depend on will have a build triple of '.destination'.
491
+ // triple will be '.tools' while the target we want to depend on will have a build triple of '.destination'.
493
492
// See for more details:
494
493
// https://github.com/swiftlang/swift-package-manager/commit/b22168ec41061ddfa3438f314a08ac7a776bef7a.
495
494
return mainModuleProduct. mainModule!. packageIdentity == self . packageIdentity &&
@@ -499,7 +498,7 @@ extension PackageGraph.ResolvedModule {
499
498
}
500
499
501
500
struct AllBuildSettings {
502
- typealias BuildSettingsByPlatform = [ PackageModel . Platform ? : [ BuildSettings . Declaration : [ String ] ] ]
501
+ typealias BuildSettingsByPlatform = [ ProjectModel . BuildSettings . Platform ? : [ BuildSettings . Declaration : [ String ] ] ]
503
502
504
503
/// Target-specific build settings declared in the manifest and that apply to the target itself.
505
504
var targetSettings : [ BuildConfiguration : BuildSettingsByPlatform ] = [ : ]
@@ -518,47 +517,51 @@ extension PackageGraph.ResolvedModule {
518
517
519
518
for (declaration, settingsAssigments) in self . underlying. buildSettings. assignments {
520
519
for settingAssignment in settingsAssigments {
521
- // Create a build setting value; in some cases there isn't a direct mapping to Swift Build build
522
- // settings.
523
- let swbDeclaration : BuildSettings . Declaration
520
+ // Create a build setting value; in some cases there
521
+ // isn't a direct mapping to Swift Build build settings.
522
+ let pifDeclaration : BuildSettings . Declaration
524
523
let values : [ String ]
525
524
switch declaration {
526
525
case . LINK_FRAMEWORKS:
527
- swbDeclaration = . OTHER_LDFLAGS
526
+ pifDeclaration = . OTHER_LDFLAGS
528
527
values = settingAssignment. values. flatMap { [ " -framework " , $0] }
529
528
case . LINK_LIBRARIES:
530
- swbDeclaration = . OTHER_LDFLAGS
529
+ pifDeclaration = . OTHER_LDFLAGS
531
530
values = settingAssignment. values. map { " -l \( $0) " }
532
531
case . HEADER_SEARCH_PATHS:
533
- swbDeclaration = . HEADER_SEARCH_PATHS
532
+ pifDeclaration = . HEADER_SEARCH_PATHS
534
533
values = settingAssignment. values. map { self . sourceDirAbsolutePath. pathString + " / " + $0 }
535
534
default :
536
- swbDeclaration = declaration
535
+ pifDeclaration = ProjectModel . BuildSettings . Declaration ( from : declaration)
537
536
values = settingAssignment. values
538
537
}
539
538
540
539
// TODO: We are currently ignoring package traits (see rdar://138149810).
541
540
let ( platforms, configurations, _) = settingAssignment. conditions. splitIntoConcreteConditions
542
541
543
542
for platform in platforms {
544
- if swbDeclaration == . OTHER_LDFLAGS {
545
- var settingsByDeclaration : [ BuildSettings . Declaration : [ String ] ] = allSettings
546
- . impartedSettings [ platform ] ?? [ : ]
547
- settingsByDeclaration [ swbDeclaration , default : [ ] ] . append ( contentsOf : values )
543
+ let pifPlatform = platform . map { ProjectModel . BuildSettings . Platform ( from : $0 ) }
544
+
545
+ if pifDeclaration == . OTHER_LDFLAGS {
546
+ var settingsByDeclaration : [ ProjectModel . BuildSettings . Declaration : [ String ] ]
548
547
549
- allSettings. impartedSettings [ platform] = settingsByDeclaration
548
+ settingsByDeclaration = allSettings. impartedSettings [ pifPlatform] ?? [ : ]
549
+ settingsByDeclaration [ pifDeclaration, default: [ ] ] . append ( contentsOf: values)
550
+
551
+ allSettings. impartedSettings [ pifPlatform] = settingsByDeclaration
550
552
}
551
553
552
554
for configuration in configurations {
553
- var settingsByDeclaration : [ BuildSettings . Declaration : [ String ] ] = allSettings
554
- . targetSettings [ configuration] ? [ platform] ?? [ : ]
555
- if swbDeclaration. allowsMultipleValues {
556
- settingsByDeclaration [ swbDeclaration, default: [ ] ] . append ( contentsOf: values)
555
+ var settingsByDeclaration : [ ProjectModel . BuildSettings . Declaration : [ String ] ]
556
+ settingsByDeclaration = allSettings. targetSettings [ configuration] ? [ pifPlatform] ?? [ : ]
557
+
558
+ if declaration. allowsMultipleValues {
559
+ settingsByDeclaration [ pifDeclaration, default: [ ] ] . append ( contentsOf: values)
557
560
} else {
558
- settingsByDeclaration [ swbDeclaration ] = values. only. flatMap { [ $0] } ?? [ ]
561
+ settingsByDeclaration [ pifDeclaration ] = values. only. flatMap { [ $0] } ?? [ ]
559
562
}
560
563
561
- allSettings. targetSettings [ configuration, default: [ : ] ] [ platform ] = settingsByDeclaration
564
+ allSettings. targetSettings [ configuration, default: [ : ] ] [ pifPlatform ] = settingsByDeclaration
562
565
}
563
566
}
564
567
}
@@ -799,34 +802,38 @@ extension ProjectModel.BuildSettings {
799
802
}
800
803
}
801
804
802
- /// Helpers for building custom PIF targets by `PIFPackageBuilder ` clients.
803
- extension SwiftBuild . ProjectModel . Project {
805
+ /// Helpers for building custom PIF targets by `PackagePIFBuilder ` clients.
806
+ extension ProjectModel . Project {
804
807
@discardableResult
805
- public func addTarget(
808
+ public mutating func addTarget(
806
809
packageProductName: String ,
807
- productType: SwiftBuild . ProjectModel . Target . ProductType
808
- ) throws -> SwiftBuild . ProjectModel . Target {
809
- let pifTarget = try self . addTargetThrowing (
810
- id: PIFPackageBuilder . targetGUID ( forProductName: packageProductName) ,
811
- productType: productType,
812
- name: packageProductName,
813
- productName: packageProductName
814
- )
815
- return pifTarget
810
+ productType: ProjectModel . Target . ProductType
811
+ ) throws -> WritableKeyPath < ProjectModel . Project , ProjectModel . Target > {
812
+ let targetKeyPath = try self . addTarget { _ in
813
+ ProjectModel . Target (
814
+ id: PackagePIFBuilder . targetGUID ( forProductName: packageProductName) ,
815
+ productType: productType,
816
+ name: packageProductName,
817
+ productName: packageProductName
818
+ )
819
+ }
820
+ return targetKeyPath
816
821
}
817
822
818
823
@discardableResult
819
- public func addTarget(
824
+ public mutating func addTarget(
820
825
packageModuleName: String ,
821
- productType: SwiftBuild . ProjectModel . Target . ProductType
822
- ) throws -> SwiftBuild . ProjectModel . Target {
823
- let pifTarget = try self . addTargetThrowing (
824
- id: PIFPackageBuilder . targetGUID ( forModuleName: packageModuleName) ,
825
- productType: productType,
826
- name: packageModuleName,
827
- productName: packageModuleName
828
- )
829
- return pifTarget
826
+ productType: ProjectModel . Target . ProductType
827
+ ) throws -> WritableKeyPath < ProjectModel . Project , ProjectModel . Target > {
828
+ let targetKeyPath = try self . addTarget { _ in
829
+ ProjectModel . Target (
830
+ id: PackagePIFBuilder . targetGUID ( forModuleName: packageModuleName) ,
831
+ productType: productType,
832
+ name: packageModuleName,
833
+ productName: packageModuleName
834
+ )
835
+ }
836
+ return targetKeyPath
830
837
}
831
838
}
832
839
@@ -929,7 +936,7 @@ extension ProjectModel.BuildSettings.Platform {
929
936
}
930
937
}
931
938
932
- extension SwiftBuild . ProjectModel . BuildSettings {
939
+ extension ProjectModel . BuildSettings {
933
940
/// Configure necessary settings for a dynamic library/framework.
934
941
mutating func configureDynamicSettings(
935
942
productName: String ,
@@ -939,7 +946,7 @@ extension SwiftBuild.ProjectModel.BuildSettings {
939
946
packageName: String ? ,
940
947
createDylibForDynamicProducts: Bool ,
941
948
installPath: String ,
942
- delegate: PIFPackageBuilder . BuildDelegate
949
+ delegate: PackagePIFBuilder . BuildDelegate
943
950
) {
944
951
self [ . TARGET_NAME] = targetName
945
952
self [ . PRODUCT_NAME] = createDylibForDynamicProducts ? productName : executableName
@@ -973,7 +980,7 @@ extension SwiftBuild.ProjectModel.BuildSettings {
973
980
}
974
981
}
975
982
976
- extension SwiftBuild . ProjectModel . BuildSettings . Declaration {
983
+ extension ProjectModel . BuildSettings . Declaration {
977
984
init ( from declaration: PackageModel . BuildSettings . Declaration ) {
978
985
self = switch declaration {
979
986
// Swift.
0 commit comments