Switch to SwiftPM conditional dependencies API (#4003)

This API allows us to mostly remove `#if` conditionals which enables
cross compilation from macOS -> Linux. It also removes the thrashing of
Package.resolved if you compile in a docker image.
This commit is contained in:
Keith Smiley 2023-04-16 11:19:25 -07:00 committed by GitHub
parent 5aed7ce95c
commit 3ef44cf742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 24 deletions

View File

@ -9,6 +9,15 @@
"version" : "0.2.0" "version" : "0.2.0"
} }
}, },
{
"identity" : "cryptoswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
"state" : {
"revision" : "19b3c3ceed117c5cc883517c4e658548315ba70b",
"version" : "1.6.0"
}
},
{ {
"identity" : "sourcekitten", "identity" : "sourcekitten",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",

View File

@ -1,26 +1,6 @@
// swift-tools-version:5.7 // swift-tools-version:5.7
import PackageDescription import PackageDescription
#if os(macOS)
private let addCryptoSwift = false
private let binaryPlugin = true
#else
private let addCryptoSwift = true
private let binaryPlugin = false
#endif
let frameworkDependencies: [Target.Dependency] = [
.product(name: "IDEUtils", package: "swift-syntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
"SwiftyTextTable",
"Yams",
]
+ (addCryptoSwift ? ["CryptoSwift"] : [])
let package = Package( let package = Package(
name: "SwiftLint", name: "SwiftLint",
platforms: [.macOS(.v12)], platforms: [.macOS(.v12)],
@ -35,14 +15,16 @@ let package = Package(
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.34.1")), .package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.34.1")),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.5"), .package(url: "https://github.com/jpsim/Yams.git", from: "5.0.5"),
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"), .package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0") .package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0"),
] + (addCryptoSwift ? [.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.6.0"))] : []), .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.6.0"))
],
targets: [ targets: [
.plugin( .plugin(
name: "SwiftLintPlugin", name: "SwiftLintPlugin",
capability: .buildTool(), capability: .buildTool(),
dependencies: [ dependencies: [
.target(name: binaryPlugin ? "SwiftLintBinary" : "swiftlint") .target(name: "SwiftLintBinary", condition: .when(platforms: [.macOS])),
.target(name: "swiftlint", condition: .when(platforms: [.linux]))
] ]
), ),
.executableTarget( .executableTarget(
@ -62,7 +44,17 @@ let package = Package(
), ),
.target( .target(
name: "SwiftLintFramework", name: "SwiftLintFramework",
dependencies: frameworkDependencies dependencies: [
.product(name: "IDEUtils", package: "swift-syntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
"SwiftyTextTable",
"Yams",
.product(name: "CryptoSwift", package: "CryptoSwift", condition: .when(platforms: [.linux]))
]
), ),
.target( .target(
name: "SwiftLintTestHelpers", name: "SwiftLintTestHelpers",