From 977c1f5535be4567ec8001205ba06e024a389653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20B=C3=BCgling?= Date: Fri, 8 Sep 2023 16:21:52 -0700 Subject: [PATCH] Reduce XCTest minimum deployment target computation We never need this for any platform that we're not building for and we also don't really need it for most commands. So we can just move the computation to SwiftTool and leave these empty for all other cases. rdar://64596106 (cherry picked from commit 019a6fb4b396a1cb5cb64ef8c0ba02cd580fc14a) --- .../ProductBuildDescription.swift | 20 ++--- Sources/Build/BuildPlan.swift | 18 ++-- .../PackageGraph/PackageGraph+Loading.swift | 89 +++---------------- Sources/PackageGraph/ResolvedProduct.swift | 24 ++--- .../MinimumDeploymentTarget.swift | 14 +-- Sources/PackageModel/Platform.swift | 50 +++++++++-- .../SPMTestSupport/PackageGraphTester.swift | 24 +++-- Sources/XCBuildSupport/PIFBuilder.swift | 25 ++---- Tests/BuildTests/BuildPlanTests.swift | 12 ++- Tests/CommandsTests/PackageToolTests.swift | 2 +- Tests/PackageGraphTests/TargetTests.swift | 2 +- 11 files changed, 134 insertions(+), 146 deletions(-) diff --git a/Sources/Build/BuildDescription/ProductBuildDescription.swift b/Sources/Build/BuildDescription/ProductBuildDescription.swift index 18043eec781..dbf76874258 100644 --- a/Sources/Build/BuildDescription/ProductBuildDescription.swift +++ b/Sources/Build/BuildDescription/ProductBuildDescription.swift @@ -274,16 +274,16 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription // When deploying to macOS prior to macOS 12, add an rpath to the // back-deployed concurrency libraries. - if useStdlibRpath, self.buildParameters.triple.isDarwin(), - let macOSSupportedPlatform = self.package.platforms.getDerived(for: .macOS), - macOSSupportedPlatform.version.major < 12 - { - let backDeployedStdlib = try buildParameters.toolchain.macosSwiftStdlib - .parentDirectory - .parentDirectory - .appending("swift-5.5") - .appending("macosx") - args += ["-Xlinker", "-rpath", "-Xlinker", backDeployedStdlib.pathString] + if useStdlibRpath, self.buildParameters.triple.isDarwin() { + let macOSSupportedPlatform = self.package.platforms.getDerived(for: .macOS, usingXCTest: product.isLinkingXCTest) + if macOSSupportedPlatform.version.major < 12 { + let backDeployedStdlib = try buildParameters.toolchain.macosSwiftStdlib + .parentDirectory + .parentDirectory + .appending("swift-5.5") + .appending("macosx") + args += ["-Xlinker", "-rpath", "-Xlinker", backDeployedStdlib.pathString] + } } } diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 52bb76d6028..b5873c7ca7a 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -140,9 +140,7 @@ extension BuildParameters { var args = ["-target"] // Compute the triple string for Darwin platform using the platform version. if triple.isDarwin() { - guard let macOSSupportedPlatform = target.platforms.getDerived(for: .macOS) else { - throw StringError("the target \(target) doesn't support building for macOS") - } + let macOSSupportedPlatform = target.platforms.getDerived(for: .macOS, usingXCTest: target.type == .test) args += [triple.tripleString(forPlatformVersion: macOSSupportedPlatform.version.versionString)] } else { args += [triple.tripleString] @@ -305,7 +303,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan { target: discoveryTarget, dependencies: testProduct.targets.map { .target($0, conditions: []) }, defaultLocalization: .none, // safe since this is a derived target - platforms: .init(declared: [], derived: []) // safe since this is a derived target + platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived target ) let discoveryTargetBuildDescription = try SwiftTargetBuildDescription( package: package, @@ -338,7 +336,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan { target: entryPointTarget, dependencies: testProduct.targets.map { .target($0, conditions: []) } + [.target(discoveryResolvedTarget, conditions: [])], defaultLocalization: .none, // safe since this is a derived target - platforms: .init(declared: [], derived: []) // safe since this is a derived target + platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived target ) return try SwiftTargetBuildDescription( package: package, @@ -367,7 +365,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan { target: entryPointTarget, dependencies: entryPointResolvedTarget.dependencies + [.target(discoveryTargets.resolved, conditions: [])], defaultLocalization: .none, // safe since this is a derived target - platforms: .init(declared: [], derived: []) // safe since this is a derived target + platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived target ) let entryPointTargetBuildDescription = try SwiftTargetBuildDescription( package: package, @@ -574,12 +572,8 @@ public class BuildPlan: SPMBuildCore.BuildPlan { ) throws { // Supported platforms are defined at the package level. // This will need to become a bit complicated once we have target-level or product-level platform support. - guard let productPlatform = product.platforms.getDerived(for: .macOS) else { - throw StringError("Expected supported platform macOS in product \(product)") - } - guard let targetPlatform = target.platforms.getDerived(for: .macOS) else { - throw StringError("Expected supported platform macOS in target \(target)") - } + let productPlatform = product.platforms.getDerived(for: .macOS, usingXCTest: product.isLinkingXCTest) + let targetPlatform = target.platforms.getDerived(for: .macOS, usingXCTest: target.type == .test) // Check if the version requirement is satisfied. // diff --git a/Sources/PackageGraph/PackageGraph+Loading.swift b/Sources/PackageGraph/PackageGraph+Loading.swift index 7b71b3e8abd..b5972b9d341 100644 --- a/Sources/PackageGraph/PackageGraph+Loading.swift +++ b/Sources/PackageGraph/PackageGraph+Loading.swift @@ -144,7 +144,13 @@ extension PackageGraph { rootManifests: root.manifests, unsafeAllowedPackages: unsafeAllowedPackages, platformRegistry: customPlatformsRegistry ?? .default, - xcTestMinimumDeploymentTargets: customXCTestMinimumDeploymentTargets ?? MinimumDeploymentTarget.default.xcTestMinimumDeploymentTargets, + derivedXCTestPlatformProvider: { declared in + if let customXCTestMinimumDeploymentTargets { + return customXCTestMinimumDeploymentTargets[declared] + } else { + return MinimumDeploymentTarget.default.computeXCTestMinimumDeploymentTarget(for: declared) + } + }, fileSystem: fileSystem, observabilityScope: observabilityScope ) @@ -225,7 +231,7 @@ private func createResolvedPackages( rootManifests: [PackageIdentity: Manifest], unsafeAllowedPackages: Set, platformRegistry: PlatformRegistry, - xcTestMinimumDeploymentTargets: [PackageModel.Platform: PlatformVersion], + derivedXCTestPlatformProvider: @escaping (_ declared: PackageModel.Platform) -> PlatformVersion?, fileSystem: FileSystem, observabilityScope: ObservabilityScope ) throws -> [ResolvedPackage] { @@ -348,16 +354,8 @@ private func createResolvedPackages( packageBuilder.platforms = computePlatforms( package: package, - usingXCTest: false, - platformRegistry: platformRegistry, - xcTestMinimumDeploymentTargets: xcTestMinimumDeploymentTargets - ) - - let testPlatforms = computePlatforms( - package: package, - usingXCTest: true, platformRegistry: platformRegistry, - xcTestMinimumDeploymentTargets: xcTestMinimumDeploymentTargets + derivedXCTestPlatformProvider: derivedXCTestPlatformProvider ) // Create target builders for each target in the package. @@ -379,7 +377,7 @@ private func createResolvedPackages( } } targetBuilder.defaultLocalization = packageBuilder.defaultLocalization - targetBuilder.platforms = targetBuilder.target.type == .test ? testPlatforms : packageBuilder.platforms + targetBuilder.platforms = packageBuilder.platforms } // Create product builders for each product in the package. A product can only contain a target present in the same package. @@ -686,9 +684,8 @@ private class DuplicateProductsChecker { private func computePlatforms( package: Package, - usingXCTest: Bool, platformRegistry: PlatformRegistry, - xcTestMinimumDeploymentTargets: [PackageModel.Platform: PlatformVersion] + derivedXCTestPlatformProvider: @escaping (_ declared: PackageModel.Platform) -> PlatformVersion? ) -> SupportedPlatforms { // the supported platforms as declared in the manifest @@ -702,67 +699,9 @@ private func computePlatforms( ) } - // the derived platforms based on known minimum deployment target logic - var derivedPlatforms = [SupportedPlatform]() - - /// Add each declared platform to the supported platforms list. - for platform in package.manifest.platforms { - let declaredPlatform = platformRegistry.platformByName[platform.platformName] - ?? PackageModel.Platform.custom(name: platform.platformName, oldestSupportedVersion: platform.version) - var version = PlatformVersion(platform.version) - - if usingXCTest, let xcTestMinimumDeploymentTarget = xcTestMinimumDeploymentTargets[declaredPlatform], version < xcTestMinimumDeploymentTarget { - version = xcTestMinimumDeploymentTarget - } - - // If the declared version is smaller than the oldest supported one, we raise the derived version to that. - if version < declaredPlatform.oldestSupportedVersion { - version = declaredPlatform.oldestSupportedVersion - } - - let supportedPlatform = SupportedPlatform( - platform: declaredPlatform, - version: version, - options: platform.options - ) - - derivedPlatforms.append(supportedPlatform) - } - - // Find the undeclared platforms. - let remainingPlatforms = Set(platformRegistry.platformByName.keys).subtracting(derivedPlatforms.map({ $0.platform.name })) - - /// Start synthesizing for each undeclared platform. - for platformName in remainingPlatforms.sorted() { - let platform = platformRegistry.platformByName[platformName]! - - let minimumSupportedVersion: PlatformVersion - if usingXCTest, let xcTestMinimumDeploymentTarget = xcTestMinimumDeploymentTargets[platform], xcTestMinimumDeploymentTarget > platform.oldestSupportedVersion { - minimumSupportedVersion = xcTestMinimumDeploymentTarget - } else { - minimumSupportedVersion = platform.oldestSupportedVersion - } - - let oldestSupportedVersion: PlatformVersion - if platform == .macCatalyst, let iOS = derivedPlatforms.first(where: { $0.platform == .iOS }) { - // If there was no deployment target specified for Mac Catalyst, fall back to the iOS deployment target. - oldestSupportedVersion = max(minimumSupportedVersion, iOS.version) - } else { - oldestSupportedVersion = minimumSupportedVersion - } - - let supportedPlatform = SupportedPlatform( - platform: platform, - version: oldestSupportedVersion, - options: [] - ) - - derivedPlatforms.append(supportedPlatform) - } - return SupportedPlatforms( declared: declaredPlatforms.sorted(by: { $0.platform.name < $1.platform.name }), - derived: derivedPlatforms.sorted(by: { $0.platform.name < $1.platform.name }) + derivedXCTestPlatformProvider: derivedXCTestPlatformProvider ) } @@ -886,7 +825,7 @@ private final class ResolvedTargetBuilder: ResolvedBuilder { var defaultLocalization: String? = nil /// The platforms supported by this package. - var platforms: SupportedPlatforms = .init(declared: [], derived: []) + var platforms: SupportedPlatforms = .init(declared: [], derivedXCTestPlatformProvider: .none) init( target: Target, @@ -978,7 +917,7 @@ private final class ResolvedPackageBuilder: ResolvedBuilder { var defaultLocalization: String? = nil /// The platforms supported by this package. - var platforms: SupportedPlatforms = .init(declared: [], derived: []) + var platforms: SupportedPlatforms = .init(declared: [], derivedXCTestPlatformProvider: .none) /// If the given package's source is a registry release, this provides additional metadata and signature information. var registryMetadata: RegistryReleaseMetadata? diff --git a/Sources/PackageGraph/ResolvedProduct.swift b/Sources/PackageGraph/ResolvedProduct.swift index 5a8628ad057..aad2db599ce 100644 --- a/Sources/PackageGraph/ResolvedProduct.swift +++ b/Sources/PackageGraph/ResolvedProduct.swift @@ -71,7 +71,7 @@ public final class ResolvedProduct { target: swiftTarget, dependencies: targets.map { .target($0, conditions: []) }, defaultLocalization: .none, // safe since this is a derived product - platforms: .init(declared: [], derived: []) // safe since this is a derived product + platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived product ) } @@ -119,16 +119,13 @@ public final class ResolvedProduct { merge(into: &partial, platforms: item.platforms.declared) } - let derived = targets.reduce(into: [SupportedPlatform]()) { partial, item in - merge(into: &partial, platforms: item.platforms.derived) - } - return SupportedPlatforms( - declared: declared.sorted(by: { $0.platform.name < $1.platform.name }), - derived: derived.sorted(by: { $0.platform.name < $1.platform.name }) - ) - - + declared: declared.sorted(by: { $0.platform.name < $1.platform.name })) { declared in + let platforms = targets.reduce(into: [SupportedPlatform]()) { partial, item in + merge(into: &partial, platforms: [item.platforms.getDerived(for: declared, usingXCTest: item.type == .test)]) + } + return platforms.first!.version + } } } @@ -147,3 +144,10 @@ extension ResolvedProduct: CustomStringConvertible { return "" } } + +extension ResolvedProduct { + public var isLinkingXCTest: Bool { + // To retain existing behavior, we have to check both the product type, as well as the types of all of its targets. + return self.type == .test || self.targets.contains(where: { $0.type == .test }) + } +} diff --git a/Sources/PackageModel/MinimumDeploymentTarget.swift b/Sources/PackageModel/MinimumDeploymentTarget.swift index 2cade2a3adf..7967cfff17e 100644 --- a/Sources/PackageModel/MinimumDeploymentTarget.swift +++ b/Sources/PackageModel/MinimumDeploymentTarget.swift @@ -10,18 +10,20 @@ // //===----------------------------------------------------------------------===// +import Basics import TSCBasic public struct MinimumDeploymentTarget { - public let xcTestMinimumDeploymentTargets: [PackageModel.Platform:PlatformVersion] + public let xcTestMinimumDeploymentTargets = ThreadSafeKeyValueStore() public static let `default`: MinimumDeploymentTarget = .init() - public init() { - xcTestMinimumDeploymentTargets = PlatformRegistry.default.knownPlatforms.reduce([PackageModel.Platform:PlatformVersion]()) { - var dict = $0 - dict[$1] = Self.computeXCTestMinimumDeploymentTarget(for: $1) - return dict + private init() { + } + + public func computeXCTestMinimumDeploymentTarget(for platform: PackageModel.Platform) -> PlatformVersion { + self.xcTestMinimumDeploymentTargets.memoize(platform) { + return Self.computeXCTestMinimumDeploymentTarget(for: platform) } } diff --git a/Sources/PackageModel/Platform.swift b/Sources/PackageModel/Platform.swift index 54613a266e1..a90e519cc2e 100644 --- a/Sources/PackageModel/Platform.swift +++ b/Sources/PackageModel/Platform.swift @@ -50,16 +50,56 @@ public struct Platform: Equatable, Hashable, Codable { public struct SupportedPlatforms { public let declared: [SupportedPlatform] - public let derived: [SupportedPlatform] + private let derivedXCTestPlatformProvider: ((Platform) -> PlatformVersion?)? - public init(declared: [SupportedPlatform], derived: [SupportedPlatform]) { + public init(declared: [SupportedPlatform], derivedXCTestPlatformProvider: ((_ declared: Platform) -> PlatformVersion?)?) { self.declared = declared - self.derived = derived + self.derivedXCTestPlatformProvider = derivedXCTestPlatformProvider } /// Returns the supported platform instance for the given platform. - public func getDerived(for platform: Platform) -> SupportedPlatform? { - return self.derived.first(where: { $0.platform == platform }) + public func getDerived(for platform: Platform, usingXCTest: Bool) -> SupportedPlatform { + // derived platform based on known minimum deployment target logic + if let declaredPlatform = self.declared.first(where: { $0.platform == platform }) { + var version = declaredPlatform.version + + if usingXCTest, let xcTestMinimumDeploymentTarget = derivedXCTestPlatformProvider?(platform), version < xcTestMinimumDeploymentTarget { + version = xcTestMinimumDeploymentTarget + } + + // If the declared version is smaller than the oldest supported one, we raise the derived version to that. + if version < platform.oldestSupportedVersion { + version = platform.oldestSupportedVersion + } + + return SupportedPlatform( + platform: declaredPlatform.platform, + version: version, + options: declaredPlatform.options + ) + } else { + let minimumSupportedVersion: PlatformVersion + if usingXCTest, let xcTestMinimumDeploymentTarget = derivedXCTestPlatformProvider?(platform), xcTestMinimumDeploymentTarget > platform.oldestSupportedVersion { + minimumSupportedVersion = xcTestMinimumDeploymentTarget + } else { + minimumSupportedVersion = platform.oldestSupportedVersion + } + + let oldestSupportedVersion: PlatformVersion + if platform == .macCatalyst { + let iOS = getDerived(for: .iOS, usingXCTest: usingXCTest) + // If there was no deployment target specified for Mac Catalyst, fall back to the iOS deployment target. + oldestSupportedVersion = max(minimumSupportedVersion, iOS.version) + } else { + oldestSupportedVersion = minimumSupportedVersion + } + + return SupportedPlatform( + platform: platform, + version: oldestSupportedVersion, + options: [] + ) + } } } diff --git a/Sources/SPMTestSupport/PackageGraphTester.swift b/Sources/SPMTestSupport/PackageGraphTester.swift index 580b157f880..981f7fc91e0 100644 --- a/Sources/SPMTestSupport/PackageGraphTester.swift +++ b/Sources/SPMTestSupport/PackageGraphTester.swift @@ -179,13 +179,21 @@ public final class ResolvedTargetResult { } public func checkDerivedPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { - let targetPlatforms = Dictionary(uniqueKeysWithValues: target.platforms.derived.map({ ($0.platform.name, $0.version.versionString) })) + let derived = platforms.map { + let platform = PlatformRegistry.default.platformByName[$0.key] ?? PackageModel.Platform + .custom(name: $0.key, oldestSupportedVersion: $0.value) + return self.target.platforms.getDerived(for: platform, usingXCTest: self.target.type == .test) + } + let targetPlatforms = Dictionary( + uniqueKeysWithValues: derived + .map { ($0.platform.name, $0.version.versionString) } + ) XCTAssertEqual(platforms, targetPlatforms, file: file, line: line) } public func checkDerivedPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) { - let platform = target.platforms.getDerived(for: platform) - XCTAssertEqual(platform?.options, options, file: file, line: line) + let platform = target.platforms.getDerived(for: platform, usingXCTest: target.type == .test) + XCTAssertEqual(platform.options, options, file: file, line: line) } } @@ -230,13 +238,17 @@ public final class ResolvedProductResult { } public func checkDerivedPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { - let targetPlatforms = Dictionary(uniqueKeysWithValues: product.platforms.derived.map({ ($0.platform.name, $0.version.versionString) })) + let derived = platforms.map { + let platform = PlatformRegistry.default.platformByName[$0.key] ?? PackageModel.Platform.custom(name: $0.key, oldestSupportedVersion: $0.value) + return product.platforms.getDerived(for: platform, usingXCTest: product.isLinkingXCTest) + } + let targetPlatforms = Dictionary(uniqueKeysWithValues: derived.map({ ($0.platform.name, $0.version.versionString) })) XCTAssertEqual(platforms, targetPlatforms, file: file, line: line) } public func checkDerivedPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) { - let platform = product.platforms.getDerived(for: platform) - XCTAssertEqual(platform?.options, options, file: file, line: line) + let platform = product.platforms.getDerived(for: platform, usingXCTest: product.isLinkingXCTest) + XCTAssertEqual(platform.options, options, file: file, line: line) } } diff --git a/Sources/XCBuildSupport/PIFBuilder.swift b/Sources/XCBuildSupport/PIFBuilder.swift index 945beabcc52..8e265ba18b6 100644 --- a/Sources/XCBuildSupport/PIFBuilder.swift +++ b/Sources/XCBuildSupport/PIFBuilder.swift @@ -298,7 +298,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder { PlatformRegistry.default.knownPlatforms.forEach { guard let platform = PIF.BuildSettings.Platform.from(platform: $0) else { return } - guard let supportedPlatform = package.platforms.getDerived(for: $0) else { return } + let supportedPlatform = package.platforms.getDerived(for: $0, usingXCTest: false) if !supportedPlatform.options.isEmpty { settings[.SPECIALIZATION_SDK_OPTIONS, for: platform] = supportedPlatform.options } @@ -427,11 +427,11 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder { // Tests can have a custom deployment target based on the minimum supported by XCTest. if mainTarget.underlyingTarget.type == .test { - settings[.MACOSX_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .macOS) - settings[.IPHONEOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .iOS) - settings[.TVOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .tvOS) - settings[.WATCHOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .watchOS) - settings[.XROS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .visionOS) + settings[.MACOSX_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .macOS, usingXCTest: true) + settings[.IPHONEOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .iOS, usingXCTest: true) + settings[.TVOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .tvOS, usingXCTest: true) + settings[.WATCHOS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .watchOS, usingXCTest: true) + settings[.XROS_DEPLOYMENT_TARGET] = mainTarget.platforms.deploymentTarget(for: .visionOS, usingXCTest: true) } if product.type == .executable { @@ -1414,17 +1414,8 @@ extension Array where Element == ResolvedTarget.Dependency { } extension SupportedPlatforms { - func deploymentTarget(for platform: PackageModel.Platform) -> String? { - if let supportedPlatform = self.getDerived(for: platform) { - return supportedPlatform.version.versionString - } else if platform == .macCatalyst { - // If there is no deployment target specified for Mac Catalyst, fall back to the iOS deployment target. - return deploymentTarget(for: .iOS) - } else if platform.oldestSupportedVersion != .unknown { - return platform.oldestSupportedVersion.versionString - } else { - return nil - } + func deploymentTarget(for platform: PackageModel.Platform, usingXCTest: Bool = false) -> String? { + return self.getDerived(for: platform, usingXCTest: usingXCTest).version.versionString } } diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index fe7ff89f53a..e0a2b423e93 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -1710,6 +1710,12 @@ final class BuildPlanTests: XCTestCase { #if os(macOS) let version = MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(for: .macOS).versionString + let rpathsForBackdeployment: [String] + if let version = try? Version(string: version, lenient: true), version.major < 12 { + rpathsForBackdeployment = ["-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx"] + } else { + rpathsForBackdeployment = [] + } XCTAssertEqual(try result.buildProduct(for: "PkgPackageTests").linkArguments(), [ result.plan.buildParameters.toolchain.swiftCompilerPath.pathString, "-L", buildPath.pathString, @@ -1717,9 +1723,9 @@ final class BuildPlanTests: XCTestCase { "-module-name", "PkgPackageTests", "-Xlinker", "-bundle", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../../../", - "@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))", - "-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx", - "-target", "\(hostTriple.tripleString(forPlatformVersion: version))", + "@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))"] + + rpathsForBackdeployment + + ["-target", "\(hostTriple.tripleString(forPlatformVersion: version))", "-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Foo.swiftmodule").pathString, "-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "FooTests.swiftmodule").pathString, ]) diff --git a/Tests/CommandsTests/PackageToolTests.swift b/Tests/CommandsTests/PackageToolTests.swift index c4b9b42b72f..6287a5753a4 100644 --- a/Tests/CommandsTests/PackageToolTests.swift +++ b/Tests/CommandsTests/PackageToolTests.swift @@ -940,7 +940,7 @@ final class PackageToolTests: CommandsTestCase { // Checks the content of checked out bar.swift. func checkBar(_ value: Int, file: StaticString = #file, line: UInt = #line) throws { let contents: String = try localFileSystem.readFileContents(barPath.appending(components:"Sources", "bar.swift")) - XCTAssertTrue(contents.spm_chomp().hasSuffix("\(value)"), file: file, line: line) + XCTAssertTrue(contents.spm_chomp().hasSuffix("\(value)"), "got \(contents)", file: file, line: line) } // We should see a pin file now. diff --git a/Tests/PackageGraphTests/TargetTests.swift b/Tests/PackageGraphTests/TargetTests.swift index 2143f266ad2..d3b9969b14c 100644 --- a/Tests/PackageGraphTests/TargetTests.swift +++ b/Tests/PackageGraphTests/TargetTests.swift @@ -31,7 +31,7 @@ private extension ResolvedTarget { ), dependencies: deps.map { .target($0, conditions: []) }, defaultLocalization: nil, - platforms: .init(declared: [], derived: []) + platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) ) } }