Updated the Package file to handle support for non Apple platforms.

This commit is contained in:
Javier Cicchelli 2023-04-28 19:12:22 +02:00
parent 23020b10a7
commit f4abf84fd8

View File

@ -11,14 +11,86 @@
import PackageDescription
private var excludePlatforms: [String] = [.PlatformFolder.iOS]
// MARK: - Variables
#if os(iOS)
excludePlatforms = []
private var targetsLibrary: [String] = [
.Target.communications,
.Target.coordination,
.Target.core,
.Target.dependencies,
]
private var targetsPackage: [Target] = [
.target(
name: .Target.communications,
dependencies: []
),
.target(
name: .Target.coordination,
dependencies: []
),
.target(
name: .Target.core,
dependencies: []
),
.target(
name: .Target.dependencies,
dependencies: []
),
.testTarget(
name: "CommunicationsTests",
dependencies: [
.init(stringLiteral: .Target.communications)
],
path: "Tests/Communications"
),
.testTarget(
name: "CoordinationTests",
dependencies: [
.init(stringLiteral: .Target.coordination)
],
path: "Tests/Coordination"
),
.testTarget(
name: "CoreTests",
dependencies: [
.init(stringLiteral: .Target.core)
],
path: "Tests/Core"
),
.testTarget(
name: "DependenciesTests",
dependencies: [
.init(stringLiteral: .Target.dependencies)
],
path: "Tests/Dependencies"
),
]
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
targetsLibrary.append(.Target.persistence)
targetsPackage.append(contentsOf: [
.target(
name: .Target.persistence,
dependencies: []
),
.testTarget(
name: "PersistenceTests",
dependencies: [
.init(stringLiteral: .Target.persistence)
],
path: "Tests/Persistence",
resources: [
.process("Resources")
]
),
])
#endif
// MARK: - Package
let package = Package(
name: "SwiftLibs",
name: .Package.name,
platforms: [
.iOS(.v15),
.macOS(.v12),
@ -27,82 +99,26 @@ let package = Package(
],
products: [
.library(
name: "SwiftLibs",
targets: [
"Communications",
"Coordination",
"Core",
"Dependencies",
"Persistence"
]
name: .Package.name,
targets: targetsLibrary
),
],
dependencies: [],
targets: [
.target(
name: "Communications",
dependencies: []
),
.target(
name: "Coordination",
dependencies: [],
exclude: excludePlatforms
),
.target(
name: "Core",
dependencies: []
),
.target(
name: "Dependencies",
dependencies: []
),
.target(
name: "Persistence",
dependencies: []
),
.testTarget(
name: "CommunicationsTests",
dependencies: [
"Communications"
],
path: "Tests/Communications"
),
.testTarget(
name: "CoordinationTests",
dependencies: [
"Coordination"
],
path: "Tests/Coordination",
exclude: excludePlatforms
),
.testTarget(
name: "CoreTests",
dependencies: [
"Core"
],
path: "Tests/Core"
),
.testTarget(
name: "DependenciesTests",
dependencies: [
"Dependencies"
],
path: "Tests/Dependencies"
),
.testTarget(
name: "PersistenceTests",
dependencies: [
"Persistence"
],
path: "Tests/Persistence"
),
]
targets: targetsPackage
)
// MARK: - String+Constants
private extension String {
enum PlatformFolder {
static let iOS = "Platform/iOS"
enum Package {
static let name = "SwiftLibs"
}
enum Target {
static let communications = "Communications"
static let coordination = "Coordination"
static let core = "Core"
static let dependencies = "Dependencies"
static let persistence = "Persistence"
}
}