Skip to content

Reapply "Remove redundant EXECUTABLE_NAME overrides in PIF" (#7915) #7918

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

Merged
merged 1 commit into from
Sep 9, 2024
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
48 changes: 24 additions & 24 deletions IntegrationTests/Tests/IntegrationTests/XCBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ final class XCBuildTests: XCTestCase {

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode")
let debugPath = binaryPath.appending(component: "Debug")
XCTAssertFileExists(debugPath.appending(component: "FooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "CFooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib.o"))
XCTAssertFileExists(debugPath.appending(component: "FooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib_Module.o"))

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "-c", "release")
let releasePath = binaryPath.appending(component: "Release")
XCTAssertFileExists(releasePath.appending(component: "FooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "CFooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib.o"))
XCTAssertFileExists(releasePath.appending(component: "FooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib_Module.o"))
}

fixture(name: "XCBuild/Libraries") { path in
Expand All @@ -226,15 +226,15 @@ final class XCBuildTests: XCTestCase {

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "--target", "FooLib")
let debugPath = binaryPath.appending(component: "Debug")
XCTAssertFileExists(debugPath.appending(component: "FooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "CFooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib.o"))
XCTAssertFileExists(debugPath.appending(component: "FooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib_Module.o"))

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "--target", "FooLib", "-c", "release")
let releasePath = binaryPath.appending(component: "Release")
XCTAssertFileExists(releasePath.appending(component: "FooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "CFooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib.o"))
XCTAssertFileExists(releasePath.appending(component: "FooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib_Module.o"))
}

fixture(name: "XCBuild/Libraries") { path in
Expand All @@ -243,15 +243,15 @@ final class XCBuildTests: XCTestCase {

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "--target", "CFooLib")
let debugPath = binaryPath.appending(component: "Debug")
XCTAssertNoSuchPath(debugPath.appending(component: "FooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "CFooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib.o"))
XCTAssertNoSuchPath(debugPath.appending(component: "FooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib_Module.o"))

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "--target", "CFooLib", "-c", "release")
let releasePath = binaryPath.appending(component: "Release")
XCTAssertNoSuchPath(releasePath.appending(component: "FooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "CFooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib.o"))
XCTAssertNoSuchPath(releasePath.appending(component: "FooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib_Module.o"))
}

fixture(name: "XCBuild/Libraries") { path in
Expand All @@ -260,15 +260,15 @@ final class XCBuildTests: XCTestCase {

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "--target", "BarLib")
let debugPath = binaryPath.appending(component: "Debug")
XCTAssertNoSuchPath(debugPath.appending(component: "FooLib.o"))
XCTAssertNoSuchPath(debugPath.appending(component: "CFooLib.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib.o"))
XCTAssertNoSuchPath(debugPath.appending(component: "FooLib_Module.o"))
XCTAssertNoSuchPath(debugPath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(debugPath.appending(component: "BarLib_Module.o"))

try sh(swiftBuild, "--package-path", fooPath, "--build-system", "xcode", "--target", "BarLib", "-c", "release")
let releasePath = binaryPath.appending(component: "Release")
XCTAssertNoSuchPath(releasePath.appending(component: "FooLib.o"))
XCTAssertNoSuchPath(releasePath.appending(component: "CFooLib.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib.o"))
XCTAssertNoSuchPath(releasePath.appending(component: "FooLib_Module.o"))
XCTAssertNoSuchPath(releasePath.appending(component: "CFooLib_Module.o"))
XCTAssertFileExists(releasePath.appending(component: "BarLib_Module.o"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/XCBuildSupport/PIF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ public enum PIF {
case ENABLE_TESTABILITY
case ENABLE_TESTING_SEARCH_PATHS
case ENTITLEMENTS_REQUIRED
case EXECUTABLE_NAME
case EXECUTABLE_PREFIX
case GENERATE_INFOPLIST_FILE
case GCC_C_LANGUAGE_STANDARD
case GCC_OPTIMIZATION_LEVEL
Expand Down
51 changes: 26 additions & 25 deletions Sources/XCBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import func TSCBasic.topologicalSort

/// The parameters required by `PIFBuilder`.
struct PIFBuilderParameters {
let triple: Triple

/// Whether the toolchain supports `-package-name` option.
let isPackageAccessModifierSupported: Bool

Expand Down Expand Up @@ -426,7 +428,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
guid: product.pifTargetGUID,
name: self.targetName(for: product),
productType: productType,
productName: product.name
productName: "\(product.name)\(parameters.triple.executableExtension)"
)

// We'll be infusing the product's main module target into the one for the product itself.
Expand All @@ -444,18 +446,19 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
var settings = PIF.BuildSettings()
settings[.TARGET_NAME] = product.name
settings[.PACKAGE_RESOURCE_TARGET_KIND] = "regular"
settings[.PRODUCT_NAME] = product.name
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
settings[.PRODUCT_MODULE_NAME] = mainTarget.c99name
settings[.PRODUCT_BUNDLE_IDENTIFIER] = product.name
settings[.EXECUTABLE_NAME] = product.name
settings[.CLANG_ENABLE_MODULES] = "YES"
settings[.DEFINES_MODULE] = "YES"

if product.type == .executable || product.type == .test {
settings[.LIBRARY_SEARCH_PATHS] = [
"$(inherited)",
"\(self.parameters.toolchainLibDir.pathString)/swift/macosx",
]
if let darwinPlatform = parameters.triple.darwinPlatform {
settings[.LIBRARY_SEARCH_PATHS] = [
"$(inherited)",
"\(self.parameters.toolchainLibDir.pathString)/swift/\(darwinPlatform.platformName)",
]
}
}

// Tests can have a custom deployment target based on the minimum supported by XCTest.
Expand Down Expand Up @@ -524,22 +527,19 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
}

private func addLibraryTarget(for product: ResolvedProduct) {
// For the name of the product reference
let pifTargetProductName: String
let executableName: String
let productType: PIF.Target.ProductType
if product.type == .library(.dynamic) {
if self.parameters.shouldCreateDylibForDynamicProducts {
pifTargetProductName = "lib\(product.name).dylib"
executableName = pifTargetProductName
pifTargetProductName = "\(parameters.triple.dynamicLibraryPrefix)\(product.name)\(parameters.triple.dynamicLibraryExtension)"
productType = .dynamicLibrary
} else {
pifTargetProductName = product.name + ".framework"
executableName = product.name
productType = .framework
}
} else {
pifTargetProductName = "lib\(product.name).a"
executableName = pifTargetProductName
pifTargetProductName = "lib\(product.name)\(parameters.triple.staticLibraryExtension)"
productType = .packageProduct
}

Expand Down Expand Up @@ -581,18 +581,20 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
// Add other build settings when we're building an actual dylib.
if product.type == .library(.dynamic) {
settings[.TARGET_NAME] = product.name
settings[.PRODUCT_NAME] = executableName
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
settings[.PRODUCT_MODULE_NAME] = product.name
settings[.PRODUCT_BUNDLE_IDENTIFIER] = product.name
settings[.EXECUTABLE_NAME] = executableName
settings[.EXECUTABLE_PREFIX] = parameters.triple.dynamicLibraryPrefix
settings[.CLANG_ENABLE_MODULES] = "YES"
settings[.DEFINES_MODULE] = "YES"
settings[.SKIP_INSTALL] = "NO"
settings[.INSTALL_PATH] = "/usr/local/lib"
settings[.LIBRARY_SEARCH_PATHS] = [
"$(inherited)",
"\(self.parameters.toolchainLibDir.pathString)/swift/macosx",
]
if let darwinPlatform = parameters.triple.darwinPlatform {
settings[.LIBRARY_SEARCH_PATHS] = [
"$(inherited)",
"\(self.parameters.toolchainLibDir.pathString)/swift/\(darwinPlatform.platformName)",
]
}

if !self.parameters.shouldCreateDylibForDynamicProducts {
settings[.GENERATE_INFOPLIST_FILE] = "YES"
Expand Down Expand Up @@ -621,16 +623,15 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
guid: target.pifTargetGUID,
name: target.name,
productType: .objectFile,
productName: "\(target.name).o"
productName: "\(target.name)_Module.o"
)

var settings = PIF.BuildSettings()
settings[.TARGET_NAME] = target.name
settings[.TARGET_NAME] = target.name + "_Module"
settings[.PACKAGE_RESOURCE_TARGET_KIND] = "regular"
settings[.PRODUCT_NAME] = "\(target.name).o"
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
settings[.PRODUCT_MODULE_NAME] = target.c99name
settings[.PRODUCT_BUNDLE_IDENTIFIER] = target.name
settings[.EXECUTABLE_NAME] = "\(target.name).o"
settings[.CLANG_ENABLE_MODULES] = "YES"
settings[.DEFINES_MODULE] = "YES"
settings[.MACH_O_TYPE] = "mh_object"
Expand Down Expand Up @@ -897,7 +898,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {

var settings = PIF.BuildSettings()
settings[.TARGET_NAME] = bundleName
settings[.PRODUCT_NAME] = bundleName
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
settings[.PRODUCT_MODULE_NAME] = bundleName
let bundleIdentifier = "\(package.manifest.displayName).\(target.name).resources"
.spm_mangledToBundleIdentifier() // TODO: use identity instead?
Expand Down Expand Up @@ -927,7 +928,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {

let targetGroup = groupTree.addGroup(path: "/", sourceTree: .group)
pifTarget.addResourceFile(targetGroup.addFileReference(
path: "\(bundleName).bundle",
path: "\(bundleName)\(parameters.triple.nsbundleExtension)",
sourceTree: .builtProductsDir
))

Expand Down
1 change: 1 addition & 0 deletions Sources/XCBuildSupport/XcodeBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ extension BuildConfiguration {
extension PIFBuilderParameters {
public init(_ buildParameters: BuildParameters, supportedSwiftVersions: [SwiftLanguageVersion]) {
self.init(
triple: buildParameters.triple,
isPackageAccessModifierSupported: buildParameters.driverParameters.isPackageAccessModifierSupported,
enableTestability: buildParameters.testingParameters.enableTestability,
shouldCreateDylibForDynamicProducts: buildParameters.shouldCreateDylibForDynamicProducts,
Expand Down
Loading