From f4abf84fd8d5c30f01bc8356fd61f71e397b8d2b Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Fri, 28 Apr 2023 19:12:22 +0200 Subject: [PATCH] Updated the Package file to handle support for non Apple platforms. --- Package.swift | 162 +++++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 73 deletions(-) diff --git a/Package.swift b/Package.swift index 2789210..f7c463c 100644 --- a/Package.swift +++ b/Package.swift @@ -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" } }