From 6c70d177d2454b70e190ab8ba309ea5ad0f456af Mon Sep 17 00:00:00 2001 From: Anders Bertelrud Date: Fri, 30 Apr 2021 13:06:17 -0700 Subject: [PATCH] [5.5] Unify PackageDescription 4.0 and 4.2+ into a single library by using availability annotations instead of #if Unify PackageDescription 4.0 and 4.2+ into a single library by using availability annotations instead of #if Replace the compile-time conditionals in PackageDescription with availability annotations. This lets us build a single PackageDescription, which will make the build scripts easier (with the goal of being able to build it entirely from the package itself). As part of this we also clean up the runtime library subdirectories. Until now we've had PackagePlugin directly in the runtime library directory, and PackageDescription under subdirectories called "4" and "4_2". This has sufficed in keeping PackageDescription and PackagePlugin in separate directories (so that a manifest or plugin script can't import both). This needs to be changed now that there is only one version of a PackageDescription, and anyway it's time to clean this up. So as part of this we also establish two subdirectories for the runtime APIs: "ManifestAPI" and "PluginAPI". If we add more kinds of scripts, we can then add new subdirectories here. rdar://77441062 (cherry picked from 2d2b3876c78d69b867434da879c6bfa2e22014a9) --- Package.swift | 22 ++-- Sources/PackageDescription/CMakeLists.txt | 122 +++++++++--------- .../LanguageStandardSettings.swift | 2 - .../PackageDependency.swift | 22 +--- .../PackageDescription.swift | 91 ++----------- .../PackageRequirement.swift | 40 ------ Sources/PackageDescription/Target.swift | 46 ++----- Sources/PackageLoading/ManifestLoader.swift | 2 +- Sources/PackagePlugin/CMakeLists.txt | 87 +++++++------ .../Workspace/DefaultPluginScriptRunner.swift | 2 +- Sources/Xcodeproj/pbxproj.swift | 2 +- .../PD4_2LoadingTests.swift | 2 +- Utilities/bootstrap | 29 ++--- 13 files changed, 161 insertions(+), 308 deletions(-) diff --git a/Package.swift b/Package.swift index a2648957d23..3f33971feea 100644 --- a/Package.swift +++ b/Package.swift @@ -113,19 +113,25 @@ let package = Package( ), ], targets: [ - // The `PackageDescription` targets define the API which is available to - // the `Package.swift` manifest files. We build the latest API version - // here which is used when building and running swiftpm without the - // bootstrap script. + // The `PackageDescription` target provides the API that is available + // to `Package.swift` manifests. Here we build a debug version of the + // library; the bootstrap scripts build the deployable version. .target( - /** Package Definition API */ name: "PackageDescription", swiftSettings: [ - .define("PACKAGE_DESCRIPTION_4_2"), + .unsafeFlags(["-package-description-version", "999.0"]), + .unsafeFlags(["-enable-library-evolution"]) ]), - + + // The `PackagePlugin` target provides the API that is available to + // plugin scripts. Here we build a debug version of the library; the + // bootstrap scripts build the deployable version. .target( - name: "PackagePlugin"), + name: "PackagePlugin", + swiftSettings: [ + .unsafeFlags(["-package-description-version", "999.0"]), + .unsafeFlags(["-enable-library-evolution"]) + ]), // MARK: SwiftPM specific support libraries diff --git a/Sources/PackageDescription/CMakeLists.txt b/Sources/PackageDescription/CMakeLists.txt index c3e696dae69..9c063e27641 100644 --- a/Sources/PackageDescription/CMakeLists.txt +++ b/Sources/PackageDescription/CMakeLists.txt @@ -1,75 +1,73 @@ # This source file is part of the Swift.org open source project # -# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors # Licensed under Apache License v2.0 with Runtime Library Exception # # See http://swift.org/LICENSE.txt for license information # See http://swift.org/CONTRIBUTORS.txt for Swift project authors -foreach(PACKAGE_DESCRIPTION_VERSION 4 4_2) - add_library(PD${PACKAGE_DESCRIPTION_VERSION} - BuildSettings.swift - LanguageStandardSettings.swift - PackageDescription.swift - PackageDependency.swift - PackageRequirement.swift - Product.swift - Resource.swift - SupportedPlatforms.swift - Target.swift - Version.swift - Version+StringLiteralConvertible.swift) +add_library(PackageDescription + BuildSettings.swift + LanguageStandardSettings.swift + PackageDescription.swift + PackageDependency.swift + PackageRequirement.swift + Product.swift + Resource.swift + SupportedPlatforms.swift + Target.swift + Version.swift + Version+StringLiteralConvertible.swift) - target_compile_definitions(PD${PACKAGE_DESCRIPTION_VERSION} PRIVATE - PACKAGE_DESCRIPTION_${PACKAGE_DESCRIPTION_VERSION}) +target_compile_options(PackageDescription PUBLIC + $<$:-package-description-version$999.0>) +target_compile_options(PackageDescription PUBLIC + $<$:-enable-library-evolution>) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - set(SWIFT_INTERFACE_PATH ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}/PackageDescription.swiftinterface) - target_compile_options(PD${PACKAGE_DESCRIPTION_VERSION} PUBLIC - $<$:-enable-library-evolution>) - target_compile_options(PD${PACKAGE_DESCRIPTION_VERSION} PUBLIC - $<$:-emit-module-interface-path$${SWIFT_INTERFACE_PATH}>) - target_link_options(PD${PACKAGE_DESCRIPTION_VERSION} PRIVATE - "SHELL:-Xlinker -install_name -Xlinker @rpath/libPackageDescription.dylib") - endif() +if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) + set(SWIFT_INTERFACE_PATH ${CMAKE_BINARY_DIR}/pm/ManifestAPI/PackageDescription.swiftinterface) + target_compile_options(PackageDescription PUBLIC + $<$:-emit-module-interface-path$${SWIFT_INTERFACE_PATH}>) + target_link_options(PackageDescription PRIVATE + "SHELL:-Xlinker -install_name -Xlinker @rpath/libPackageDescription.dylib") +endif() - set_target_properties(PD${PACKAGE_DESCRIPTION_VERSION} PROPERTIES - Swift_MODULE_NAME PackageDescription - Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION} - INSTALL_NAME_DIR \\@rpath - OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION} - OUTPUT_NAME PackageDescription - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION} - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION} - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION} - ) +set_target_properties(PackageDescription PROPERTIES + Swift_MODULE_NAME PackageDescription + Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI + INSTALL_NAME_DIR \\@rpath + OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI + OUTPUT_NAME PackageDescription + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI +) - if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) - if(Foundation_FOUND) - target_link_libraries(PD${PACKAGE_DESCRIPTION_VERSION} PRIVATE - Foundation) - endif() - target_link_options(PD${PACKAGE_DESCRIPTION_VERSION} PRIVATE - "SHELL:-no-toolchain-stdlib-rpath") - set_target_properties(PD${PACKAGE_DESCRIPTION_VERSION} PROPERTIES - BUILD_WITH_INSTALL_RPATH TRUE - INSTALL_RPATH "$ORIGIN/../../$") - endif() +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + if(Foundation_FOUND) + target_link_libraries(PackageDescription PRIVATE + Foundation) + endif() + target_link_options(PackageDescription PRIVATE + "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(PackageDescription PROPERTIES + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH "$ORIGIN/../../$") +endif() - if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - install(FILES - ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}/PackageDescription.swiftinterface - ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}/PackageDescription.swiftdoc - DESTINATION lib/swift/pm/${PACKAGE_DESCRIPTION_VERSION} - ) - else() - install(FILES - ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}/PackageDescription.swiftmodule - ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}/PackageDescription.swiftdoc - DESTINATION lib/swift/pm/${PACKAGE_DESCRIPTION_VERSION} - ) - endif() +if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) + install(FILES + ${CMAKE_BINARY_DIR}/pm/ManifestAPI/PackageDescription.swiftinterface + ${CMAKE_BINARY_DIR}/pm/ManifestAPI/PackageDescription.swiftdoc + DESTINATION lib/swift/pm/ManifestAPI + ) +else() + install(FILES + ${CMAKE_BINARY_DIR}/pm/ManifestAPI/PackageDescription.swiftmodule + ${CMAKE_BINARY_DIR}/pm/ManifestAPI/PackageDescription.swiftdoc + DESTINATION lib/swift/pm/ManifestAPI + ) +endif() - install(TARGETS PD${PACKAGE_DESCRIPTION_VERSION} - DESTINATION lib/swift/pm/${PACKAGE_DESCRIPTION_VERSION}) -endforeach() +install(TARGETS PackageDescription + DESTINATION lib/swift/pm/ManifestAPI) diff --git a/Sources/PackageDescription/LanguageStandardSettings.swift b/Sources/PackageDescription/LanguageStandardSettings.swift index bf1311ee2e8..630ea1535f3 100644 --- a/Sources/PackageDescription/LanguageStandardSettings.swift +++ b/Sources/PackageDescription/LanguageStandardSettings.swift @@ -144,7 +144,6 @@ public enum CXXLanguageStandard: String, Encodable { case gnucxx20 = "gnu++20" } -#if !PACKAGE_DESCRIPTION_4 /// The version of the Swift language to use for compiling Swift sources in the package. public enum SwiftVersion { @available(_PackageDescription, introduced: 4, obsoleted: 5) @@ -187,4 +186,3 @@ extension SwiftVersion: Encodable { try container.encode(value) } } -#endif diff --git a/Sources/PackageDescription/PackageDependency.swift b/Sources/PackageDescription/PackageDependency.swift index 138fe97b364..827c586c3a5 100644 --- a/Sources/PackageDescription/PackageDependency.swift +++ b/Sources/PackageDescription/PackageDependency.swift @@ -147,11 +147,7 @@ extension Package.Dependency { url: String, _ range: Range ) -> Package.Dependency { - #if PACKAGE_DESCRIPTION_4 return .init(name: nil, url: url, requirement: .rangeItem(range)) - #else - return .init(name: nil, url: url, requirement: ._rangeItem(range)) - #endif } /// Adds a package dependency starting with a specific minimum version, up to @@ -172,11 +168,7 @@ extension Package.Dependency { url: String, _ range: Range ) -> Package.Dependency { - #if PACKAGE_DESCRIPTION_4 return .init(name: name, url: url, requirement: .rangeItem(range)) - #else - return .init(name: name, url: url, requirement: ._rangeItem(range)) - #endif } /// Adds a package dependency starting with a specific minimum version, going @@ -202,11 +194,7 @@ extension Package.Dependency { upper.major, upper.minor, upper.patch + 1, prereleaseIdentifiers: upper.prereleaseIdentifiers, buildMetadataIdentifiers: upper.buildMetadataIdentifiers) - #if PACKAGE_DESCRIPTION_4 return .init(name: nil, url: url, requirement: .rangeItem(range.lowerBound.. Package.Dependency { - return .init(name: nil, url: path, requirement: ._localPackageItem) + return .init(name: nil, url: path, requirement: .localPackageItem) } /// Adds a package dependency to a local package on the filesystem. @@ -271,9 +254,8 @@ extension Package.Dependency { name: String? = nil, path: String ) -> Package.Dependency { - return .init(name: name, url: path, requirement: ._localPackageItem) + return .init(name: name, url: path, requirement: .localPackageItem) } - #endif } // Mark common APIs used by mistake as unavailable to provide better error messages. diff --git a/Sources/PackageDescription/PackageDescription.swift b/Sources/PackageDescription/PackageDescription.swift index 6527fe3e014..c4417432ebc 100644 --- a/Sources/PackageDescription/PackageDescription.swift +++ b/Sources/PackageDescription/PackageDescription.swift @@ -122,26 +122,14 @@ public final class Package { /// dependency requirements; you should remove commit-based dependency /// requirements before publishing a version of your package. public enum Requirement { - #if PACKAGE_DESCRIPTION_4 case exactItem(Version) case rangeItem(Range) case revisionItem(String) case branchItem(String) case localPackageItem - #else - case _exactItem(Version) - case _rangeItem(Range) - case _revisionItem(String) - case _branchItem(String) - case _localPackageItem - #endif var isLocalPackage: Bool { - #if PACKAGE_DESCRIPTION_4 if case .localPackageItem = self { return true } - #else - if case ._localPackageItem = self { return true } - #endif return false } } @@ -167,14 +155,12 @@ public final class Package { /// The name of the Swift package. public var name: String - #if !PACKAGE_DESCRIPTION_4 /// The list of supported platforms with a custom deployment target. @available(_PackageDescription, introduced: 5) public var platforms: [SupportedPlatform]? { get { return _platforms } set { _platforms = newValue } } - #endif private var _platforms: [SupportedPlatform]? /// The default localization for resources. @@ -203,13 +189,8 @@ public final class Package { /// The list of package dependencies. public var dependencies: [Dependency] - #if PACKAGE_DESCRIPTION_4 - /// The list of Swift versions that this package is compatible with. - public var swiftLanguageVersions: [Int]? - #else /// The list of Swift versions that this package is compatible with. public var swiftLanguageVersions: [SwiftVersion]? - #endif /// The C language standard to use for all C targets in this package. public var cLanguageStandard: CLanguageStandard? @@ -217,13 +198,12 @@ public final class Package { /// The C++ language standard to use for all C++ targets in this package. public var cxxLanguageStandard: CXXLanguageStandard? - #if PACKAGE_DESCRIPTION_4 /// Initializes a Swift package with configuration options you provide. /// /// - Parameters: /// - name: The name of the Swift package, or `nil`, if you want the Swift Package Manager to deduce the /// name from the package’s Git URL. - /// - pkgConfig: The name to use for C modules. If present, the Swift + /// - pkgConfig: The name to use for C modules. If present, the Swift /// Package Manager searches for a `.pc` file to get the /// additional flags required for a system target. /// - providers: The package providers for a system package. @@ -233,6 +213,7 @@ public final class Package { /// - swiftLanguageVersions: The list of Swift versions that this package is compatible with. /// - cLanguageStandard: The C language standard to use for all C targets in this package. /// - cxxLanguageStandard: The C++ language standard to use for all C++ targets in this package. + @available(_PackageDescription, obsoleted: 4.2) public init( name: String, pkgConfig: String? = nil, @@ -250,12 +231,12 @@ public final class Package { self.products = products self.dependencies = dependencies self.targets = targets - self.swiftLanguageVersions = swiftLanguageVersions + self.swiftLanguageVersions = swiftLanguageVersions.map{ $0.map{ .version("\($0)") } } self.cLanguageStandard = cLanguageStandard self.cxxLanguageStandard = cxxLanguageStandard registerExitHandler() } - #else + /// Initializes a Swift package with configuration options you provide. /// /// - Parameters: @@ -378,7 +359,6 @@ public final class Package { self.cxxLanguageStandard = cxxLanguageStandard registerExitHandler() } - #endif private func registerExitHandler() { // Add a custom exit handler to cause the package's JSON representation @@ -457,14 +437,10 @@ extension LanguageTag: CustomStringConvertible { /// The system package providers used in this Swift package. public enum SystemPackageProvider { - #if PACKAGE_DESCRIPTION_4 case brewItem([String]) case aptItem([String]) - #else - case _brewItem([String]) - case _aptItem([String]) - case _yumItem([String]) - #endif + @available(_PackageDescription, introduced: 5.3) + case yumItem([String]) /// Creates a system package provider with a list of installable packages /// for users of the HomeBrew package manager on macOS. @@ -472,11 +448,7 @@ public enum SystemPackageProvider { /// - Parameters: /// - packages: The list of package names. public static func brew(_ packages: [String]) -> SystemPackageProvider { - #if PACKAGE_DESCRIPTION_4 return .brewItem(packages) - #else - return ._brewItem(packages) - #endif } /// Creates a system package provider with a list of installable packages @@ -485,16 +457,9 @@ public enum SystemPackageProvider { /// - Parameters: /// - packages: The list of package names. public static func apt(_ packages: [String]) -> SystemPackageProvider { - #if PACKAGE_DESCRIPTION_4 return .aptItem(packages) - #else - return ._aptItem(packages) - #endif } -#if PACKAGE_DESCRIPTION_4 -// yum is not supported -#else /// Creates a system package provider with a list of installable packages /// for users of the yum package manager on Red Hat Enterprise Linux or CentOS. /// @@ -502,9 +467,8 @@ public enum SystemPackageProvider { /// - packages: The list of package names. @available(_PackageDescription, introduced: 5.3) public static func yum(_ packages: [String]) -> SystemPackageProvider { - return ._yumItem(packages) + return .yumItem(packages) } -#endif } // MARK: Package JSON serialization @@ -528,26 +492,19 @@ extension Package: Encodable { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(name, forKey: .name) - #if !PACKAGE_DESCRIPTION_4 if let defaultLocalization = _defaultLocalization { try container.encode(defaultLocalization.tag, forKey: .defaultLocalization) } if let platforms = self._platforms { try container.encode(platforms, forKey: .platforms) } - #endif try container.encode(pkgConfig, forKey: .pkgConfig) try container.encode(providers, forKey: .providers) try container.encode(products, forKey: .products) try container.encode(dependencies, forKey: .dependencies) try container.encode(targets, forKey: .targets) - #if PACKAGE_DESCRIPTION_4 - let slv = swiftLanguageVersions?.map({ String($0) }) - try container.encode(slv, forKey: .swiftLanguageVersions) - #else try container.encode(swiftLanguageVersions, forKey: .swiftLanguageVersions) - #endif try container.encode(cLanguageStandard, forKey: .cLanguageStandard) try container.encode(cxxLanguageStandard, forKey: .cxxLanguageStandard) } @@ -567,7 +524,6 @@ extension SystemPackageProvider: Encodable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - #if PACKAGE_DESCRIPTION_4 switch self { case .brewItem(let packages): try container.encode(Name.brew, forKey: .name) @@ -575,20 +531,10 @@ extension SystemPackageProvider: Encodable { case .aptItem(let packages): try container.encode(Name.apt, forKey: .name) try container.encode(packages, forKey: .values) - } - #else - switch self { - case ._brewItem(let packages): - try container.encode(Name.brew, forKey: .name) - try container.encode(packages, forKey: .values) - case ._aptItem(let packages): - try container.encode(Name.apt, forKey: .name) - try container.encode(packages, forKey: .values) - case ._yumItem(let packages): + case .yumItem(let packages): try container.encode(Name.yum, forKey: .name) try container.encode(packages, forKey: .values) } - #endif } } @@ -626,36 +572,21 @@ extension Target.Dependency: Encodable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - #if PACKAGE_DESCRIPTION_4 - switch self { - case .targetItem(let name): - try container.encode(Kind.target, forKey: .type) - try container.encode(name, forKey: .name) - case .productItem(let name, let package): - try container.encode(Kind.product, forKey: .type) - try container.encode(name, forKey: .name) - try container.encode(package, forKey: .package) - case .byNameItem(let name): - try container.encode(Kind.byName, forKey: .type) - try container.encode(name, forKey: .name) - } - #else switch self { - case ._targetItem(let name, let condition): + case .targetItem(let name, let condition): try container.encode(Kind.target, forKey: .type) try container.encode(name, forKey: .name) try container.encode(condition, forKey: .condition) - case ._productItem(let name, let package, let condition): + case .productItem(let name, let package, let condition): try container.encode(Kind.product, forKey: .type) try container.encode(name, forKey: .name) try container.encode(package, forKey: .package) try container.encode(condition, forKey: .condition) - case ._byNameItem(let name, let condition): + case .byNameItem(let name, let condition): try container.encode(Kind.byName, forKey: .type) try container.encode(name, forKey: .name) try container.encode(condition, forKey: .condition) } - #endif } } diff --git a/Sources/PackageDescription/PackageRequirement.swift b/Sources/PackageDescription/PackageRequirement.swift index b6f22024388..3b0c91875f5 100644 --- a/Sources/PackageDescription/PackageRequirement.swift +++ b/Sources/PackageDescription/PackageRequirement.swift @@ -24,11 +24,7 @@ extension Package.Dependency.Requirement: Encodable { /// - Parameters: /// - version: The exact version of the dependency for this requirement. public static func exact(_ version: Version) -> Package.Dependency.Requirement { - #if PACKAGE_DESCRIPTION_4 return .exactItem(version) - #else - return ._exactItem(version) - #endif } /// Returns a requirement for a source control revision such as the hash of a commit. @@ -45,11 +41,7 @@ extension Package.Dependency.Requirement: Encodable { /// - Parameters: /// - ref: The Git revision, usually a commit hash. public static func revision(_ ref: String) -> Package.Dependency.Requirement { - #if PACKAGE_DESCRIPTION_4 return .revisionItem(ref) - #else - return ._revisionItem(ref) - #endif } /// Returns a requirement for a source control branch. @@ -67,11 +59,7 @@ extension Package.Dependency.Requirement: Encodable { /// - Parameters: /// - name: The name of the branch. public static func branch(_ name: String) -> Package.Dependency.Requirement { - #if PACKAGE_DESCRIPTION_4 return .branchItem(name) - #else - return ._branchItem(name) - #endif } /// Returns a requirement for a version range, starting at the given minimum @@ -80,11 +68,7 @@ extension Package.Dependency.Requirement: Encodable { /// - Parameters: /// - version: The minimum version for the version range. public static func upToNextMajor(from version: Version) -> Package.Dependency.Requirement { - #if PACKAGE_DESCRIPTION_4 return .rangeItem(version.. Package.Dependency.Requirement { - #if PACKAGE_DESCRIPTION_4 return .rangeItem(version.. Target.Dependency { - #if PACKAGE_DESCRIPTION_4 - return .targetItem(name: name) - #else - return ._targetItem(name: name, condition: nil) - #endif + return .targetItem(name: name, condition: nil) } /// Creates a dependency on a product from a package dependency. @@ -1005,11 +995,7 @@ extension Target.Dependency { /// - package: The name of the package. @available(_PackageDescription, obsoleted: 5.2, message: "the 'package' argument is mandatory as of tools version 5.2") public static func product(name: String, package: String? = nil) -> Target.Dependency { - #if PACKAGE_DESCRIPTION_4 - return .productItem(name: name, package: package) - #else - return ._productItem(name: name, package: package, condition: nil) - #endif + return .productItem(name: name, package: package, condition: nil) } /// Creates a dependency that resolves to either a target or a product with the specified name. @@ -1020,14 +1006,9 @@ extension Target.Dependency { /// The Swift Package Manager creates the by-name dependency after it has loaded the package graph. @available(_PackageDescription, obsoleted: 5.3) public static func byName(name: String) -> Target.Dependency { - #if PACKAGE_DESCRIPTION_4 - return .byNameItem(name: name) - #else - return ._byNameItem(name: name, condition: nil) - #endif + return .byNameItem(name: name, condition: nil) } - #if !PACKAGE_DESCRIPTION_4 /// Creates a dependency on a product from a package dependency. /// /// - parameters: @@ -1038,7 +1019,7 @@ extension Target.Dependency { name: String, package: String ) -> Target.Dependency { - return ._productItem(name: name, package: package, condition: nil) + return .productItem(name: name, package: package, condition: nil) } /// Creates a dependency on a target in the same package. @@ -1049,7 +1030,7 @@ extension Target.Dependency { /// dependency for a specific platform. @available(_PackageDescription, introduced: 5.3) public static func target(name: String, condition: TargetDependencyCondition? = nil) -> Target.Dependency { - return ._targetItem(name: name, condition: condition) + return .targetItem(name: name, condition: condition) } /// Creates a target dependency on a product from a package dependency. @@ -1065,7 +1046,7 @@ extension Target.Dependency { package: String, condition: TargetDependencyCondition? = nil ) -> Target.Dependency { - return ._productItem(name: name, package: package, condition: condition) + return .productItem(name: name, package: package, condition: condition) } /// Creates a by-name dependency that resolves to either a target or a product but after the Swift Package Manager @@ -1077,9 +1058,8 @@ extension Target.Dependency { /// dependency for a specific platform. @available(_PackageDescription, introduced: 5.3) public static func byName(name: String, condition: TargetDependencyCondition? = nil) -> Target.Dependency { - return ._byNameItem(name: name, condition: condition) + return .byNameItem(name: name, condition: condition) } - #endif } extension Target.PluginCapability { @@ -1124,11 +1104,7 @@ extension Target.Dependency: ExpressibleByStringLiteral { /// - parameters: /// - value: A string literal. public init(stringLiteral value: String) { - #if PACKAGE_DESCRIPTION_4 - self = .byNameItem(name: value) - #else - self = ._byNameItem(name: value, condition: nil) - #endif + self = .byNameItem(name: value, condition: nil) } } diff --git a/Sources/PackageLoading/ManifestLoader.swift b/Sources/PackageLoading/ManifestLoader.swift index 8d4dc456e3c..986351c12bd 100644 --- a/Sources/PackageLoading/ManifestLoader.swift +++ b/Sources/PackageLoading/ManifestLoader.swift @@ -938,7 +938,7 @@ public final class ManifestLoader: ManifestLoaderProtocol { /// Returns the runtime path given the manifest version and path to libDir. private func runtimePath(for version: ToolsVersion) -> AbsolutePath { // Bin dir will be set when developing swiftpm without building all of the runtimes. - return resources.binDir ?? resources.libDir.appending(version.runtimeSubpath) + return resources.binDir ?? resources.libDir.appending(component: "ManifestAPI") } /// Returns path to the manifest database inside the given cache directory. diff --git a/Sources/PackagePlugin/CMakeLists.txt b/Sources/PackagePlugin/CMakeLists.txt index c1737a04e1e..91f07ea3a0e 100644 --- a/Sources/PackagePlugin/CMakeLists.txt +++ b/Sources/PackagePlugin/CMakeLists.txt @@ -7,60 +7,63 @@ # See http://swift.org/CONTRIBUTORS.txt for Swift project authors add_library(PackagePlugin - PublicAPI/CommandConstructor.swift - PublicAPI/DiagnosticsEmitter.swift - PublicAPI/FileList.swift - PublicAPI/Globals.swift - PublicAPI/Path.swift - PublicAPI/TargetBuildContext.swift - ImplementationDetails.swift) + PublicAPI/CommandConstructor.swift + PublicAPI/DiagnosticsEmitter.swift + PublicAPI/FileList.swift + PublicAPI/Globals.swift + PublicAPI/Path.swift + PublicAPI/TargetBuildContext.swift + ImplementationDetails.swift) + +target_compile_options(PackagePlugin PUBLIC + $<$:-package-description-version$999.0>) +target_compile_options(PackagePlugin PUBLIC + $<$:-enable-library-evolution>) if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - set(SWIFT_INTERFACE_PATH ${CMAKE_BINARY_DIR}/pm/PackagePlugin.swiftinterface) - target_compile_options(PackagePlugin PUBLIC - $<$:-enable-library-evolution>) - target_compile_options(PackagePlugin PUBLIC - $<$:-emit-module-interface-path$${SWIFT_INTERFACE_PATH}>) - target_link_options(PackagePlugin PRIVATE - "SHELL:-Xlinker -install_name -Xlinker @rpath/libPackagePlugin.dylib") + set(SWIFT_INTERFACE_PATH ${CMAKE_BINARY_DIR}/pm/PluginAPI/PackagePlugin.swiftinterface) + target_compile_options(PackagePlugin PUBLIC + $<$:-emit-module-interface-path$${SWIFT_INTERFACE_PATH}>) + target_link_options(PackagePlugin PRIVATE + "SHELL:-Xlinker -install_name -Xlinker @rpath/libPackagePlugin.dylib") endif() set_target_properties(PackagePlugin PROPERTIES - Swift_MODULE_NAME PackagePlugin - Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/pm - INSTALL_NAME_DIR \\@rpath - OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm - OUTPUT_NAME PackagePlugin - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm + Swift_MODULE_NAME PackagePlugin + Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI + INSTALL_NAME_DIR \\@rpath + OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI + OUTPUT_NAME PackagePlugin + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI ) if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) - if(Foundation_FOUND) - target_link_libraries(PackagePlugin PRIVATE - Foundation) - endif() - target_link_options(PackagePlugin PRIVATE - "SHELL:-no-toolchain-stdlib-rpath") - set_target_properties(PackagePlugin PROPERTIES - BUILD_WITH_INSTALL_RPATH TRUE - INSTALL_RPATH "$ORIGIN/../../$") + if(Foundation_FOUND) + target_link_libraries(PackagePlugin PRIVATE + Foundation) + endif() + target_link_options(PackagePlugin PRIVATE + "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(PackagePlugin PROPERTIES + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH "$ORIGIN/../../$") endif() if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) - install(FILES - ${CMAKE_BINARY_DIR}/pm/PackagePlugin.swiftinterface - ${CMAKE_BINARY_DIR}/pm/PackagePlugin.swiftdoc - DESTINATION lib/swift/pm - ) + install(FILES + ${CMAKE_BINARY_DIR}/pm/PluginAPI/PackagePlugin.swiftinterface + ${CMAKE_BINARY_DIR}/pm/PluginAPI/PackagePlugin.swiftdoc + DESTINATION lib/swift/pm/PluginAPI + ) else() - install(FILES - ${CMAKE_BINARY_DIR}/pm/PackagePlugin.swiftmodule - ${CMAKE_BINARY_DIR}/pm/PackagePlugin.swiftdoc - DESTINATION lib/swift/pm - ) + install(FILES + ${CMAKE_BINARY_DIR}/pm/PluginAPI/PackagePlugin.swiftmodule + ${CMAKE_BINARY_DIR}/pm/PluginAPI/PackagePlugin.swiftdoc + DESTINATION lib/swift/pm/PluginAPI + ) endif() install(TARGETS PackagePlugin - DESTINATION lib/swift/pm) + DESTINATION lib/swift/pm/PluginAPI) diff --git a/Sources/Workspace/DefaultPluginScriptRunner.swift b/Sources/Workspace/DefaultPluginScriptRunner.swift index a766a52f3c3..048e0b8933c 100644 --- a/Sources/Workspace/DefaultPluginScriptRunner.swift +++ b/Sources/Workspace/DefaultPluginScriptRunner.swift @@ -50,7 +50,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner { // FIXME: Much of this is copied from the ManifestLoader and should be consolidated. // Bin dir will be set when developing swiftpm without building all of the runtimes. - let runtimePath = self.resources.binDir ?? self.resources.libDir + let runtimePath = self.resources.binDir ?? self.resources.libDir.appending(component: "PluginAPI") // Compile the package plugin script. var command = [resources.swiftCompiler.pathString] diff --git a/Sources/Xcodeproj/pbxproj.swift b/Sources/Xcodeproj/pbxproj.swift index e1df5c4858f..611331a8867 100644 --- a/Sources/Xcodeproj/pbxproj.swift +++ b/Sources/Xcodeproj/pbxproj.swift @@ -81,7 +81,7 @@ public func xcodeProject( var interpreterFlags = manifestLoader.interpreterFlags(for: package.manifest.toolsVersion) if !interpreterFlags.isEmpty { // Patch the interpreter flags to use Xcode supported toolchain macro instead of the resolved path. - interpreterFlags[3] = "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/\(package.manifest.toolsVersion.runtimeSubpath.pathString)" + interpreterFlags[3] = "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/ManifestAPI" } pdTarget.buildSettings.common.OTHER_SWIFT_FLAGS += interpreterFlags pdTarget.buildSettings.common.SWIFT_VERSION = package.manifest.toolsVersion.swiftLanguageVersion.xcodeBuildSettingValue diff --git a/Tests/PackageLoadingTests/PD4_2LoadingTests.swift b/Tests/PackageLoadingTests/PD4_2LoadingTests.swift index 296e788cb67..f7d66c63b9a 100644 --- a/Tests/PackageLoadingTests/PD4_2LoadingTests.swift +++ b/Tests/PackageLoadingTests/PD4_2LoadingTests.swift @@ -98,7 +98,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { guard case let ManifestParseError.invalidManifestFormat(output, _) = error else { return XCTFail() } - XCTAssertMatch(output, .and(.or(.contains("expected argument type"), .contains("expected element type")), .contains("SwiftVersion"))) + XCTAssertMatch(output, .and(.contains("'init(name:pkgConfig:providers:products:dependencies:targets:swiftLanguageVersions:cLanguageStandard:cxxLanguageStandard:)' is unavailable"), .contains("was obsoleted in PackageDescription 4.2"))) } // Check when Swift language versions is empty. diff --git a/Utilities/bootstrap b/Utilities/bootstrap index dc61e55b543..2303db23ec2 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -393,22 +393,21 @@ def install_swiftpm(prefix, args): runtime_lib_dest = os.path.join(prefix, "lib", "swift", "pm") runtime_lib_src = os.path.join(args.bootstrap_dir, "pm") - for runtime in ["4", "4_2"]: - files_to_install = ["libPackageDescription" + g_shared_lib_ext] - if platform.system() == 'Darwin': - files_to_install.append("PackageDescription.swiftinterface") - else: - files_to_install.append("PackageDescription.swiftmodule") - files_to_install.append("PackageDescription.swiftdoc") + files_to_install = ["libPackageDescription" + g_shared_lib_ext] + if platform.system() == 'Darwin': + files_to_install.append("PackageDescription.swiftinterface") + else: + files_to_install.append("PackageDescription.swiftmodule") + files_to_install.append("PackageDescription.swiftdoc") - for file in files_to_install: - src = os.path.join(runtime_lib_src, runtime, file) - dest = os.path.join(runtime_lib_dest, runtime, file) - mkdir_p(os.path.dirname(dest)) + for file in files_to_install: + src = os.path.join(runtime_lib_src, "ManifestAPI", file) + dest = os.path.join(runtime_lib_dest, "ManifestAPI", file) + mkdir_p(os.path.dirname(dest)) - note("Installing %s to %s" % (src, dest)) + note("Installing %s to %s" % (src, dest)) - file_util.copy_file(src, dest, update=1) + file_util.copy_file(src, dest, update=1) files_to_install = ["libPackagePlugin" + g_shared_lib_ext] if platform.system() == 'Darwin': @@ -418,8 +417,8 @@ def install_swiftpm(prefix, args): files_to_install.append("PackagePlugin.swiftdoc") for file in files_to_install: - src = os.path.join(runtime_lib_src, file) - dest = os.path.join(runtime_lib_dest, file) + src = os.path.join(runtime_lib_src, "PluginAPI", file) + dest = os.path.join(runtime_lib_dest, "PluginAPI", file) mkdir_p(os.path.dirname(dest)) note("Installing %s to %s" % (src, dest))