Skip to content

Commit b348d44

Browse files
committed
Reapply "Remove redundant EXECUTABLE_NAME overrides in PIF" (#7915)
This reverts commit 9608baf.
1 parent 0646fc0 commit b348d44

File tree

6 files changed

+102
-121
lines changed

6 files changed

+102
-121
lines changed

IntegrationTests/Tests/IntegrationTests/XCBuildTests.swift

+24-24
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ final class XCBuildTests: XCTestCase {
209209

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

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

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

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

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

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

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

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

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

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

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

Sources/XCBuildSupport/PIF.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ public enum PIF {
913913
case ENABLE_TESTABILITY
914914
case ENABLE_TESTING_SEARCH_PATHS
915915
case ENTITLEMENTS_REQUIRED
916-
case EXECUTABLE_NAME
916+
case EXECUTABLE_PREFIX
917917
case GENERATE_INFOPLIST_FILE
918918
case GCC_C_LANGUAGE_STANDARD
919919
case GCC_OPTIMIZATION_LEVEL

Sources/XCBuildSupport/PIFBuilder.swift

+26-25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import func TSCBasic.topologicalSort
2424

2525
/// The parameters required by `PIFBuilder`.
2626
struct PIFBuilderParameters {
27+
let triple: Triple
28+
2729
/// Whether the toolchain supports `-package-name` option.
2830
let isPackageAccessModifierSupported: Bool
2931

@@ -427,7 +429,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
427429
guid: product.pifTargetGUID,
428430
name: self.targetName(for: product),
429431
productType: productType,
430-
productName: product.name
432+
productName: "\(product.name)\(parameters.triple.executableExtension)"
431433
)
432434

433435
// We'll be infusing the product's main module target into the one for the product itself.
@@ -445,18 +447,19 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
445447
var settings = PIF.BuildSettings()
446448
settings[.TARGET_NAME] = product.name
447449
settings[.PACKAGE_RESOURCE_TARGET_KIND] = "regular"
448-
settings[.PRODUCT_NAME] = product.name
450+
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
449451
settings[.PRODUCT_MODULE_NAME] = mainTarget.c99name
450452
settings[.PRODUCT_BUNDLE_IDENTIFIER] = product.name
451-
settings[.EXECUTABLE_NAME] = product.name
452453
settings[.CLANG_ENABLE_MODULES] = "YES"
453454
settings[.DEFINES_MODULE] = "YES"
454455

455456
if product.type == .executable || product.type == .test {
456-
settings[.LIBRARY_SEARCH_PATHS] = [
457-
"$(inherited)",
458-
"\(self.parameters.toolchainLibDir.pathString)/swift/macosx",
459-
]
457+
if let darwinPlatform = parameters.triple.darwinPlatform {
458+
settings[.LIBRARY_SEARCH_PATHS] = [
459+
"$(inherited)",
460+
"\(self.parameters.toolchainLibDir.pathString)/swift/\(darwinPlatform.platformName)",
461+
]
462+
}
460463
}
461464

462465
// Tests can have a custom deployment target based on the minimum supported by XCTest.
@@ -525,22 +528,19 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
525528
}
526529

527530
private func addLibraryTarget(for product: ResolvedProduct) {
531+
// For the name of the product reference
528532
let pifTargetProductName: String
529-
let executableName: String
530533
let productType: PIF.Target.ProductType
531534
if product.type == .library(.dynamic) {
532535
if self.parameters.shouldCreateDylibForDynamicProducts {
533-
pifTargetProductName = "lib\(product.name).dylib"
534-
executableName = pifTargetProductName
536+
pifTargetProductName = "\(parameters.triple.dynamicLibraryPrefix)\(product.name)\(parameters.triple.dynamicLibraryExtension)"
535537
productType = .dynamicLibrary
536538
} else {
537539
pifTargetProductName = product.name + ".framework"
538-
executableName = product.name
539540
productType = .framework
540541
}
541542
} else {
542-
pifTargetProductName = "lib\(product.name).a"
543-
executableName = pifTargetProductName
543+
pifTargetProductName = "lib\(product.name)\(parameters.triple.staticLibraryExtension)"
544544
productType = .packageProduct
545545
}
546546

@@ -582,18 +582,20 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
582582
// Add other build settings when we're building an actual dylib.
583583
if product.type == .library(.dynamic) {
584584
settings[.TARGET_NAME] = product.name
585-
settings[.PRODUCT_NAME] = executableName
585+
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
586586
settings[.PRODUCT_MODULE_NAME] = product.name
587587
settings[.PRODUCT_BUNDLE_IDENTIFIER] = product.name
588-
settings[.EXECUTABLE_NAME] = executableName
588+
settings[.EXECUTABLE_PREFIX] = parameters.triple.dynamicLibraryPrefix
589589
settings[.CLANG_ENABLE_MODULES] = "YES"
590590
settings[.DEFINES_MODULE] = "YES"
591591
settings[.SKIP_INSTALL] = "NO"
592592
settings[.INSTALL_PATH] = "/usr/local/lib"
593-
settings[.LIBRARY_SEARCH_PATHS] = [
594-
"$(inherited)",
595-
"\(self.parameters.toolchainLibDir.pathString)/swift/macosx",
596-
]
593+
if let darwinPlatform = parameters.triple.darwinPlatform {
594+
settings[.LIBRARY_SEARCH_PATHS] = [
595+
"$(inherited)",
596+
"\(self.parameters.toolchainLibDir.pathString)/swift/\(darwinPlatform.platformName)",
597+
]
598+
}
597599

598600
if !self.parameters.shouldCreateDylibForDynamicProducts {
599601
settings[.GENERATE_INFOPLIST_FILE] = "YES"
@@ -622,16 +624,15 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
622624
guid: target.pifTargetGUID,
623625
name: target.name,
624626
productType: .objectFile,
625-
productName: "\(target.name).o"
627+
productName: "\(target.name)_Module.o"
626628
)
627629

628630
var settings = PIF.BuildSettings()
629-
settings[.TARGET_NAME] = target.name
631+
settings[.TARGET_NAME] = target.name + "_Module"
630632
settings[.PACKAGE_RESOURCE_TARGET_KIND] = "regular"
631-
settings[.PRODUCT_NAME] = "\(target.name).o"
633+
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
632634
settings[.PRODUCT_MODULE_NAME] = target.c99name
633635
settings[.PRODUCT_BUNDLE_IDENTIFIER] = target.name
634-
settings[.EXECUTABLE_NAME] = "\(target.name).o"
635636
settings[.CLANG_ENABLE_MODULES] = "YES"
636637
settings[.DEFINES_MODULE] = "YES"
637638
settings[.MACH_O_TYPE] = "mh_object"
@@ -898,7 +899,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
898899

899900
var settings = PIF.BuildSettings()
900901
settings[.TARGET_NAME] = bundleName
901-
settings[.PRODUCT_NAME] = bundleName
902+
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
902903
settings[.PRODUCT_MODULE_NAME] = bundleName
903904
let bundleIdentifier = "\(package.manifest.displayName).\(target.name).resources"
904905
.spm_mangledToBundleIdentifier() // TODO: use identity instead?
@@ -928,7 +929,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
928929

929930
let targetGroup = groupTree.addGroup(path: "/", sourceTree: .group)
930931
pifTarget.addResourceFile(targetGroup.addFileReference(
931-
path: "\(bundleName).bundle",
932+
path: "\(bundleName)\(parameters.triple.nsbundleExtension)",
932933
sourceTree: .builtProductsDir
933934
))
934935

Sources/XCBuildSupport/XcodeBuildSystem.swift

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ extension BuildConfiguration {
369369
extension PIFBuilderParameters {
370370
public init(_ buildParameters: BuildParameters, supportedSwiftVersions: [SwiftLanguageVersion]) {
371371
self.init(
372+
triple: buildParameters.triple,
372373
isPackageAccessModifierSupported: buildParameters.driverParameters.isPackageAccessModifierSupported,
373374
enableTestability: buildParameters.testingParameters.enableTestability,
374375
shouldCreateDylibForDynamicProducts: buildParameters.shouldCreateDylibForDynamicProducts,

0 commit comments

Comments
 (0)