Skip to content

Commit f19d08c

Browse files
authored
SwiftBuildSupport: Revert patch required when we were using '#if canImport(SwiftBuild)' checks (#8957)
### Motivation: We couldn't call `SwiftBuildSupport.PackagePIFBuilder` from `SwiftBuildSupport/BuildSystem.swift` given the prior `#if canImport(SwiftBuild)` checks in former. This is no longer the case. ### Modifications: Provides a minor code cleanup in `PackagePIFBuilder+Helpers.swift`. This is tracked by: rdar://139545019
1 parent a833084 commit f19d08c

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

Sources/SwiftBuildSupport/BuildSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension BuildSubset {
1414
var pifTargetName: String {
1515
switch self {
1616
case .product(let name, _):
17-
targetName(forProductName: name)
17+
PackagePIFBuilder.targetName(forProductName: name)
1818
case .target(let name, _):
1919
name
2020
case .allExcludingTests:

Sources/SwiftBuildSupport/PackagePIFBuilder+Helpers.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ import struct PackageGraph.ResolvedProduct
5555

5656
import func PackageLoading.pkgConfigArgs
5757

58-
// TODO: Move this back to `PackagePIFBuilder` once we get rid of `#if canImport(SwiftBuild)`.
59-
func targetName(forProductName name: String, suffix: String? = nil) -> String {
60-
let suffix = suffix ?? ""
61-
return "\(name)\(suffix)-product"
62-
}
63-
6458
import enum SwiftBuild.ProjectModel
6559

6660
// MARK: - PIF GUID Helpers
@@ -74,7 +68,7 @@ enum TargetSuffix: String {
7468
}
7569

7670
extension TargetSuffix? {
77-
func description(forName name: String) -> String {
71+
func uniqueDescription(forName name: String) -> String {
7872
switch self {
7973
case .some(let suffix):
8074
"-\(String(name.hash, radix: 16, uppercase: true))-\(suffix.rawValue)"
@@ -132,7 +126,7 @@ extension PackagePIFBuilder {
132126
/// This format helps make sure that there is no collision with any other PIF targets,
133127
/// and in particular that a PIF target and a PIF product can have the same name (as they often do).
134128
static func targetGUID(forModuleName name: String, suffix: TargetSuffix? = nil) -> GUID {
135-
let suffixDescription = suffix.description(forName: name)
129+
let suffixDescription = suffix.uniqueDescription(forName: name)
136130
return "PACKAGE-TARGET:\(name)\(suffixDescription)"
137131
}
138132

@@ -141,15 +135,17 @@ extension PackagePIFBuilder {
141135
/// This format helps make sure that there is no collision with any other PIF targets,
142136
/// and in particular that a PIF target and a PIF product can have the same name (as they often do).
143137
static func targetGUID(forProductName name: String, suffix: TargetSuffix? = nil) -> GUID {
144-
let suffixDescription = suffix.description(forName: name)
138+
let suffixDescription = suffix.uniqueDescription(forName: name)
145139
return "PACKAGE-PRODUCT:\(name)\(suffixDescription)"
146140
}
147141

148142
/// Helper function to consistently generate a target name string for a product in a package.
149-
/// This format helps make sure that targets and products with the same name (as they often have) have different
150-
/// target names in the PIF.
143+
///
144+
/// This format helps make sure that modules and products with the same name (as they often have)
145+
/// have different target names in the PIF.
151146
static func targetName(forProductName name: String, suffix: TargetSuffix? = nil) -> String {
152-
return SwiftBuildSupport.targetName(forProductName: name, suffix: suffix?.rawValue)
147+
let suffix = suffix?.rawValue ?? ""
148+
return "\(name)\(suffix)-product"
153149
}
154150
}
155151

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ extension PackagePIFProjectBuilder {
450450
}
451451

452452
// We have to give each target a unique name.
453-
settings[.TARGET_NAME] = sourceModule.name + targetSuffix.description(forName: sourceModule.name)
453+
settings[.TARGET_NAME] = sourceModule.name + targetSuffix.uniqueDescription(forName: sourceModule.name)
454454

455455
// Redirect the built executable into a separate directory so it won't conflict with the real one.
456456
settings[.TARGET_BUILD_DIR] = "$(TARGET_BUILD_DIR)/ExecutableModules"

0 commit comments

Comments
 (0)