Skip to content

SwiftBuildSupport: Revert patch required when we were using '#if canImport(SwiftBuild)' checks #8957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/SwiftBuildSupport/BuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension BuildSubset {
var pifTargetName: String {
switch self {
case .product(let name, _):
targetName(forProductName: name)
PackagePIFBuilder.targetName(forProductName: name)
case .target(let name, _):
name
case .allExcludingTests:
Expand Down
20 changes: 8 additions & 12 deletions Sources/SwiftBuildSupport/PackagePIFBuilder+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ import struct PackageGraph.ResolvedProduct

import func PackageLoading.pkgConfigArgs

// TODO: Move this back to `PackagePIFBuilder` once we get rid of `#if canImport(SwiftBuild)`.
func targetName(forProductName name: String, suffix: String? = nil) -> String {
let suffix = suffix ?? ""
return "\(name)\(suffix)-product"
}

import enum SwiftBuild.ProjectModel

// MARK: - PIF GUID Helpers
Expand All @@ -74,7 +68,7 @@ enum TargetSuffix: String {
}

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

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

/// Helper function to consistently generate a target name string for a product in a package.
/// This format helps make sure that targets and products with the same name (as they often have) have different
/// target names in the PIF.
///
/// This format helps make sure that modules and products with the same name (as they often have)
/// have different target names in the PIF.
static func targetName(forProductName name: String, suffix: TargetSuffix? = nil) -> String {
return SwiftBuildSupport.targetName(forProductName: name, suffix: suffix?.rawValue)
let suffix = suffix?.rawValue ?? ""
return "\(name)\(suffix)-product"
Copy link
Contributor Author

@pmattos pmattos Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change! The rest is just some quick refactorings...

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ extension PackagePIFProjectBuilder {
}

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

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