From 4ea3252403f4a5042af1e08a0329a1d0aee67b84 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Fri, 15 Mar 2019 18:22:33 +0200 Subject: [PATCH 01/41] Implemented support for custom user types in configuration using type preserving coding adapter --- Package.swift | 20 +- Sources/Example/main.swift | 7 +- Sources/PackageConfig/Aliased.swift | 15 + Sources/PackageConfig/PackageConfig.swift | 332 +++++++++++++--------- 4 files changed, 223 insertions(+), 151 deletions(-) create mode 100644 Sources/PackageConfig/Aliased.swift diff --git a/Package.swift b/Package.swift index ffe0b04..ac5fc38 100644 --- a/Package.swift +++ b/Package.swift @@ -9,13 +9,15 @@ let package = Package( .library(name: "PackageConfig", type: .dynamic, targets: ["PackageConfig"]), .executable(name: "package-config-example", targets: ["Example"]) ], - dependencies: [], + dependencies: [ + .package(url: "https://github.com/IgorMuzyka/Type-Preserving-Coding-Adapter.git", .branch("master")), + ], targets: [ // The lib - .target(name: "PackageConfig", dependencies: []), + .target(name: "PackageConfig", dependencies: ["TypePreservingCodingAdapter"]), // The app I use to verify it all works - .target(name: "Example", dependencies: ["PackageConfig"]), + .target(name: "Example", dependencies: ["PackageConfig", "TypePreservingCodingAdapter"]), // Not used .testTarget(name: "PackageConfigTests", dependencies: ["PackageConfig"]), ] @@ -24,9 +26,13 @@ let package = Package( #if canImport(PackageConfig) import PackageConfig -let config = PackageConfig([ - "danger" : ["disable"], - "linter": ["rules": ["allowSomething"]] -]) +let config = PackageConfig( + configurations: [ + "example": ExampleConfiguration(value: "example configuration value") + ], + adapter: TypePreservingCodingAdapter() + .register(aliased: ExampleConfiguration.self) +) + #endif diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index 7e98d3d..270f778 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,5 +1,8 @@ import PackageConfig import Foundation +import TypePreservingCodingAdapter -let config = getPackageConfig() -print(config["linter"]) +let adapter = TypePreservingCodingAdapter().register(aliased: ExampleConfiguration.self) +let config = PackageConfig.load(adapter) + +print(config?[package: "example"]) diff --git a/Sources/PackageConfig/Aliased.swift b/Sources/PackageConfig/Aliased.swift new file mode 100644 index 0000000..3851f28 --- /dev/null +++ b/Sources/PackageConfig/Aliased.swift @@ -0,0 +1,15 @@ + +import Foundation +import TypePreservingCodingAdapter + +public protocol Aliased: Codable { + + static var alias: Alias { get } +} + +extension TypePreservingCodingAdapter { + + public func register(aliased type: T.Type) -> TypePreservingCodingAdapter { + return register(type: type).register(alias: T.alias, for: type) + } +} diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 37e9fa2..2b2d0d4 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -1,161 +1,209 @@ + import Foundation +@_exported import TypePreservingCodingAdapter -/// The public API for tools working with Swift Package Manager +/// A facade to decorate any configurations we might think of public struct PackageConfig { - public init(_ options: [String: Any]) { - let fileManager = FileManager.default - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" - let jsonData = try! JSONSerialization.data(withJSONObject: options, options: []) - - if !fileManager.createFile(atPath: packageConfigJSON, contents: jsonData, attributes: nil) { - // Couldn't write to tmpdir - print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") - } - } -} - -/// Only prints when --verbose is in the arge, or when DEBUG exists -func debugLog(_ message: String) -> Void { - let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) - if isVerbose { - print(message) - } -} - -/// Gets a config object from the user's Package.swift -/// by parsing the document by the same way that SwiftPM does it -/// - Returns: A dictionary of all settings -public func getPackageConfig() -> Dictionary { - let fileManager = FileManager.default - let swiftC = runXCRun(tool: "swiftc") - - var args = [String]() - args += ["--driver-mode=swift"] // Eval in swift mode, I think? - - args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib - args += getPackageConfigArgs() // This lib - - args += ["-suppress-warnings"] // SPM does that too - args += ["Package.swift"] // The Package.swift in the CWD - - // Create a process to eval the Swift Package manifest as a subprocess - let proc = Process() - proc.launchPath = swiftC - proc.arguments = args - - debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") - - let standardOutput = FileHandle.standardOutput - proc.standardOutput = standardOutput - proc.standardError = standardOutput - - // Evaluation of the package swift code will end up - // creating a file in the tmpdir that stores the JSON - // settings when a new instance of PackageConfig is created - proc.launch() - proc.waitUntilExit() + private let configurations: [String: Aliased] - debugLog("Finished launching swiftc") + public init(configurations: [String: Aliased], adapter: TypePreservingCodingAdapter) { + self.configurations = configurations + write(adapter: adapter) + } - // So read it - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" - guard let jsonData = fileManager.contents(atPath: packageConfigJSON) else { - // Package Manifest did not contain a config object at all - // so just return an empty dictionary - debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") - return [:] - } + /// Loads the Configuration if capable + public static func load(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { + return read(adapter: adapter) + } - debugLog("Got \(String(describing: String(data: jsonData, encoding: .utf8)))") - return try! JSONSerialization.jsonObject(with: jsonData) as! Dictionary + /// Provides a specific package configuation by packageName + public subscript(package packageName: String) -> Aliased? { + get { + return configurations[packageName] + } + } } -/// Helper to run xcrun to get paths for things -func runXCRun(tool: String) -> String { - let proc = Process() - proc.launchPath = "/usr/bin/xcrun" - proc.arguments = ["--find", tool] +/// Just an example configuration to test against +public struct ExampleConfiguration: Aliased { - debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") + let value: String - let pipe = Pipe() - proc.standardOutput = pipe + public init(value: String) { + self.value = value + } - proc.launch() - proc.waitUntilExit() - - let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) -} - -/// Finds args for the locally built copy of PackageConfig -func getPackageConfigArgs() -> [String] { - guard let libPackageConfig = getLibPackageConfigPath() else { - print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") - exit(1) - } - return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] + public static var alias: Alias = "ExampleConfiguration" } -// Finds args for the current version of Xcode's Swift Package Manager -func getSwiftPMManifestArgs(swiftPath: String) -> [String] { - // using "xcrun --find swift" we get - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc - // we need to transform it to something like: - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 - let fileManager = FileManager.default - - let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") - let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) - // TODO: Handle the - // // swift-tools-version:4.2 - // declarations? - let latestSPM = versions.sorted().last! - let libraryPathSPM = swiftPMDir + "/" + latestSPM - - debugLog("Using SPM version: \(libraryPathSPM)") - return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] +extension PackageConfig: Codable { + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + let keysAndValues = try container.decode([String: Wrap].self).map { package, wrap in + (package, wrap.wrapped as! Aliased) + } + self.configurations = [String: Aliased](uniqueKeysWithValues: keysAndValues) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + let wraps = [String: Wrap](uniqueKeysWithValues: configurations.map { (package, configuration) in + (package, Wrap(wrapped: configuration, strategy: .alias)) + }) + try container.encode(wraps) + } } +extension PackageConfig { -/// Finds a path to add at runtime to the compiler, which links -/// to the library which ships with Swift PM -func getLibPackageDescriptionPath() -> String? { - let fileManager = FileManager.default + func write(adapter: TypePreservingCodingAdapter) { + let fileManager = FileManager.default + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" + let encoder = JSONEncoder() + encoder.userInfo[.typePreservingAdapter] = adapter + let data = try! encoder.encode(self) - // Check and find where we can link to libDanger from - let libPaths = [ - "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2", // Xcode - ] - - func isThePackageLibPath(path: String) -> Bool { - return fileManager.fileExists(atPath: path + "/libPackageDescription.dylib") || // OSX - fileManager.fileExists(atPath: path + "/libPackageDescription.so") // Linux - } - - return libPaths.first(where: isThePackageLibPath) + if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { + print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") + } + } + + /// Only prints when --verbose is in the arge, or when DEBUG exists + static func debugLog(_ message: String) -> Void { + let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) + if isVerbose { + print(message) + } + } + + /// Gets a config object from the user's Package.swift + /// by parsing the document by the same way that SwiftPM does it + /// - Returns: A dictionary of all settings + static func read(adapter: TypePreservingCodingAdapter) -> PackageConfig? { + let fileManager = FileManager.default + let swiftC = runXCRun(tool: "swiftc") + + var args = [String]() + args += ["--driver-mode=swift"] // Eval in swift mode, I think? + + args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib + args += getPackageConfigArgs() // This lib + + args += ["-suppress-warnings"] // SPM does that too + args += ["Package.swift"] // The Package.swift in the CWD + + // Create a process to eval the Swift Package manifest as a subprocess + let proc = Process() + proc.launchPath = swiftC + proc.arguments = args + + debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") + + let standardOutput = FileHandle.standardOutput + proc.standardOutput = standardOutput + proc.standardError = standardOutput + + // Evaluation of the package swift code will end up + // creating a file in the tmpdir that stores the JSON + // settings when a new instance of PackageConfig is created + + proc.launch() + proc.waitUntilExit() + + debugLog("Finished launching swiftc") + + // So read it + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" + + print("path") + + guard let data = fileManager.contents(atPath: packageConfigJSON) else { + // Package Manifest did not contain a config object at all + // so just return an empty dictionary + debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") + return nil + } + + debugLog("Got \(String(describing: String(data: data, encoding: .utf8)))") + + let decoder = JSONDecoder() + decoder.userInfo[.typePreservingAdapter] = adapter + + return try! decoder.decode(PackageConfig.self, from: data) + } + + /// Helper to run xcrun to get paths for things + static func runXCRun(tool: String) -> String { + let proc = Process() + proc.launchPath = "/usr/bin/xcrun" + proc.arguments = ["--find", tool] + + debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") + + let pipe = Pipe() + proc.standardOutput = pipe + + proc.launch() + proc.waitUntilExit() + + let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! + return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) + } + + // Finds args for the current version of Xcode's Swift Package Manager + static func getSwiftPMManifestArgs(swiftPath: String) -> [String] { + // using "xcrun --find swift" we get + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc + // we need to transform it to something like: + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 + let fileManager = FileManager.default + + let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") + let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) + // TODO: Handle the + // // swift-tools-version:4.2 + // declarations? + let latestSPM = versions.sorted().last! + let libraryPathSPM = swiftPMDir + "/" + latestSPM + + debugLog("Using SPM version: \(libraryPathSPM)") + return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] + } + + /// Finds a path to add at runtime to the compiler, which links + /// to the library Danger + static func getLibPackageConfigPath() -> String? { + let fileManager = FileManager.default + + // Check and find where we can link to libDanger from + let libPaths = [ + ".build/debug", // Working in Xcode / CLI + ".build/x86_64-unknown-linux/debug", // Danger Swift's CI + ".build/release", // Testing prod + ] + + func isTheDangerLibPath(path: String) -> Bool { + return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX + fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux + } + + return libPaths.first(where: { + print($0) + return isTheDangerLibPath(path: $0) + }) + } + + + /// Finds args for the locally built copy of PackageConfig + static func getPackageConfigArgs() -> [String] { + guard let libPackageConfig = getLibPackageConfigPath() else { + print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") + exit(1) + } + return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] + } } - -/// Finds a path to add at runtime to the compiler, which links -/// to the library Danger -func getLibPackageConfigPath() -> String? { - let fileManager = FileManager.default - - // Check and find where we can link to libDanger from - let libPaths = [ - ".build/debug", // Working in Xcode / CLI - ".build/x86_64-unknown-linux/debug", // Danger Swift's CI - ".build/release", // Testing prod - ] - - func isTheDangerLibPath(path: String) -> Bool { - return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX - fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux - } - - return libPaths.first(where: isTheDangerLibPath) -} - From e6681df0eb7d93b25bf0df51d2d5b9f00b827abb Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 12:40:55 +0200 Subject: [PATCH 02/41] Updated README.md --- PackageConfig.xcodeproj/project.pbxproj | 505 +++++++++++++----- .../xcschemes/PackageConfig-Package.xcscheme | 18 +- README.md | 30 +- 3 files changed, 409 insertions(+), 144 deletions(-) diff --git a/PackageConfig.xcodeproj/project.pbxproj b/PackageConfig.xcodeproj/project.pbxproj index be3a9a0..0e5deb4 100644 --- a/PackageConfig.xcodeproj/project.pbxproj +++ b/PackageConfig.xcodeproj/project.pbxproj @@ -9,22 +9,22 @@ /* Begin PBXAggregateTarget section */ "PackageConfig::PackageConfigPackageTests::ProductTarget" /* PackageConfigPackageTests */ = { isa = PBXAggregateTarget; - buildConfigurationList = OBJ_43 /* Build configuration list for PBXAggregateTarget "PackageConfigPackageTests" */; + buildConfigurationList = OBJ_58 /* Build configuration list for PBXAggregateTarget "PackageConfigPackageTests" */; buildPhases = ( ); dependencies = ( - OBJ_46 /* PBXTargetDependency */, + OBJ_61 /* PBXTargetDependency */, ); name = PackageConfigPackageTests; productName = PackageConfigPackageTests; }; "PackageConfig::package-config-example::ProductTarget" /* package-config-example */ = { isa = PBXAggregateTarget; - buildConfigurationList = OBJ_58 /* Build configuration list for PBXAggregateTarget "package-config-example" */; + buildConfigurationList = OBJ_92 /* Build configuration list for PBXAggregateTarget "package-config-example" */; buildPhases = ( ); dependencies = ( - OBJ_61 /* PBXTargetDependency */, + OBJ_95 /* PBXTargetDependency */, ); name = "package-config-example"; productName = "package-config-example"; @@ -32,77 +32,143 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ - OBJ_25 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* main.swift */; }; - OBJ_27 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; - OBJ_34 /* PackageConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* PackageConfig.swift */; }; - OBJ_41 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_6 /* Package.swift */; }; - OBJ_52 /* PackageConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* PackageConfigTests.swift */; }; - OBJ_53 /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_15 /* XCTestManifests.swift */; }; - OBJ_55 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; + 789A035E223BDC8D00007369 /* Aliased.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789A035D223BDC8D00007369 /* Aliased.swift */; }; + 789A0360223BDCB700007369 /* PackageConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789A035F223BDCB700007369 /* PackageConfig.swift */; }; + OBJ_35 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* main.swift */; }; + OBJ_37 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; + OBJ_38 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; + OBJ_49 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; + OBJ_56 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_6 /* Package.swift */; }; + OBJ_67 /* PackageConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* PackageConfigTests.swift */; }; + OBJ_68 /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_15 /* XCTestManifests.swift */; }; + OBJ_70 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; + OBJ_71 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; + OBJ_78 /* Alias.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_19 /* Alias.swift */; }; + OBJ_79 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_20 /* Convenience.swift */; }; + OBJ_80 /* Signature.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_21 /* Signature.swift */; }; + OBJ_81 /* TypePreservingCodingAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_22 /* TypePreservingCodingAdapter.swift */; }; + OBJ_82 /* TypePreservingCodingAdapterError.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_23 /* TypePreservingCodingAdapterError.swift */; }; + OBJ_83 /* Wrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_24 /* Wrap.swift */; }; + OBJ_90 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_18 /* Package.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 3A98600B218F38350009C71A /* PBXContainerItemProxy */ = { + 789A0356223BD31100007369 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = OBJ_1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = "TypePreservingCodingAdapter::TypePreservingCodingAdapter"; + remoteInfo = TypePreservingCodingAdapter; + }; + 789A0357223BD31100007369 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = OBJ_1 /* Project object */; proxyType = 1; remoteGlobalIDString = "PackageConfig::PackageConfig"; remoteInfo = PackageConfig; }; - 3A98600C218F38350009C71A /* PBXContainerItemProxy */ = { + 789A0358223BD31100007369 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = OBJ_1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = "TypePreservingCodingAdapter::TypePreservingCodingAdapter"; + remoteInfo = TypePreservingCodingAdapter; + }; + 789A0359223BD31100007369 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = OBJ_1 /* Project object */; proxyType = 1; remoteGlobalIDString = "PackageConfig::PackageConfig"; remoteInfo = PackageConfig; }; + 789A035A223BD31100007369 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = OBJ_1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = "TypePreservingCodingAdapter::TypePreservingCodingAdapter"; + remoteInfo = TypePreservingCodingAdapter; + }; + 789A035B223BD31200007369 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = OBJ_1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = "PackageConfig::PackageConfigTests"; + remoteInfo = PackageConfigTests; + }; + 789A035C223BD31200007369 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = OBJ_1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = "PackageConfig::Example"; + remoteInfo = Example; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - OBJ_11 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 789A035D223BDC8D00007369 /* Aliased.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Aliased.swift; sourceTree = ""; }; + 789A035F223BDCB700007369 /* PackageConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfig.swift; sourceTree = ""; }; OBJ_14 /* PackageConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfigTests.swift; sourceTree = ""; }; OBJ_15 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = ""; }; + OBJ_18 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; name = Package.swift; path = "/Users/igor/development/libraries/PackageConfig/.build/checkouts/Type-Preserving-Coding-Adapter.git--4237871635319230087/Package.swift"; sourceTree = ""; }; + OBJ_19 /* Alias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alias.swift; sourceTree = ""; }; + OBJ_20 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; + OBJ_21 /* Signature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signature.swift; sourceTree = ""; }; + OBJ_22 /* TypePreservingCodingAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypePreservingCodingAdapter.swift; sourceTree = ""; }; + OBJ_23 /* TypePreservingCodingAdapterError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypePreservingCodingAdapterError.swift; sourceTree = ""; }; + OBJ_24 /* Wrap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wrap.swift; sourceTree = ""; }; OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; - OBJ_9 /* PackageConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfig.swift; sourceTree = ""; }; + OBJ_9 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; "PackageConfig::Example::Product" /* Example */ = {isa = PBXFileReference; lastKnownFileType = text; path = Example; sourceTree = BUILT_PRODUCTS_DIR; }; "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = PackageConfig.framework; sourceTree = BUILT_PRODUCTS_DIR; }; "PackageConfig::PackageConfigTests::Product" /* PackageConfigTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = PackageConfigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = TypePreservingCodingAdapter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - OBJ_26 /* Frameworks */ = { + OBJ_36 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 0; files = ( - OBJ_27 /* PackageConfig.framework in Frameworks */, + OBJ_37 /* PackageConfig.framework in Frameworks */, + OBJ_38 /* TypePreservingCodingAdapter.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; - OBJ_35 /* Frameworks */ = { + OBJ_48 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 0; files = ( + OBJ_49 /* TypePreservingCodingAdapter.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; - OBJ_54 /* Frameworks */ = { + OBJ_69 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 0; + files = ( + OBJ_70 /* PackageConfig.framework in Frameworks */, + OBJ_71 /* TypePreservingCodingAdapter.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + OBJ_84 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 0; files = ( - OBJ_55 /* PackageConfig.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - OBJ_10 /* Example */ = { + OBJ_10 /* PackageConfig */ = { isa = PBXGroup; children = ( - OBJ_11 /* main.swift */, + 789A035D223BDC8D00007369 /* Aliased.swift */, + 789A035F223BDCB700007369 /* PackageConfig.swift */, ); - name = Example; - path = Sources/Example; + name = PackageConfig; + path = Sources/PackageConfig; sourceTree = SOURCE_ROOT; }; OBJ_12 /* Tests */ = { @@ -123,12 +189,36 @@ path = Tests/PackageConfigTests; sourceTree = SOURCE_ROOT; }; - OBJ_16 /* Products */ = { + OBJ_16 /* Dependencies */ = { + isa = PBXGroup; + children = ( + OBJ_17 /* TypePreservingCodingAdapter */, + ); + name = Dependencies; + sourceTree = ""; + }; + OBJ_17 /* TypePreservingCodingAdapter */ = { + isa = PBXGroup; + children = ( + OBJ_18 /* Package.swift */, + OBJ_19 /* Alias.swift */, + OBJ_20 /* Convenience.swift */, + OBJ_21 /* Signature.swift */, + OBJ_22 /* TypePreservingCodingAdapter.swift */, + OBJ_23 /* TypePreservingCodingAdapterError.swift */, + OBJ_24 /* Wrap.swift */, + ); + name = TypePreservingCodingAdapter; + path = ".build/checkouts/Type-Preserving-Coding-Adapter.git--4237871635319230087/Sources"; + sourceTree = SOURCE_ROOT; + }; + OBJ_25 /* Products */ = { isa = PBXGroup; children = ( - "PackageConfig::Example::Product" /* Example */, - "PackageConfig::PackageConfigTests::Product" /* PackageConfigTests.xctest */, "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */, + "PackageConfig::PackageConfigTests::Product" /* PackageConfigTests.xctest */, + "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */, + "PackageConfig::Example::Product" /* Example */, ); name = Products; sourceTree = BUILT_PRODUCTS_DIR; @@ -139,7 +229,8 @@ OBJ_6 /* Package.swift */, OBJ_7 /* Sources */, OBJ_12 /* Tests */, - OBJ_16 /* Products */, + OBJ_16 /* Dependencies */, + OBJ_25 /* Products */, ); name = ""; sourceTree = ""; @@ -147,19 +238,19 @@ OBJ_7 /* Sources */ = { isa = PBXGroup; children = ( - OBJ_8 /* PackageConfig */, - OBJ_10 /* Example */, + OBJ_8 /* Example */, + OBJ_10 /* PackageConfig */, ); name = Sources; sourceTree = SOURCE_ROOT; }; - OBJ_8 /* PackageConfig */ = { + OBJ_8 /* Example */ = { isa = PBXGroup; children = ( - OBJ_9 /* PackageConfig.swift */, + OBJ_9 /* main.swift */, ); - name = PackageConfig; - path = Sources/PackageConfig; + name = Example; + path = Sources/Example; sourceTree = SOURCE_ROOT; }; /* End PBXGroup section */ @@ -167,15 +258,16 @@ /* Begin PBXNativeTarget section */ "PackageConfig::Example" /* Example */ = { isa = PBXNativeTarget; - buildConfigurationList = OBJ_21 /* Build configuration list for PBXNativeTarget "Example" */; + buildConfigurationList = OBJ_31 /* Build configuration list for PBXNativeTarget "Example" */; buildPhases = ( - OBJ_24 /* Sources */, - OBJ_26 /* Frameworks */, + OBJ_34 /* Sources */, + OBJ_36 /* Frameworks */, ); buildRules = ( ); dependencies = ( - OBJ_28 /* PBXTargetDependency */, + OBJ_39 /* PBXTargetDependency */, + OBJ_41 /* PBXTargetDependency */, ); name = Example; productName = Example; @@ -184,14 +276,15 @@ }; "PackageConfig::PackageConfig" /* PackageConfig */ = { isa = PBXNativeTarget; - buildConfigurationList = OBJ_30 /* Build configuration list for PBXNativeTarget "PackageConfig" */; + buildConfigurationList = OBJ_43 /* Build configuration list for PBXNativeTarget "PackageConfig" */; buildPhases = ( - OBJ_33 /* Sources */, - OBJ_35 /* Frameworks */, + OBJ_46 /* Sources */, + OBJ_48 /* Frameworks */, ); buildRules = ( ); dependencies = ( + OBJ_50 /* PBXTargetDependency */, ); name = PackageConfig; productName = PackageConfig; @@ -200,15 +293,16 @@ }; "PackageConfig::PackageConfigTests" /* PackageConfigTests */ = { isa = PBXNativeTarget; - buildConfigurationList = OBJ_48 /* Build configuration list for PBXNativeTarget "PackageConfigTests" */; + buildConfigurationList = OBJ_63 /* Build configuration list for PBXNativeTarget "PackageConfigTests" */; buildPhases = ( - OBJ_51 /* Sources */, - OBJ_54 /* Frameworks */, + OBJ_66 /* Sources */, + OBJ_69 /* Frameworks */, ); buildRules = ( ); dependencies = ( - OBJ_56 /* PBXTargetDependency */, + OBJ_72 /* PBXTargetDependency */, + OBJ_73 /* PBXTargetDependency */, ); name = PackageConfigTests; productName = PackageConfigTests; @@ -217,9 +311,9 @@ }; "PackageConfig::SwiftPMPackageDescription" /* PackageConfigPackageDescription */ = { isa = PBXNativeTarget; - buildConfigurationList = OBJ_37 /* Build configuration list for PBXNativeTarget "PackageConfigPackageDescription" */; + buildConfigurationList = OBJ_52 /* Build configuration list for PBXNativeTarget "PackageConfigPackageDescription" */; buildPhases = ( - OBJ_40 /* Sources */, + OBJ_55 /* Sources */, ); buildRules = ( ); @@ -229,6 +323,36 @@ productName = PackageConfigPackageDescription; productType = "com.apple.product-type.framework"; }; + "TypePreservingCodingAdapter::SwiftPMPackageDescription" /* TypePreservingCodingAdapterPackageDescription */ = { + isa = PBXNativeTarget; + buildConfigurationList = OBJ_86 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapterPackageDescription" */; + buildPhases = ( + OBJ_89 /* Sources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = TypePreservingCodingAdapterPackageDescription; + productName = TypePreservingCodingAdapterPackageDescription; + productType = "com.apple.product-type.framework"; + }; + "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */ = { + isa = PBXNativeTarget; + buildConfigurationList = OBJ_74 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapter" */; + buildPhases = ( + OBJ_77 /* Sources */, + OBJ_84 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = TypePreservingCodingAdapter; + productName = TypePreservingCodingAdapter; + productReference = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; + productType = "com.apple.product-type.framework"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -245,7 +369,7 @@ en, ); mainGroup = OBJ_5 /* */; - productRefGroup = OBJ_16 /* Products */; + productRefGroup = OBJ_25 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( @@ -254,72 +378,137 @@ "PackageConfig::SwiftPMPackageDescription" /* PackageConfigPackageDescription */, "PackageConfig::PackageConfigPackageTests::ProductTarget" /* PackageConfigPackageTests */, "PackageConfig::PackageConfigTests" /* PackageConfigTests */, + "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */, + "TypePreservingCodingAdapter::SwiftPMPackageDescription" /* TypePreservingCodingAdapterPackageDescription */, "PackageConfig::package-config-example::ProductTarget" /* package-config-example */, ); }; /* End PBXProject section */ /* Begin PBXSourcesBuildPhase section */ - OBJ_24 /* Sources */ = { + OBJ_34 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 0; + files = ( + OBJ_35 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + OBJ_46 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 0; + files = ( + 789A0360223BDCB700007369 /* PackageConfig.swift in Sources */, + 789A035E223BDC8D00007369 /* Aliased.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + OBJ_55 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( - OBJ_25 /* main.swift in Sources */, + OBJ_56 /* Package.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - OBJ_33 /* Sources */ = { + OBJ_66 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( - OBJ_34 /* PackageConfig.swift in Sources */, + OBJ_67 /* PackageConfigTests.swift in Sources */, + OBJ_68 /* XCTestManifests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - OBJ_40 /* Sources */ = { + OBJ_77 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( - OBJ_41 /* Package.swift in Sources */, + OBJ_78 /* Alias.swift in Sources */, + OBJ_79 /* Convenience.swift in Sources */, + OBJ_80 /* Signature.swift in Sources */, + OBJ_81 /* TypePreservingCodingAdapter.swift in Sources */, + OBJ_82 /* TypePreservingCodingAdapterError.swift in Sources */, + OBJ_83 /* Wrap.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - OBJ_51 /* Sources */ = { + OBJ_89 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( - OBJ_52 /* PackageConfigTests.swift in Sources */, - OBJ_53 /* XCTestManifests.swift in Sources */, + OBJ_90 /* Package.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - OBJ_28 /* PBXTargetDependency */ = { + OBJ_39 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = "PackageConfig::PackageConfig" /* PackageConfig */; - targetProxy = 3A98600B218F38350009C71A /* PBXContainerItemProxy */; + targetProxy = 789A0357223BD31100007369 /* PBXContainerItemProxy */; }; - OBJ_46 /* PBXTargetDependency */ = { + OBJ_41 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = "PackageConfig::PackageConfigTests" /* PackageConfigTests */; - targetProxy = "PackageConfig::PackageConfigTests" /* PackageConfigTests */; + target = "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */; + targetProxy = 789A0358223BD31100007369 /* PBXContainerItemProxy */; }; - OBJ_56 /* PBXTargetDependency */ = { + OBJ_50 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = "PackageConfig::PackageConfig" /* PackageConfig */; - targetProxy = 3A98600C218F38350009C71A /* PBXContainerItemProxy */; + target = "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */; + targetProxy = 789A0356223BD31100007369 /* PBXContainerItemProxy */; }; OBJ_61 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = "PackageConfig::PackageConfigTests" /* PackageConfigTests */; + targetProxy = 789A035B223BD31200007369 /* PBXContainerItemProxy */; + }; + OBJ_72 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = "PackageConfig::PackageConfig" /* PackageConfig */; - targetProxy = "PackageConfig::PackageConfig" /* PackageConfig */; + targetProxy = 789A0359223BD31100007369 /* PBXContainerItemProxy */; + }; + OBJ_73 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */; + targetProxy = 789A035A223BD31100007369 /* PBXContainerItemProxy */; + }; + OBJ_95 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = "PackageConfig::Example" /* Example */; + targetProxy = 789A035C223BD31200007369 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ - OBJ_22 /* Debug */ = { + OBJ_3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_NS_ASSERTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + MACOSX_DEPLOYMENT_TARGET = 10.10; + ONLY_ACTIVE_ARCH = YES; + OTHER_SWIFT_FLAGS = "-DXcode"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "SWIFT_PACKAGE DEBUG"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + USE_HEADERMAP = NO; + }; + name = Debug; + }; + OBJ_32 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { FRAMEWORK_SEARCH_PATHS = ( @@ -340,7 +529,7 @@ }; name = Debug; }; - OBJ_23 /* Release */ = { + OBJ_33 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { FRAMEWORK_SEARCH_PATHS = ( @@ -361,33 +550,27 @@ }; name = Release; }; - OBJ_3 /* Debug */ = { + OBJ_4 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_NS_ASSERTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); + GCC_OPTIMIZATION_LEVEL = s; MACOSX_DEPLOYMENT_TARGET = 10.10; - ONLY_ACTIVE_ARCH = YES; OTHER_SWIFT_FLAGS = "-DXcode"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "SWIFT_PACKAGE DEBUG"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; USE_HEADERMAP = NO; }; - name = Debug; + name = Release; }; - OBJ_31 /* Debug */ = { + OBJ_44 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ENABLE_TESTABILITY = YES; @@ -411,7 +594,7 @@ }; name = Debug; }; - OBJ_32 /* Release */ = { + OBJ_45 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ENABLE_TESTABILITY = YES; @@ -435,7 +618,7 @@ }; name = Release; }; - OBJ_38 /* Debug */ = { + OBJ_53 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { LD = /usr/bin/true; @@ -444,7 +627,7 @@ }; name = Debug; }; - OBJ_39 /* Release */ = { + OBJ_54 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { LD = /usr/bin/true; @@ -453,39 +636,19 @@ }; name = Release; }; - OBJ_4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_OPTIMIZATION_LEVEL = s; - MACOSX_DEPLOYMENT_TARGET = 10.10; - OTHER_SWIFT_FLAGS = "-DXcode"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - USE_HEADERMAP = NO; - }; - name = Release; - }; - OBJ_44 /* Debug */ = { + OBJ_59 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { }; name = Debug; }; - OBJ_45 /* Release */ = { + OBJ_60 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { }; name = Release; }; - OBJ_49 /* Debug */ = { + OBJ_64 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; @@ -506,7 +669,7 @@ }; name = Debug; }; - OBJ_50 /* Release */ = { + OBJ_65 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; @@ -527,13 +690,79 @@ }; name = Release; }; - OBJ_59 /* Debug */ = { + OBJ_75 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks", + ); + HEADER_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = PackageConfig.xcodeproj/TypePreservingCodingAdapter_Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; + OTHER_CFLAGS = "$(inherited)"; + OTHER_LDFLAGS = "$(inherited)"; + OTHER_SWIFT_FLAGS = "$(inherited)"; + PRODUCT_BUNDLE_IDENTIFIER = TypePreservingCodingAdapter; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; + SWIFT_VERSION = 4.2; + TARGET_NAME = TypePreservingCodingAdapter; }; name = Debug; }; - OBJ_60 /* Release */ = { + OBJ_76 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks", + ); + HEADER_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = PackageConfig.xcodeproj/TypePreservingCodingAdapter_Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; + OTHER_CFLAGS = "$(inherited)"; + OTHER_LDFLAGS = "$(inherited)"; + OTHER_SWIFT_FLAGS = "$(inherited)"; + PRODUCT_BUNDLE_IDENTIFIER = TypePreservingCodingAdapter; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; + SWIFT_VERSION = 4.2; + TARGET_NAME = TypePreservingCodingAdapter; + }; + name = Release; + }; + OBJ_87 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + LD = /usr/bin/true; + OTHER_SWIFT_FLAGS = "-swift-version 4.2 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"; + SWIFT_VERSION = 4.2; + }; + name = Debug; + }; + OBJ_88 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + LD = /usr/bin/true; + OTHER_SWIFT_FLAGS = "-swift-version 4.2 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"; + SWIFT_VERSION = 4.2; + }; + name = Release; + }; + OBJ_93 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + OBJ_94 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { }; @@ -551,56 +780,74 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - OBJ_21 /* Build configuration list for PBXNativeTarget "Example" */ = { + OBJ_31 /* Build configuration list for PBXNativeTarget "Example" */ = { isa = XCConfigurationList; buildConfigurations = ( - OBJ_22 /* Debug */, - OBJ_23 /* Release */, + OBJ_32 /* Debug */, + OBJ_33 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - OBJ_30 /* Build configuration list for PBXNativeTarget "PackageConfig" */ = { + OBJ_43 /* Build configuration list for PBXNativeTarget "PackageConfig" */ = { isa = XCConfigurationList; buildConfigurations = ( - OBJ_31 /* Debug */, - OBJ_32 /* Release */, + OBJ_44 /* Debug */, + OBJ_45 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - OBJ_37 /* Build configuration list for PBXNativeTarget "PackageConfigPackageDescription" */ = { + OBJ_52 /* Build configuration list for PBXNativeTarget "PackageConfigPackageDescription" */ = { isa = XCConfigurationList; buildConfigurations = ( - OBJ_38 /* Debug */, - OBJ_39 /* Release */, + OBJ_53 /* Debug */, + OBJ_54 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - OBJ_43 /* Build configuration list for PBXAggregateTarget "PackageConfigPackageTests" */ = { + OBJ_58 /* Build configuration list for PBXAggregateTarget "PackageConfigPackageTests" */ = { isa = XCConfigurationList; buildConfigurations = ( - OBJ_44 /* Debug */, - OBJ_45 /* Release */, + OBJ_59 /* Debug */, + OBJ_60 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - OBJ_48 /* Build configuration list for PBXNativeTarget "PackageConfigTests" */ = { + OBJ_63 /* Build configuration list for PBXNativeTarget "PackageConfigTests" */ = { isa = XCConfigurationList; buildConfigurations = ( - OBJ_49 /* Debug */, - OBJ_50 /* Release */, + OBJ_64 /* Debug */, + OBJ_65 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - OBJ_58 /* Build configuration list for PBXAggregateTarget "package-config-example" */ = { + OBJ_74 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapter" */ = { isa = XCConfigurationList; buildConfigurations = ( - OBJ_59 /* Debug */, - OBJ_60 /* Release */, + OBJ_75 /* Debug */, + OBJ_76 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + OBJ_86 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapterPackageDescription" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + OBJ_87 /* Debug */, + OBJ_88 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + OBJ_92 /* Build configuration list for PBXAggregateTarget "package-config-example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + OBJ_93 /* Debug */, + OBJ_94 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme b/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme index 8a06f84..2dbd03a 100644 --- a/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme +++ b/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "YES"> @@ -28,9 +28,9 @@ buildForAnalyzing = "YES"> @@ -69,9 +69,9 @@ diff --git a/README.md b/README.md index 06f95ee..420e0f8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ settings. ```swift // swift-tools-version:4.0 import PackageDescription +import YourPackage // Traditional Package.swift @@ -20,13 +21,18 @@ let package = Package( // Config lives under the package -#if canImport(PackageConfig) +#if canImport(PackageConfig) && canImport(YourPackage) import PackageConfig +import YourPackage -let config = PackageConfig([ - "danger" : ["disable"], - "linter": ["rules": ["allowSomething"]] -]) +let adapter = TypePreservingCodingAdapter() +let config = PackageConfig( + configurations: [ + "yourPackageName": YourPackageConfig(info: ["this", "and", "that", "whatever"]), + ], + adapter: TypePreservingCodingAdapter() + .register(aliase: YourPackageConfig.self) +) #endif ``` @@ -60,7 +66,19 @@ Then in your app, you can grab the config via the exposed function `getPackageCo ```swift import PackageConfig -let config = getPackageConfig() +public struct YourPackageConfig: Aliased { + + public let info: [String] + + public static var alias: Alias = "YourPackageConfig" + + public init(info: [String]) { + self.info = info + } +} + +let adapter = TypePreservingCodingAdapter().register(aliased: YourPackageConfig.self) +let config = PackageConfig.load(adapter) print(config["linter"]) ``` From f941fe9715a7893c3eb30dc0bf8752a3ba04c74b Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 13:49:02 +0200 Subject: [PATCH 03/41] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 420e0f8..05e7d36 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Then in your app, you can grab the config via the exposed function `getPackageCo ```swift import PackageConfig -public struct YourPackageConfig: Aliased { +public struct YourPackageConfig: Aliased { // just an example, it can be watever you want as long as it's codable public let info: [String] From ff21fffdc100937092f36f4c5762ff78fc616c45 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 14:15:43 +0200 Subject: [PATCH 04/41] minor changes --- README.md | 4 +--- Sources/PackageConfig/PackageConfig.swift | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 05e7d36..90de09b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # PackageConfig -A Swift Package that allows you to define configuration settings inside a `Package.swift` - this is so that tools -can all keep their configs consolidated inside a single place. Tool builders use this dependency to grab their config -settings. +A Swift Package that allows you to define configuration settings inside a `Package.swift` - this is so that tools can all keep their configs consolidated inside a single place. Tool builders use this dependency to grab their config settings. ### User writes: diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 2b2d0d4..2614d2b 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -119,7 +119,7 @@ extension PackageConfig { let path = NSTemporaryDirectory() let packageConfigJSON = path + "package-config.json" - print("path") + print(path) guard let data = fileManager.contents(atPath: packageConfigJSON) else { // Package Manifest did not contain a config object at all From 7dc56a620ec2ee206ff4470830912afd0d011710 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 14:36:59 +0200 Subject: [PATCH 05/41] Added PackageName type to allow for strict configuration keys for packages --- Package.swift | 3 +-- Sources/Example/main.swift | 2 +- .../PackageConfig/ExampleConfiguration.swift | 17 +++++++++++++ Sources/PackageConfig/PackageConfig.swift | 24 +++++------------- Sources/PackageConfig/PackageName.swift | 25 +++++++++++++++++++ 5 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 Sources/PackageConfig/ExampleConfiguration.swift create mode 100644 Sources/PackageConfig/PackageName.swift diff --git a/Package.swift b/Package.swift index ac5fc38..f2b8897 100644 --- a/Package.swift +++ b/Package.swift @@ -28,11 +28,10 @@ import PackageConfig let config = PackageConfig( configurations: [ - "example": ExampleConfiguration(value: "example configuration value") + .example: ExampleConfiguration(value: "example configuration value") ], adapter: TypePreservingCodingAdapter() .register(aliased: ExampleConfiguration.self) ) - #endif diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index 270f778..dc31df1 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -5,4 +5,4 @@ import TypePreservingCodingAdapter let adapter = TypePreservingCodingAdapter().register(aliased: ExampleConfiguration.self) let config = PackageConfig.load(adapter) -print(config?[package: "example"]) +print(config?[package: .example]) diff --git a/Sources/PackageConfig/ExampleConfiguration.swift b/Sources/PackageConfig/ExampleConfiguration.swift new file mode 100644 index 0000000..1b17ae8 --- /dev/null +++ b/Sources/PackageConfig/ExampleConfiguration.swift @@ -0,0 +1,17 @@ + +/// Just an example configuration to test against +public struct ExampleConfiguration: Aliased { + + let value: String + + public init(value: String) { + self.value = value + } + + public static var alias: Alias = "ExampleConfiguration" +} + +extension PackageName { + + public static var example: PackageName = "ExampleConfiguration" +} diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 2614d2b..8ac65f2 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -5,9 +5,9 @@ import Foundation /// A facade to decorate any configurations we might think of public struct PackageConfig { - private let configurations: [String: Aliased] + private let configurations: [PackageName: Aliased] - public init(configurations: [String: Aliased], adapter: TypePreservingCodingAdapter) { + public init(configurations: [PackageName: Aliased], adapter: TypePreservingCodingAdapter) { self.configurations = configurations write(adapter: adapter) } @@ -18,38 +18,26 @@ public struct PackageConfig { } /// Provides a specific package configuation by packageName - public subscript(package packageName: String) -> Aliased? { + public subscript(package packageName: PackageName) -> Aliased? { get { return configurations[packageName] } } } -/// Just an example configuration to test against -public struct ExampleConfiguration: Aliased { - - let value: String - - public init(value: String) { - self.value = value - } - - public static var alias: Alias = "ExampleConfiguration" -} - extension PackageConfig: Codable { public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() - let keysAndValues = try container.decode([String: Wrap].self).map { package, wrap in + let keysAndValues = try container.decode([PackageName: Wrap].self).map { package, wrap in (package, wrap.wrapped as! Aliased) } - self.configurations = [String: Aliased](uniqueKeysWithValues: keysAndValues) + self.configurations = [PackageName: Aliased](uniqueKeysWithValues: keysAndValues) } public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() - let wraps = [String: Wrap](uniqueKeysWithValues: configurations.map { (package, configuration) in + let wraps = [PackageName: Wrap](uniqueKeysWithValues: configurations.map { (package, configuration) in (package, Wrap(wrapped: configuration, strategy: .alias)) }) try container.encode(wraps) diff --git a/Sources/PackageConfig/PackageName.swift b/Sources/PackageConfig/PackageName.swift new file mode 100644 index 0000000..343ad79 --- /dev/null +++ b/Sources/PackageConfig/PackageName.swift @@ -0,0 +1,25 @@ + +public struct PackageName: ExpressibleByStringLiteral, Codable, Hashable, Equatable { + + public typealias StringLiteralType = String + + private let name: String + + public init(_ name: String) { + self.name = name + } + + public init(stringLiteral name: String) { + self.name = name + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.name = try container.decode(String.self) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(name) + } +} From 5ed88bf1ab6b8b4d7c3f30b2a006f286ef3eef21 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 14:41:12 +0200 Subject: [PATCH 06/41] Updated README.md --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 90de09b..c6eddce 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ import YourPackage let adapter = TypePreservingCodingAdapter() let config = PackageConfig( configurations: [ - "yourPackageName": YourPackageConfig(info: ["this", "and", "that", "whatever"]), + .yourPackageName: YourPackageConfig(info: ["this", "and", "that", "whatever"]), ], adapter: TypePreservingCodingAdapter() .register(aliase: YourPackageConfig.self) @@ -59,25 +59,30 @@ let package = Package( ) ``` -Then in your app, you can grab the config via the exposed function `getPackageConfig`. +To grab your configuration: ```swift import PackageConfig -public struct YourPackageConfig: Aliased { // just an example, it can be watever you want as long as it's codable +// just an example, it can be watever you want as long as it's Codable +public struct YourPackageConfig: Aliased { public let info: [String] - - public static var alias: Alias = "YourPackageConfig" + public static var alias: Alias = "YourPackageConfig" // alias to preserve type when coding public init(info: [String]) { self.info = info } } +extension PackageName { + // define your PackageName to make it possible to register the config by it in PackageConfig + public static var yourPackageName: PackageName = "YourPackageName" +} + let adapter = TypePreservingCodingAdapter().register(aliased: YourPackageConfig.self) let config = PackageConfig.load(adapter) -print(config["linter"]) +print(config?[package: .yourPackageName]) ``` This will be a simple dictionary where you can. From 0a40c609bd79b801ffd506673a7219f162ef06ca Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 14:55:24 +0200 Subject: [PATCH 07/41] Stabilised TypePreservingCodingAdapter version --- Package.swift | 2 +- PackageConfig.xcodeproj/project.pbxproj | 13 ++++++++++--- Sources/Example/main.swift | 10 ++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index f2b8897..2a166d3 100644 --- a/Package.swift +++ b/Package.swift @@ -10,7 +10,7 @@ let package = Package( .executable(name: "package-config-example", targets: ["Example"]) ], dependencies: [ - .package(url: "https://github.com/IgorMuzyka/Type-Preserving-Coding-Adapter.git", .branch("master")), + .package(url: "https://github.com/IgorMuzyka/Type-Preserving-Coding-Adapter.git", from: "1.0.0"), ], targets: [ // The lib diff --git a/PackageConfig.xcodeproj/project.pbxproj b/PackageConfig.xcodeproj/project.pbxproj index 0e5deb4..83a14b0 100644 --- a/PackageConfig.xcodeproj/project.pbxproj +++ b/PackageConfig.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ /* Begin PBXBuildFile section */ 789A035E223BDC8D00007369 /* Aliased.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789A035D223BDC8D00007369 /* Aliased.swift */; }; 789A0360223BDCB700007369 /* PackageConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789A035F223BDCB700007369 /* PackageConfig.swift */; }; + 78AB289F223D246B00B2296B /* PackageName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78AB289D223D237600B2296B /* PackageName.swift */; }; + 78AB28A1223D24A300B2296B /* ExampleConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78AB28A0223D24A300B2296B /* ExampleConfiguration.swift */; }; OBJ_35 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* main.swift */; }; OBJ_37 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; OBJ_38 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; @@ -107,6 +109,8 @@ /* Begin PBXFileReference section */ 789A035D223BDC8D00007369 /* Aliased.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Aliased.swift; sourceTree = ""; }; 789A035F223BDCB700007369 /* PackageConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfig.swift; sourceTree = ""; }; + 78AB289D223D237600B2296B /* PackageName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageName.swift; sourceTree = ""; }; + 78AB28A0223D24A300B2296B /* ExampleConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleConfiguration.swift; sourceTree = ""; }; OBJ_14 /* PackageConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfigTests.swift; sourceTree = ""; }; OBJ_15 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = ""; }; OBJ_18 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; name = Package.swift; path = "/Users/igor/development/libraries/PackageConfig/.build/checkouts/Type-Preserving-Coding-Adapter.git--4237871635319230087/Package.swift"; sourceTree = ""; }; @@ -166,6 +170,8 @@ children = ( 789A035D223BDC8D00007369 /* Aliased.swift */, 789A035F223BDCB700007369 /* PackageConfig.swift */, + 78AB289D223D237600B2296B /* PackageName.swift */, + 78AB28A0223D24A300B2296B /* ExampleConfiguration.swift */, ); name = PackageConfig; path = Sources/PackageConfig; @@ -223,7 +229,7 @@ name = Products; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_5 /* */ = { + OBJ_5 = { isa = PBXGroup; children = ( OBJ_6 /* Package.swift */, @@ -232,7 +238,6 @@ OBJ_16 /* Dependencies */, OBJ_25 /* Products */, ); - name = ""; sourceTree = ""; }; OBJ_7 /* Sources */ = { @@ -368,7 +373,7 @@ knownRegions = ( en, ); - mainGroup = OBJ_5 /* */; + mainGroup = OBJ_5; productRefGroup = OBJ_25 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -399,6 +404,8 @@ buildActionMask = 0; files = ( 789A0360223BDCB700007369 /* PackageConfig.swift in Sources */, + 78AB28A1223D24A300B2296B /* ExampleConfiguration.swift in Sources */, + 78AB289F223D246B00B2296B /* PackageName.swift in Sources */, 789A035E223BDC8D00007369 /* Aliased.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index dc31df1..308d558 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,8 +1,10 @@ + import PackageConfig -import Foundation -import TypePreservingCodingAdapter -let adapter = TypePreservingCodingAdapter().register(aliased: ExampleConfiguration.self) +let adapter = TypePreservingCodingAdapter() + .register(aliased: ExampleConfiguration.self) + let config = PackageConfig.load(adapter) +let exampleConfiguration = config?[package: .example] as? ExampleConfiguration -print(config?[package: .example]) +print(exampleConfiguration!) From 6dd2fba4968f24bfbc92e367db20705eec37c13b Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 15:10:57 +0200 Subject: [PATCH 08/41] Updated README.md --- README.md | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c6eddce..7370f2f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ A Swift Package that allows you to define configuration settings inside a `Packa ```swift // swift-tools-version:4.0 import PackageDescription -import YourPackage // Traditional Package.swift @@ -59,12 +58,14 @@ let package = Package( ) ``` -To grab your configuration: +Define your Configuration and extend PackageName with your package name: ```swift import PackageConfig -// just an example, it can be watever you want as long as it's Codable +// Define your config type. +// Just an example, it can be watever you want as long as it's `Codable`. +// It must conform to `Aliased` and provide an alias. public struct YourPackageConfig: Aliased { public let info: [String] @@ -75,17 +76,26 @@ public struct YourPackageConfig: Aliased { } } +// Define your `PackageName` to make it possible to register and get the config by it in PackageConfig. extension PackageName { - // define your PackageName to make it possible to register the config by it in PackageConfig + public static var yourPackageName: PackageName = "YourPackageName" } +``` -let adapter = TypePreservingCodingAdapter().register(aliased: YourPackageConfig.self) +To grab your configuration: + +```swift +import PackageConfig + +let adapter = TypePreservingCodingAdapter() + .register(aliased: YourPackageConfig.self) let config = PackageConfig.load(adapter) -print(config?[package: .yourPackageName]) -``` -This will be a simple dictionary where you can. +let yourConfig = config?[package: .yourPackageName] as? YourPackageConfig + +print(yourConfig) +``` ---- From b3f82d0fdd144d351ed88d884ff65955c9f12539 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 15:25:32 +0200 Subject: [PATCH 09/41] Simplifed specific library configuration loading even further --- Sources/Example/main.swift | 5 ++--- Sources/PackageConfig/PackageConfig.swift | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index 308d558..ff4a521 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -4,7 +4,6 @@ import PackageConfig let adapter = TypePreservingCodingAdapter() .register(aliased: ExampleConfiguration.self) -let config = PackageConfig.load(adapter) -let exampleConfiguration = config?[package: .example] as? ExampleConfiguration +let example: ExampleConfiguration? = PackageConfig.load(.example, adapter: adapter) -print(exampleConfiguration!) +print(example) diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 8ac65f2..94cd663 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -12,6 +12,11 @@ public struct PackageConfig { write(adapter: adapter) } + /// Loads the specific Configuration if capable + public static func load(_ packageName: PackageName, adapter: TypePreservingCodingAdapter) -> T? { + return read(adapter: adapter)?[package: packageName] as? T + } + /// Loads the Configuration if capable public static func load(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { return read(adapter: adapter) From 2a0d7b637a20382a81d97429a8f3239e77000132 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 15:26:40 +0200 Subject: [PATCH 10/41] Updated README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7370f2f..33144fc 100644 --- a/README.md +++ b/README.md @@ -90,11 +90,9 @@ import PackageConfig let adapter = TypePreservingCodingAdapter() .register(aliased: YourPackageConfig.self) -let config = PackageConfig.load(adapter) +let yourConfig: YourPackageConfig? = PackageConfig.load(.yourPackageName, adapter: adapter) -let yourConfig = config?[package: .yourPackageName] as? YourPackageConfig - -print(yourConfig) +print(yourConfig!) ``` ---- From fea2070c29e138e9d292fb9458be0cfd985fc68f Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 16:12:05 +0200 Subject: [PATCH 11/41] Testing with external dependency to make it work --- Sources/Example/main.swift | 2 +- Sources/PackageConfig/PackageConfig.swift | 256 +++++++++++----------- 2 files changed, 128 insertions(+), 130 deletions(-) diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index ff4a521..c48c210 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -4,6 +4,6 @@ import PackageConfig let adapter = TypePreservingCodingAdapter() .register(aliased: ExampleConfiguration.self) -let example: ExampleConfiguration? = PackageConfig.load(.example, adapter: adapter) +let example: ExampleConfiguration? = loadConfigurationFromPackageConfig(.example, adapter: adapter) print(example) diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 94cd663..02cd282 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -9,17 +9,7 @@ public struct PackageConfig { public init(configurations: [PackageName: Aliased], adapter: TypePreservingCodingAdapter) { self.configurations = configurations - write(adapter: adapter) - } - - /// Loads the specific Configuration if capable - public static func load(_ packageName: PackageName, adapter: TypePreservingCodingAdapter) -> T? { - return read(adapter: adapter)?[package: packageName] as? T - } - - /// Loads the Configuration if capable - public static func load(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { - return read(adapter: adapter) + write(packageConfig: self, adapter: adapter) } /// Provides a specific package configuation by packageName @@ -49,154 +39,162 @@ extension PackageConfig: Codable { } } -extension PackageConfig { - func write(adapter: TypePreservingCodingAdapter) { - let fileManager = FileManager.default - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" - let encoder = JSONEncoder() - encoder.userInfo[.typePreservingAdapter] = adapter - let data = try! encoder.encode(self) +/// Loads the specific Configuration if capable +public func loadConfigurationFromPackageConfig(_ packageName: PackageName, adapter: TypePreservingCodingAdapter) -> T? { + return read(adapter: adapter)?[package: packageName] as? T +} - if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { - print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") - } - } +/// Loads the Configuration if capable +public func loadPackageConfig(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { + return read(adapter: adapter) +} - /// Only prints when --verbose is in the arge, or when DEBUG exists - static func debugLog(_ message: String) -> Void { - let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) - if isVerbose { - print(message) - } +func write(packageConfig: PackageConfig, adapter: TypePreservingCodingAdapter) { + let fileManager = FileManager.default + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" + let encoder = JSONEncoder() + encoder.userInfo[.typePreservingAdapter] = adapter + let data = try! encoder.encode(packageConfig) + + if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { + print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") } +} - /// Gets a config object from the user's Package.swift - /// by parsing the document by the same way that SwiftPM does it - /// - Returns: A dictionary of all settings - static func read(adapter: TypePreservingCodingAdapter) -> PackageConfig? { - let fileManager = FileManager.default - let swiftC = runXCRun(tool: "swiftc") +/// Only prints when --verbose is in the arge, or when DEBUG exists +func debugLog(_ message: String) -> Void { + let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) + if isVerbose { + print(message) + } +} - var args = [String]() - args += ["--driver-mode=swift"] // Eval in swift mode, I think? +/// Gets a config object from the user's Package.swift +/// by parsing the document by the same way that SwiftPM does it +/// - Returns: A dictionary of all settings +func read(adapter: TypePreservingCodingAdapter) -> PackageConfig? { + let fileManager = FileManager.default + let swiftC = runXCRun(tool: "swiftc") - args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib - args += getPackageConfigArgs() // This lib + var args = [String]() + args += ["--driver-mode=swift"] // Eval in swift mode, I think? - args += ["-suppress-warnings"] // SPM does that too - args += ["Package.swift"] // The Package.swift in the CWD + args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib + args += getPackageConfigArgs() // This lib - // Create a process to eval the Swift Package manifest as a subprocess - let proc = Process() - proc.launchPath = swiftC - proc.arguments = args + args += ["-suppress-warnings"] // SPM does that too + args += ["Package.swift"] // The Package.swift in the CWD - debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") + // Create a process to eval the Swift Package manifest as a subprocess + let proc = Process() + proc.launchPath = swiftC + proc.arguments = args - let standardOutput = FileHandle.standardOutput - proc.standardOutput = standardOutput - proc.standardError = standardOutput + debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") - // Evaluation of the package swift code will end up - // creating a file in the tmpdir that stores the JSON - // settings when a new instance of PackageConfig is created + let standardOutput = FileHandle.standardOutput + proc.standardOutput = standardOutput + proc.standardError = standardOutput - proc.launch() - proc.waitUntilExit() + // Evaluation of the package swift code will end up + // creating a file in the tmpdir that stores the JSON + // settings when a new instance of PackageConfig is created - debugLog("Finished launching swiftc") + proc.launch() + proc.waitUntilExit() - // So read it - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" + debugLog("Finished launching swiftc") - print(path) + // So read it + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" - guard let data = fileManager.contents(atPath: packageConfigJSON) else { - // Package Manifest did not contain a config object at all - // so just return an empty dictionary - debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") - return nil - } + print(path) - debugLog("Got \(String(describing: String(data: data, encoding: .utf8)))") + guard let data = fileManager.contents(atPath: packageConfigJSON) else { + // Package Manifest did not contain a config object at all + // so just return an empty dictionary + debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") + return nil + } - let decoder = JSONDecoder() - decoder.userInfo[.typePreservingAdapter] = adapter + debugLog("Got \(String(describing: String(data: data, encoding: .utf8)))") - return try! decoder.decode(PackageConfig.self, from: data) - } + let decoder = JSONDecoder() + decoder.userInfo[.typePreservingAdapter] = adapter - /// Helper to run xcrun to get paths for things - static func runXCRun(tool: String) -> String { - let proc = Process() - proc.launchPath = "/usr/bin/xcrun" - proc.arguments = ["--find", tool] + return try! decoder.decode(PackageConfig.self, from: data) +} - debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") +/// Helper to run xcrun to get paths for things +func runXCRun(tool: String) -> String { + let proc = Process() + proc.launchPath = "/usr/bin/xcrun" + proc.arguments = ["--find", tool] - let pipe = Pipe() - proc.standardOutput = pipe + debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") - proc.launch() - proc.waitUntilExit() + let pipe = Pipe() + proc.standardOutput = pipe - let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) - } + proc.launch() + proc.waitUntilExit() - // Finds args for the current version of Xcode's Swift Package Manager - static func getSwiftPMManifestArgs(swiftPath: String) -> [String] { - // using "xcrun --find swift" we get - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc - // we need to transform it to something like: - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 - let fileManager = FileManager.default - - let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") - let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) - // TODO: Handle the - // // swift-tools-version:4.2 - // declarations? - let latestSPM = versions.sorted().last! - let libraryPathSPM = swiftPMDir + "/" + latestSPM - - debugLog("Using SPM version: \(libraryPathSPM)") - return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] - } + let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! + return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) +} - /// Finds a path to add at runtime to the compiler, which links - /// to the library Danger - static func getLibPackageConfigPath() -> String? { - let fileManager = FileManager.default - - // Check and find where we can link to libDanger from - let libPaths = [ - ".build/debug", // Working in Xcode / CLI - ".build/x86_64-unknown-linux/debug", // Danger Swift's CI - ".build/release", // Testing prod - ] - - func isTheDangerLibPath(path: String) -> Bool { - return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX - fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux - } +// Finds args for the current version of Xcode's Swift Package Manager +func getSwiftPMManifestArgs(swiftPath: String) -> [String] { + // using "xcrun --find swift" we get + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc + // we need to transform it to something like: + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 + let fileManager = FileManager.default + + let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") + let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) + // TODO: Handle the + // // swift-tools-version:4.2 + // declarations? + let latestSPM = versions.sorted().last! + let libraryPathSPM = swiftPMDir + "/" + latestSPM + + debugLog("Using SPM version: \(libraryPathSPM)") + return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] +} - return libPaths.first(where: { - print($0) - return isTheDangerLibPath(path: $0) - }) +/// Finds a path to add at runtime to the compiler, which links +/// to the library Danger +func getLibPackageConfigPath() -> String? { + let fileManager = FileManager.default + + // Check and find where we can link to libDanger from + let libPaths = [ + ".build/debug", // Working in Xcode / CLI + ".build/x86_64-unknown-linux/debug", // Danger Swift's CI + ".build/release", // Testing prod + ] + + func isTheDangerLibPath(path: String) -> Bool { + return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX + fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux } + return libPaths.first(where: { + print($0) + return isTheDangerLibPath(path: $0) + }) +} - /// Finds args for the locally built copy of PackageConfig - static func getPackageConfigArgs() -> [String] { - guard let libPackageConfig = getLibPackageConfigPath() else { - print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") - exit(1) - } - return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] + +/// Finds args for the locally built copy of PackageConfig +func getPackageConfigArgs() -> [String] { + guard let libPackageConfig = getLibPackageConfigPath() else { + print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") + exit(1) } + return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] } From 7224fdf4e2409f39f9f7df5f85530bdee11b6e7a Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 16:35:04 +0200 Subject: [PATCH 12/41] Reverted changes --- Sources/Example/main.swift | 2 +- Sources/PackageConfig/PackageConfig.swift | 253 +++++++++++----------- 2 files changed, 127 insertions(+), 128 deletions(-) diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index c48c210..ff4a521 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -4,6 +4,6 @@ import PackageConfig let adapter = TypePreservingCodingAdapter() .register(aliased: ExampleConfiguration.self) -let example: ExampleConfiguration? = loadConfigurationFromPackageConfig(.example, adapter: adapter) +let example: ExampleConfiguration? = PackageConfig.load(.example, adapter: adapter) print(example) diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 02cd282..bff1735 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -9,7 +9,7 @@ public struct PackageConfig { public init(configurations: [PackageName: Aliased], adapter: TypePreservingCodingAdapter) { self.configurations = configurations - write(packageConfig: self, adapter: adapter) + write(adapter: adapter) } /// Provides a specific package configuation by packageName @@ -18,6 +18,16 @@ public struct PackageConfig { return configurations[packageName] } } + + /// Loads the specific Configuration if capable + public static func load(_ packageName: PackageName, adapter: TypePreservingCodingAdapter) -> T? { + return read(adapter: adapter)?[package: packageName] as? T + } + + /// Loads the Configuration if capable + public static func load(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { + return read(adapter: adapter) + } } extension PackageConfig: Codable { @@ -39,162 +49,151 @@ extension PackageConfig: Codable { } } +extension PackageConfig { -/// Loads the specific Configuration if capable -public func loadConfigurationFromPackageConfig(_ packageName: PackageName, adapter: TypePreservingCodingAdapter) -> T? { - return read(adapter: adapter)?[package: packageName] as? T -} - -/// Loads the Configuration if capable -public func loadPackageConfig(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { - return read(adapter: adapter) -} + func write(adapter: TypePreservingCodingAdapter) { + let fileManager = FileManager.default + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" + let encoder = JSONEncoder() + encoder.userInfo[.typePreservingAdapter] = adapter + let data = try! encoder.encode(self) -func write(packageConfig: PackageConfig, adapter: TypePreservingCodingAdapter) { - let fileManager = FileManager.default - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" - let encoder = JSONEncoder() - encoder.userInfo[.typePreservingAdapter] = adapter - let data = try! encoder.encode(packageConfig) - - if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { - print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") + if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { + print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") + } } -} -/// Only prints when --verbose is in the arge, or when DEBUG exists -func debugLog(_ message: String) -> Void { - let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) - if isVerbose { - print(message) + /// Only prints when --verbose is in the arge, or when DEBUG exists + static func debugLog(_ message: String) -> Void { + let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) + if isVerbose { + print(message) + } } -} -/// Gets a config object from the user's Package.swift -/// by parsing the document by the same way that SwiftPM does it -/// - Returns: A dictionary of all settings -func read(adapter: TypePreservingCodingAdapter) -> PackageConfig? { - let fileManager = FileManager.default - let swiftC = runXCRun(tool: "swiftc") + /// Gets a config object from the user's Package.swift + /// by parsing the document by the same way that SwiftPM does it + /// - Returns: A dictionary of all settings + static func read(adapter: TypePreservingCodingAdapter) -> PackageConfig? { + let fileManager = FileManager.default + let swiftC = runXCRun(tool: "swiftc") - var args = [String]() - args += ["--driver-mode=swift"] // Eval in swift mode, I think? + var args = [String]() + args += ["--driver-mode=swift"] // Eval in swift mode, I think? - args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib - args += getPackageConfigArgs() // This lib + args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib + args += getPackageConfigArgs() // This lib - args += ["-suppress-warnings"] // SPM does that too - args += ["Package.swift"] // The Package.swift in the CWD + args += ["-suppress-warnings"] // SPM does that too + args += ["Package.swift"] // The Package.swift in the CWD - // Create a process to eval the Swift Package manifest as a subprocess - let proc = Process() - proc.launchPath = swiftC - proc.arguments = args + // Create a process to eval the Swift Package manifest as a subprocess + let proc = Process() + proc.launchPath = swiftC + proc.arguments = args - debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") + debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") - let standardOutput = FileHandle.standardOutput - proc.standardOutput = standardOutput - proc.standardError = standardOutput + let standardOutput = FileHandle.standardOutput + proc.standardOutput = standardOutput + proc.standardError = standardOutput - // Evaluation of the package swift code will end up - // creating a file in the tmpdir that stores the JSON - // settings when a new instance of PackageConfig is created + // Evaluation of the package swift code will end up + // creating a file in the tmpdir that stores the JSON + // settings when a new instance of PackageConfig is created - proc.launch() - proc.waitUntilExit() + proc.launch() + proc.waitUntilExit() - debugLog("Finished launching swiftc") + debugLog("Finished launching swiftc") - // So read it - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" + // So read it + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" - print(path) + print(path) - guard let data = fileManager.contents(atPath: packageConfigJSON) else { - // Package Manifest did not contain a config object at all - // so just return an empty dictionary - debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") - return nil - } - - debugLog("Got \(String(describing: String(data: data, encoding: .utf8)))") + guard let data = fileManager.contents(atPath: packageConfigJSON) else { + // Package Manifest did not contain a config object at all + // so just return an empty dictionary + debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") + return nil + } - let decoder = JSONDecoder() - decoder.userInfo[.typePreservingAdapter] = adapter + debugLog("Got \(String(describing: String(data: data, encoding: .utf8)))") - return try! decoder.decode(PackageConfig.self, from: data) -} + let decoder = JSONDecoder() + decoder.userInfo[.typePreservingAdapter] = adapter -/// Helper to run xcrun to get paths for things -func runXCRun(tool: String) -> String { - let proc = Process() - proc.launchPath = "/usr/bin/xcrun" - proc.arguments = ["--find", tool] + return try! decoder.decode(PackageConfig.self, from: data) + } - debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") + /// Helper to run xcrun to get paths for things + static func runXCRun(tool: String) -> String { + let proc = Process() + proc.launchPath = "/usr/bin/xcrun" + proc.arguments = ["--find", tool] - let pipe = Pipe() - proc.standardOutput = pipe + debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") - proc.launch() - proc.waitUntilExit() + let pipe = Pipe() + proc.standardOutput = pipe - let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) -} + proc.launch() + proc.waitUntilExit() -// Finds args for the current version of Xcode's Swift Package Manager -func getSwiftPMManifestArgs(swiftPath: String) -> [String] { - // using "xcrun --find swift" we get - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc - // we need to transform it to something like: - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 - let fileManager = FileManager.default - - let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") - let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) - // TODO: Handle the - // // swift-tools-version:4.2 - // declarations? - let latestSPM = versions.sorted().last! - let libraryPathSPM = swiftPMDir + "/" + latestSPM - - debugLog("Using SPM version: \(libraryPathSPM)") - return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] -} + let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! + return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) + } -/// Finds a path to add at runtime to the compiler, which links -/// to the library Danger -func getLibPackageConfigPath() -> String? { - let fileManager = FileManager.default - - // Check and find where we can link to libDanger from - let libPaths = [ - ".build/debug", // Working in Xcode / CLI - ".build/x86_64-unknown-linux/debug", // Danger Swift's CI - ".build/release", // Testing prod - ] - - func isTheDangerLibPath(path: String) -> Bool { - return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX - fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux + // Finds args for the current version of Xcode's Swift Package Manager + static func getSwiftPMManifestArgs(swiftPath: String) -> [String] { + // using "xcrun --find swift" we get + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc + // we need to transform it to something like: + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 + let fileManager = FileManager.default + + let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") + let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) + // TODO: Handle the + // // swift-tools-version:4.2 + // declarations? + let latestSPM = versions.sorted().last! + let libraryPathSPM = swiftPMDir + "/" + latestSPM + + debugLog("Using SPM version: \(libraryPathSPM)") + return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] } - return libPaths.first(where: { - print($0) - return isTheDangerLibPath(path: $0) - }) -} + /// Finds a path to add at runtime to the compiler, which links + /// to the library Danger + static func getLibPackageConfigPath() -> String? { + let fileManager = FileManager.default + + // Check and find where we can link to libDanger from + let libPaths = [ + ".build/debug", // Working in Xcode / CLI + ".build/x86_64-unknown-linux/debug", // Danger Swift's CI + ".build/release", // Testing prod + ] + + func isTheDangerLibPath(path: String) -> Bool { + return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX + fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux + } + + return libPaths.first(where: isTheDangerLibPath) + } -/// Finds args for the locally built copy of PackageConfig -func getPackageConfigArgs() -> [String] { - guard let libPackageConfig = getLibPackageConfigPath() else { - print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") - exit(1) + /// Finds args for the locally built copy of PackageConfig + static func getPackageConfigArgs() -> [String] { + guard let libPackageConfig = getLibPackageConfigPath() else { + print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") + exit(1) + } + return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] } - return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] } From ede013e748ef301bcd104abbdc94e50fddb383ff Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 18:20:36 +0200 Subject: [PATCH 13/41] Seems to work, now to test on external project --- Package.swift | 15 +- PackageConfig.xcodeproj/project.pbxproj | 1617 ++++++++--------- .../xcschemes/PackageConfig-Package.xcscheme | 18 +- Sources/Example/main.swift | 5 +- Sources/PackageConfig/Aliased.swift | 15 - Sources/PackageConfig/Configuration.swift | 53 + .../PackageConfig/ExampleConfiguration.swift | 12 +- Sources/PackageConfig/Loader.swift | 16 + Sources/PackageConfig/Package.swift | 108 ++ Sources/PackageConfig/PackageConfig.swift | 199 -- Sources/PackageConfig/PackageName.swift | 25 - Sources/PackageConfig/Writer.swift | 18 + 12 files changed, 967 insertions(+), 1134 deletions(-) delete mode 100644 Sources/PackageConfig/Aliased.swift create mode 100644 Sources/PackageConfig/Configuration.swift create mode 100644 Sources/PackageConfig/Loader.swift create mode 100644 Sources/PackageConfig/Package.swift delete mode 100644 Sources/PackageConfig/PackageConfig.swift delete mode 100644 Sources/PackageConfig/PackageName.swift create mode 100644 Sources/PackageConfig/Writer.swift diff --git a/Package.swift b/Package.swift index 2a166d3..e856409 100644 --- a/Package.swift +++ b/Package.swift @@ -10,14 +10,13 @@ let package = Package( .executable(name: "package-config-example", targets: ["Example"]) ], dependencies: [ - .package(url: "https://github.com/IgorMuzyka/Type-Preserving-Coding-Adapter.git", from: "1.0.0"), ], targets: [ // The lib - .target(name: "PackageConfig", dependencies: ["TypePreservingCodingAdapter"]), + .target(name: "PackageConfig", dependencies: []), // The app I use to verify it all works - .target(name: "Example", dependencies: ["PackageConfig", "TypePreservingCodingAdapter"]), + .target(name: "Example", dependencies: ["PackageConfig"]), // Not used .testTarget(name: "PackageConfigTests", dependencies: ["PackageConfig"]), ] @@ -26,12 +25,6 @@ let package = Package( #if canImport(PackageConfig) import PackageConfig -let config = PackageConfig( - configurations: [ - .example: ExampleConfiguration(value: "example configuration value") - ], - adapter: TypePreservingCodingAdapter() - .register(aliased: ExampleConfiguration.self) -) -#endif +ExampleConfiguration(value: "lol kek").write() +#endif diff --git a/PackageConfig.xcodeproj/project.pbxproj b/PackageConfig.xcodeproj/project.pbxproj index 83a14b0..02262a3 100644 --- a/PackageConfig.xcodeproj/project.pbxproj +++ b/PackageConfig.xcodeproj/project.pbxproj @@ -1,865 +1,758 @@ // !$*UTF8*$! { - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXAggregateTarget section */ - "PackageConfig::PackageConfigPackageTests::ProductTarget" /* PackageConfigPackageTests */ = { - isa = PBXAggregateTarget; - buildConfigurationList = OBJ_58 /* Build configuration list for PBXAggregateTarget "PackageConfigPackageTests" */; - buildPhases = ( - ); - dependencies = ( - OBJ_61 /* PBXTargetDependency */, - ); - name = PackageConfigPackageTests; - productName = PackageConfigPackageTests; - }; - "PackageConfig::package-config-example::ProductTarget" /* package-config-example */ = { - isa = PBXAggregateTarget; - buildConfigurationList = OBJ_92 /* Build configuration list for PBXAggregateTarget "package-config-example" */; - buildPhases = ( - ); - dependencies = ( - OBJ_95 /* PBXTargetDependency */, - ); - name = "package-config-example"; - productName = "package-config-example"; - }; -/* End PBXAggregateTarget section */ - -/* Begin PBXBuildFile section */ - 789A035E223BDC8D00007369 /* Aliased.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789A035D223BDC8D00007369 /* Aliased.swift */; }; - 789A0360223BDCB700007369 /* PackageConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789A035F223BDCB700007369 /* PackageConfig.swift */; }; - 78AB289F223D246B00B2296B /* PackageName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78AB289D223D237600B2296B /* PackageName.swift */; }; - 78AB28A1223D24A300B2296B /* ExampleConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78AB28A0223D24A300B2296B /* ExampleConfiguration.swift */; }; - OBJ_35 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* main.swift */; }; - OBJ_37 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; - OBJ_38 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; - OBJ_49 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; - OBJ_56 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_6 /* Package.swift */; }; - OBJ_67 /* PackageConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* PackageConfigTests.swift */; }; - OBJ_68 /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_15 /* XCTestManifests.swift */; }; - OBJ_70 /* PackageConfig.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; }; - OBJ_71 /* TypePreservingCodingAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; }; - OBJ_78 /* Alias.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_19 /* Alias.swift */; }; - OBJ_79 /* Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_20 /* Convenience.swift */; }; - OBJ_80 /* Signature.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_21 /* Signature.swift */; }; - OBJ_81 /* TypePreservingCodingAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_22 /* TypePreservingCodingAdapter.swift */; }; - OBJ_82 /* TypePreservingCodingAdapterError.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_23 /* TypePreservingCodingAdapterError.swift */; }; - OBJ_83 /* Wrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_24 /* Wrap.swift */; }; - OBJ_90 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_18 /* Package.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 789A0356223BD31100007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "TypePreservingCodingAdapter::TypePreservingCodingAdapter"; - remoteInfo = TypePreservingCodingAdapter; - }; - 789A0357223BD31100007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "PackageConfig::PackageConfig"; - remoteInfo = PackageConfig; - }; - 789A0358223BD31100007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "TypePreservingCodingAdapter::TypePreservingCodingAdapter"; - remoteInfo = TypePreservingCodingAdapter; - }; - 789A0359223BD31100007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "PackageConfig::PackageConfig"; - remoteInfo = PackageConfig; - }; - 789A035A223BD31100007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "TypePreservingCodingAdapter::TypePreservingCodingAdapter"; - remoteInfo = TypePreservingCodingAdapter; - }; - 789A035B223BD31200007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "PackageConfig::PackageConfigTests"; - remoteInfo = PackageConfigTests; - }; - 789A035C223BD31200007369 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = OBJ_1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = "PackageConfig::Example"; - remoteInfo = Example; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 789A035D223BDC8D00007369 /* Aliased.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Aliased.swift; sourceTree = ""; }; - 789A035F223BDCB700007369 /* PackageConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfig.swift; sourceTree = ""; }; - 78AB289D223D237600B2296B /* PackageName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageName.swift; sourceTree = ""; }; - 78AB28A0223D24A300B2296B /* ExampleConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleConfiguration.swift; sourceTree = ""; }; - OBJ_14 /* PackageConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageConfigTests.swift; sourceTree = ""; }; - OBJ_15 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = ""; }; - OBJ_18 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; name = Package.swift; path = "/Users/igor/development/libraries/PackageConfig/.build/checkouts/Type-Preserving-Coding-Adapter.git--4237871635319230087/Package.swift"; sourceTree = ""; }; - OBJ_19 /* Alias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alias.swift; sourceTree = ""; }; - OBJ_20 /* Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Convenience.swift; sourceTree = ""; }; - OBJ_21 /* Signature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signature.swift; sourceTree = ""; }; - OBJ_22 /* TypePreservingCodingAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypePreservingCodingAdapter.swift; sourceTree = ""; }; - OBJ_23 /* TypePreservingCodingAdapterError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypePreservingCodingAdapterError.swift; sourceTree = ""; }; - OBJ_24 /* Wrap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wrap.swift; sourceTree = ""; }; - OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; - OBJ_9 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; - "PackageConfig::Example::Product" /* Example */ = {isa = PBXFileReference; lastKnownFileType = text; path = Example; sourceTree = BUILT_PRODUCTS_DIR; }; - "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = PackageConfig.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - "PackageConfig::PackageConfigTests::Product" /* PackageConfigTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = PackageConfigTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = TypePreservingCodingAdapter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - OBJ_36 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 0; - files = ( - OBJ_37 /* PackageConfig.framework in Frameworks */, - OBJ_38 /* TypePreservingCodingAdapter.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_48 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 0; - files = ( - OBJ_49 /* TypePreservingCodingAdapter.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_69 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 0; - files = ( - OBJ_70 /* PackageConfig.framework in Frameworks */, - OBJ_71 /* TypePreservingCodingAdapter.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_84 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - OBJ_10 /* PackageConfig */ = { - isa = PBXGroup; - children = ( - 789A035D223BDC8D00007369 /* Aliased.swift */, - 789A035F223BDCB700007369 /* PackageConfig.swift */, - 78AB289D223D237600B2296B /* PackageName.swift */, - 78AB28A0223D24A300B2296B /* ExampleConfiguration.swift */, - ); - name = PackageConfig; - path = Sources/PackageConfig; - sourceTree = SOURCE_ROOT; - }; - OBJ_12 /* Tests */ = { - isa = PBXGroup; - children = ( - OBJ_13 /* PackageConfigTests */, - ); - name = Tests; - sourceTree = SOURCE_ROOT; - }; - OBJ_13 /* PackageConfigTests */ = { - isa = PBXGroup; - children = ( - OBJ_14 /* PackageConfigTests.swift */, - OBJ_15 /* XCTestManifests.swift */, - ); - name = PackageConfigTests; - path = Tests/PackageConfigTests; - sourceTree = SOURCE_ROOT; - }; - OBJ_16 /* Dependencies */ = { - isa = PBXGroup; - children = ( - OBJ_17 /* TypePreservingCodingAdapter */, - ); - name = Dependencies; - sourceTree = ""; - }; - OBJ_17 /* TypePreservingCodingAdapter */ = { - isa = PBXGroup; - children = ( - OBJ_18 /* Package.swift */, - OBJ_19 /* Alias.swift */, - OBJ_20 /* Convenience.swift */, - OBJ_21 /* Signature.swift */, - OBJ_22 /* TypePreservingCodingAdapter.swift */, - OBJ_23 /* TypePreservingCodingAdapterError.swift */, - OBJ_24 /* Wrap.swift */, - ); - name = TypePreservingCodingAdapter; - path = ".build/checkouts/Type-Preserving-Coding-Adapter.git--4237871635319230087/Sources"; - sourceTree = SOURCE_ROOT; - }; - OBJ_25 /* Products */ = { - isa = PBXGroup; - children = ( - "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */, - "PackageConfig::PackageConfigTests::Product" /* PackageConfigTests.xctest */, - "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */, - "PackageConfig::Example::Product" /* Example */, - ); - name = Products; - sourceTree = BUILT_PRODUCTS_DIR; - }; - OBJ_5 = { - isa = PBXGroup; - children = ( - OBJ_6 /* Package.swift */, - OBJ_7 /* Sources */, - OBJ_12 /* Tests */, - OBJ_16 /* Dependencies */, - OBJ_25 /* Products */, - ); - sourceTree = ""; - }; - OBJ_7 /* Sources */ = { - isa = PBXGroup; - children = ( - OBJ_8 /* Example */, - OBJ_10 /* PackageConfig */, - ); - name = Sources; - sourceTree = SOURCE_ROOT; - }; - OBJ_8 /* Example */ = { - isa = PBXGroup; - children = ( - OBJ_9 /* main.swift */, - ); - name = Example; - path = Sources/Example; - sourceTree = SOURCE_ROOT; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - "PackageConfig::Example" /* Example */ = { - isa = PBXNativeTarget; - buildConfigurationList = OBJ_31 /* Build configuration list for PBXNativeTarget "Example" */; - buildPhases = ( - OBJ_34 /* Sources */, - OBJ_36 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - OBJ_39 /* PBXTargetDependency */, - OBJ_41 /* PBXTargetDependency */, - ); - name = Example; - productName = Example; - productReference = "PackageConfig::Example::Product" /* Example */; - productType = "com.apple.product-type.tool"; - }; - "PackageConfig::PackageConfig" /* PackageConfig */ = { - isa = PBXNativeTarget; - buildConfigurationList = OBJ_43 /* Build configuration list for PBXNativeTarget "PackageConfig" */; - buildPhases = ( - OBJ_46 /* Sources */, - OBJ_48 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - OBJ_50 /* PBXTargetDependency */, - ); - name = PackageConfig; - productName = PackageConfig; - productReference = "PackageConfig::PackageConfig::Product" /* PackageConfig.framework */; - productType = "com.apple.product-type.framework"; - }; - "PackageConfig::PackageConfigTests" /* PackageConfigTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = OBJ_63 /* Build configuration list for PBXNativeTarget "PackageConfigTests" */; - buildPhases = ( - OBJ_66 /* Sources */, - OBJ_69 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - OBJ_72 /* PBXTargetDependency */, - OBJ_73 /* PBXTargetDependency */, - ); - name = PackageConfigTests; - productName = PackageConfigTests; - productReference = "PackageConfig::PackageConfigTests::Product" /* PackageConfigTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - "PackageConfig::SwiftPMPackageDescription" /* PackageConfigPackageDescription */ = { - isa = PBXNativeTarget; - buildConfigurationList = OBJ_52 /* Build configuration list for PBXNativeTarget "PackageConfigPackageDescription" */; - buildPhases = ( - OBJ_55 /* Sources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = PackageConfigPackageDescription; - productName = PackageConfigPackageDescription; - productType = "com.apple.product-type.framework"; - }; - "TypePreservingCodingAdapter::SwiftPMPackageDescription" /* TypePreservingCodingAdapterPackageDescription */ = { - isa = PBXNativeTarget; - buildConfigurationList = OBJ_86 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapterPackageDescription" */; - buildPhases = ( - OBJ_89 /* Sources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = TypePreservingCodingAdapterPackageDescription; - productName = TypePreservingCodingAdapterPackageDescription; - productType = "com.apple.product-type.framework"; - }; - "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */ = { - isa = PBXNativeTarget; - buildConfigurationList = OBJ_74 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapter" */; - buildPhases = ( - OBJ_77 /* Sources */, - OBJ_84 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = TypePreservingCodingAdapter; - productName = TypePreservingCodingAdapter; - productReference = "TypePreservingCodingAdapter::TypePreservingCodingAdapter::Product" /* TypePreservingCodingAdapter.framework */; - productType = "com.apple.product-type.framework"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - OBJ_1 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 9999; - }; - buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "PackageConfig" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = OBJ_5; - productRefGroup = OBJ_25 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - "PackageConfig::Example" /* Example */, - "PackageConfig::PackageConfig" /* PackageConfig */, - "PackageConfig::SwiftPMPackageDescription" /* PackageConfigPackageDescription */, - "PackageConfig::PackageConfigPackageTests::ProductTarget" /* PackageConfigPackageTests */, - "PackageConfig::PackageConfigTests" /* PackageConfigTests */, - "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */, - "TypePreservingCodingAdapter::SwiftPMPackageDescription" /* TypePreservingCodingAdapterPackageDescription */, - "PackageConfig::package-config-example::ProductTarget" /* package-config-example */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - OBJ_34 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - OBJ_35 /* main.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_46 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - 789A0360223BDCB700007369 /* PackageConfig.swift in Sources */, - 78AB28A1223D24A300B2296B /* ExampleConfiguration.swift in Sources */, - 78AB289F223D246B00B2296B /* PackageName.swift in Sources */, - 789A035E223BDC8D00007369 /* Aliased.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_55 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - OBJ_56 /* Package.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_66 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - OBJ_67 /* PackageConfigTests.swift in Sources */, - OBJ_68 /* XCTestManifests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_77 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - OBJ_78 /* Alias.swift in Sources */, - OBJ_79 /* Convenience.swift in Sources */, - OBJ_80 /* Signature.swift in Sources */, - OBJ_81 /* TypePreservingCodingAdapter.swift in Sources */, - OBJ_82 /* TypePreservingCodingAdapterError.swift in Sources */, - OBJ_83 /* Wrap.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - OBJ_89 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - OBJ_90 /* Package.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - OBJ_39 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "PackageConfig::PackageConfig" /* PackageConfig */; - targetProxy = 789A0357223BD31100007369 /* PBXContainerItemProxy */; - }; - OBJ_41 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */; - targetProxy = 789A0358223BD31100007369 /* PBXContainerItemProxy */; - }; - OBJ_50 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */; - targetProxy = 789A0356223BD31100007369 /* PBXContainerItemProxy */; - }; - OBJ_61 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "PackageConfig::PackageConfigTests" /* PackageConfigTests */; - targetProxy = 789A035B223BD31200007369 /* PBXContainerItemProxy */; - }; - OBJ_72 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "PackageConfig::PackageConfig" /* PackageConfig */; - targetProxy = 789A0359223BD31100007369 /* PBXContainerItemProxy */; - }; - OBJ_73 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "TypePreservingCodingAdapter::TypePreservingCodingAdapter" /* TypePreservingCodingAdapter */; - targetProxy = 789A035A223BD31100007369 /* PBXContainerItemProxy */; - }; - OBJ_95 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "PackageConfig::Example" /* Example */; - targetProxy = 789A035C223BD31200007369 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - OBJ_3 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_NS_ASSERTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - MACOSX_DEPLOYMENT_TARGET = 10.10; - ONLY_ACTIVE_ARCH = YES; - OTHER_SWIFT_FLAGS = "-DXcode"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "SWIFT_PACKAGE DEBUG"; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - USE_HEADERMAP = NO; - }; - name = Debug; - }; - OBJ_32 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/Example_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx @executable_path"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES; - SWIFT_FORCE_STATIC_LINK_STDLIB = NO; - SWIFT_VERSION = 4.2; - TARGET_NAME = Example; - }; - name = Debug; - }; - OBJ_33 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/Example_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx @executable_path"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES; - SWIFT_FORCE_STATIC_LINK_STDLIB = NO; - SWIFT_VERSION = 4.2; - TARGET_NAME = Example; - }; - name = Release; - }; - OBJ_4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_OPTIMIZATION_LEVEL = s; - MACOSX_DEPLOYMENT_TARGET = 10.10; - OTHER_SWIFT_FLAGS = "-DXcode"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - USE_HEADERMAP = NO; - }; - name = Release; - }; - OBJ_44 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/PackageConfig_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - PRODUCT_BUNDLE_IDENTIFIER = PackageConfig; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_VERSION = 4.2; - TARGET_NAME = PackageConfig; - }; - name = Debug; - }; - OBJ_45 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/PackageConfig_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - PRODUCT_BUNDLE_IDENTIFIER = PackageConfig; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_VERSION = 4.2; - TARGET_NAME = PackageConfig; - }; - name = Release; - }; - OBJ_53 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - LD = /usr/bin/true; - OTHER_SWIFT_FLAGS = "-swift-version 4.2 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"; - SWIFT_VERSION = 4.2; - }; - name = Debug; - }; - OBJ_54 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - LD = /usr/bin/true; - OTHER_SWIFT_FLAGS = "-swift-version 4.2 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"; - SWIFT_VERSION = 4.2; - }; - name = Release; - }; - OBJ_59 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - }; - name = Debug; - }; - OBJ_60 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - }; - name = Release; - }; - OBJ_64 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/PackageConfigTests_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_VERSION = 4.2; - TARGET_NAME = PackageConfigTests; - }; - name = Debug; - }; - OBJ_65 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/PackageConfigTests_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_VERSION = 4.2; - TARGET_NAME = PackageConfigTests; - }; - name = Release; - }; - OBJ_75 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/TypePreservingCodingAdapter_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - PRODUCT_BUNDLE_IDENTIFIER = TypePreservingCodingAdapter; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_VERSION = 4.2; - TARGET_NAME = TypePreservingCodingAdapter; - }; - name = Debug; - }; - OBJ_76 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks", - ); - HEADER_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = PackageConfig.xcodeproj/TypePreservingCodingAdapter_Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; - OTHER_CFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; - OTHER_SWIFT_FLAGS = "$(inherited)"; - PRODUCT_BUNDLE_IDENTIFIER = TypePreservingCodingAdapter; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; - SWIFT_VERSION = 4.2; - TARGET_NAME = TypePreservingCodingAdapter; - }; - name = Release; - }; - OBJ_87 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - LD = /usr/bin/true; - OTHER_SWIFT_FLAGS = "-swift-version 4.2 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"; - SWIFT_VERSION = 4.2; - }; - name = Debug; - }; - OBJ_88 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - LD = /usr/bin/true; - OTHER_SWIFT_FLAGS = "-swift-version 4.2 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"; - SWIFT_VERSION = 4.2; - }; - name = Release; - }; - OBJ_93 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - }; - name = Debug; - }; - OBJ_94 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - OBJ_2 /* Build configuration list for PBXProject "PackageConfig" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_3 /* Debug */, - OBJ_4 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_31 /* Build configuration list for PBXNativeTarget "Example" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_32 /* Debug */, - OBJ_33 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_43 /* Build configuration list for PBXNativeTarget "PackageConfig" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_44 /* Debug */, - OBJ_45 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_52 /* Build configuration list for PBXNativeTarget "PackageConfigPackageDescription" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_53 /* Debug */, - OBJ_54 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_58 /* Build configuration list for PBXAggregateTarget "PackageConfigPackageTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_59 /* Debug */, - OBJ_60 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_63 /* Build configuration list for PBXNativeTarget "PackageConfigTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_64 /* Debug */, - OBJ_65 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_74 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapter" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_75 /* Debug */, - OBJ_76 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_86 /* Build configuration list for PBXNativeTarget "TypePreservingCodingAdapterPackageDescription" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_87 /* Debug */, - OBJ_88 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - OBJ_92 /* Build configuration list for PBXAggregateTarget "package-config-example" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - OBJ_93 /* Debug */, - OBJ_94 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = OBJ_1 /* Project object */; + archiveVersion = "1"; + objectVersion = "46"; + objects = { + "OBJ_1" = { + isa = "PBXProject"; + attributes = { + LastUpgradeCheck = "9999"; + }; + buildConfigurationList = "OBJ_2"; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = "English"; + hasScannedForEncodings = "0"; + knownRegions = ( + "en" + ); + mainGroup = "OBJ_5"; + productRefGroup = "OBJ_20"; + projectDirPath = "."; + targets = ( + "PackageConfig::Example", + "PackageConfig::PackageConfig", + "PackageConfig::SwiftPMPackageDescription", + "PackageConfig::PackageConfigPackageTests::ProductTarget", + "PackageConfig::PackageConfigTests", + "PackageConfig::package-config-example::ProductTarget" + ); + }; + "OBJ_10" = { + isa = "PBXFileReference"; + path = "ExampleConfiguration.swift"; + sourceTree = ""; + }; + "OBJ_11" = { + isa = "PBXFileReference"; + path = "Loader.swift"; + sourceTree = ""; + }; + "OBJ_12" = { + isa = "PBXFileReference"; + path = "Package.swift"; + sourceTree = ""; + }; + "OBJ_13" = { + isa = "PBXFileReference"; + path = "Writer.swift"; + sourceTree = ""; + }; + "OBJ_14" = { + isa = "PBXGroup"; + children = ( + "OBJ_15" + ); + name = "Example"; + path = "Sources/Example"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_15" = { + isa = "PBXFileReference"; + path = "main.swift"; + sourceTree = ""; + }; + "OBJ_16" = { + isa = "PBXGroup"; + children = ( + "OBJ_17" + ); + name = "Tests"; + path = ""; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_17" = { + isa = "PBXGroup"; + children = ( + "OBJ_18", + "OBJ_19" + ); + name = "PackageConfigTests"; + path = "Tests/PackageConfigTests"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_18" = { + isa = "PBXFileReference"; + path = "PackageConfigTests.swift"; + sourceTree = ""; + }; + "OBJ_19" = { + isa = "PBXFileReference"; + path = "XCTestManifests.swift"; + sourceTree = ""; + }; + "OBJ_2" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_3", + "OBJ_4" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_20" = { + isa = "PBXGroup"; + children = ( + "PackageConfig::Example::Product", + "PackageConfig::PackageConfigTests::Product", + "PackageConfig::PackageConfig::Product" + ); + name = "Products"; + path = ""; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "OBJ_25" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_26", + "OBJ_27" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_26" = { + isa = "XCBuildConfiguration"; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "PackageConfig.xcodeproj/Example_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", + "@executable_path" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_FORCE_DYNAMIC_LINK_STDLIB = "YES"; + SWIFT_FORCE_STATIC_LINK_STDLIB = "NO"; + SWIFT_VERSION = "4.2"; + TARGET_NAME = "Example"; + }; + name = "Debug"; + }; + "OBJ_27" = { + isa = "XCBuildConfiguration"; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "PackageConfig.xcodeproj/Example_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", + "@executable_path" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_FORCE_DYNAMIC_LINK_STDLIB = "YES"; + SWIFT_FORCE_STATIC_LINK_STDLIB = "NO"; + SWIFT_VERSION = "4.2"; + TARGET_NAME = "Example"; + }; + name = "Release"; + }; + "OBJ_28" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_29" + ); + }; + "OBJ_29" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_15"; + }; + "OBJ_3" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = "YES"; + COMBINE_HIDPI_IMAGES = "YES"; + COPY_PHASE_STRIP = "NO"; + DEBUG_INFORMATION_FORMAT = "dwarf"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_NS_ASSERTIONS = "YES"; + GCC_OPTIMIZATION_LEVEL = "0"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)" + ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; + ONLY_ACTIVE_ARCH = "YES"; + OTHER_SWIFT_FLAGS = ( + "-DXcode" + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = "macosx"; + SUPPORTED_PLATFORMS = ( + "macosx", + "iphoneos", + "iphonesimulator", + "appletvos", + "appletvsimulator", + "watchos", + "watchsimulator" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "SWIFT_PACKAGE", + "DEBUG" + ); + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + USE_HEADERMAP = "NO"; + }; + name = "Debug"; + }; + "OBJ_30" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + "OBJ_31" + ); + }; + "OBJ_31" = { + isa = "PBXBuildFile"; + fileRef = "PackageConfig::PackageConfig::Product"; + }; + "OBJ_32" = { + isa = "PBXTargetDependency"; + target = "PackageConfig::PackageConfig"; + }; + "OBJ_34" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_35", + "OBJ_36" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_35" = { + isa = "XCBuildConfiguration"; + buildSettings = { + ENABLE_TESTABILITY = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfig_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + PRODUCT_BUNDLE_IDENTIFIER = "PackageConfig"; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = "YES"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "PackageConfig"; + }; + name = "Debug"; + }; + "OBJ_36" = { + isa = "XCBuildConfiguration"; + buildSettings = { + ENABLE_TESTABILITY = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfig_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + PRODUCT_BUNDLE_IDENTIFIER = "PackageConfig"; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = "YES"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "PackageConfig"; + }; + name = "Release"; + }; + "OBJ_37" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_38", + "OBJ_39", + "OBJ_40", + "OBJ_41", + "OBJ_42" + ); + }; + "OBJ_38" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_9"; + }; + "OBJ_39" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_10"; + }; + "OBJ_4" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = "YES"; + COMBINE_HIDPI_IMAGES = "YES"; + COPY_PHASE_STRIP = "YES"; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = "s"; + MACOSX_DEPLOYMENT_TARGET = "10.10"; + OTHER_SWIFT_FLAGS = ( + "-DXcode" + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = "macosx"; + SUPPORTED_PLATFORMS = ( + "macosx", + "iphoneos", + "iphonesimulator", + "appletvos", + "appletvsimulator", + "watchos", + "watchsimulator" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "SWIFT_PACKAGE" + ); + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + USE_HEADERMAP = "NO"; + }; + name = "Release"; + }; + "OBJ_40" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_11"; + }; + "OBJ_41" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_12"; + }; + "OBJ_42" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_13"; + }; + "OBJ_43" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + ); + }; + "OBJ_45" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_46", + "OBJ_47" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_46" = { + isa = "XCBuildConfiguration"; + buildSettings = { + LD = "/usr/bin/true"; + OTHER_SWIFT_FLAGS = ( + "-swift-version", + "4.2", + "-I", + "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", + "-target", + "x86_64-apple-macosx10.10", + "-sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" + ); + SWIFT_VERSION = "4.2"; + }; + name = "Debug"; + }; + "OBJ_47" = { + isa = "XCBuildConfiguration"; + buildSettings = { + LD = "/usr/bin/true"; + OTHER_SWIFT_FLAGS = ( + "-swift-version", + "4.2", + "-I", + "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", + "-target", + "x86_64-apple-macosx10.10", + "-sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" + ); + SWIFT_VERSION = "4.2"; + }; + name = "Release"; + }; + "OBJ_48" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_49" + ); + }; + "OBJ_49" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_6"; + }; + "OBJ_5" = { + isa = "PBXGroup"; + children = ( + "OBJ_6", + "OBJ_7", + "OBJ_16", + "OBJ_20" + ); + path = ""; + sourceTree = ""; + }; + "OBJ_51" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_52", + "OBJ_53" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_52" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Debug"; + }; + "OBJ_53" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Release"; + }; + "OBJ_54" = { + isa = "PBXTargetDependency"; + target = "PackageConfig::PackageConfigTests"; + }; + "OBJ_56" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_57", + "OBJ_58" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_57" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_MODULES = "YES"; + EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfigTests_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/../Frameworks", + "@loader_path/Frameworks" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "PackageConfigTests"; + }; + name = "Debug"; + }; + "OBJ_58" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_MODULES = "YES"; + EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfigTests_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/../Frameworks", + "@loader_path/Frameworks" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "PackageConfigTests"; + }; + name = "Release"; + }; + "OBJ_59" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_60", + "OBJ_61" + ); + }; + "OBJ_6" = { + isa = "PBXFileReference"; + explicitFileType = "sourcecode.swift"; + path = "Package.swift"; + sourceTree = ""; + }; + "OBJ_60" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_18"; + }; + "OBJ_61" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_19"; + }; + "OBJ_62" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + "OBJ_63" + ); + }; + "OBJ_63" = { + isa = "PBXBuildFile"; + fileRef = "PackageConfig::PackageConfig::Product"; + }; + "OBJ_64" = { + isa = "PBXTargetDependency"; + target = "PackageConfig::PackageConfig"; + }; + "OBJ_66" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_67", + "OBJ_68" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_67" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Debug"; + }; + "OBJ_68" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Release"; + }; + "OBJ_69" = { + isa = "PBXTargetDependency"; + target = "PackageConfig::Example"; + }; + "OBJ_7" = { + isa = "PBXGroup"; + children = ( + "OBJ_8", + "OBJ_14" + ); + name = "Sources"; + path = ""; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_8" = { + isa = "PBXGroup"; + children = ( + "OBJ_9", + "OBJ_10", + "OBJ_11", + "OBJ_12", + "OBJ_13" + ); + name = "PackageConfig"; + path = "Sources/PackageConfig"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_9" = { + isa = "PBXFileReference"; + path = "Configuration.swift"; + sourceTree = ""; + }; + "PackageConfig::Example" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_25"; + buildPhases = ( + "OBJ_28", + "OBJ_30" + ); + dependencies = ( + "OBJ_32" + ); + name = "Example"; + productName = "Example"; + productReference = "PackageConfig::Example::Product"; + productType = "com.apple.product-type.tool"; + }; + "PackageConfig::Example::Product" = { + isa = "PBXFileReference"; + path = "Example"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "PackageConfig::PackageConfig" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_34"; + buildPhases = ( + "OBJ_37", + "OBJ_43" + ); + dependencies = ( + ); + name = "PackageConfig"; + productName = "PackageConfig"; + productReference = "PackageConfig::PackageConfig::Product"; + productType = "com.apple.product-type.framework"; + }; + "PackageConfig::PackageConfig::Product" = { + isa = "PBXFileReference"; + path = "PackageConfig.framework"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "PackageConfig::PackageConfigPackageTests::ProductTarget" = { + isa = "PBXAggregateTarget"; + buildConfigurationList = "OBJ_51"; + buildPhases = ( + ); + dependencies = ( + "OBJ_54" + ); + name = "PackageConfigPackageTests"; + productName = "PackageConfigPackageTests"; + }; + "PackageConfig::PackageConfigTests" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_56"; + buildPhases = ( + "OBJ_59", + "OBJ_62" + ); + dependencies = ( + "OBJ_64" + ); + name = "PackageConfigTests"; + productName = "PackageConfigTests"; + productReference = "PackageConfig::PackageConfigTests::Product"; + productType = "com.apple.product-type.bundle.unit-test"; + }; + "PackageConfig::PackageConfigTests::Product" = { + isa = "PBXFileReference"; + path = "PackageConfigTests.xctest"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "PackageConfig::SwiftPMPackageDescription" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_45"; + buildPhases = ( + "OBJ_48" + ); + dependencies = ( + ); + name = "PackageConfigPackageDescription"; + productName = "PackageConfigPackageDescription"; + productType = "com.apple.product-type.framework"; + }; + "PackageConfig::package-config-example::ProductTarget" = { + isa = "PBXAggregateTarget"; + buildConfigurationList = "OBJ_66"; + buildPhases = ( + ); + dependencies = ( + "OBJ_69" + ); + name = "package-config-example"; + productName = "package-config-example"; + }; + }; + rootObject = "OBJ_1"; } diff --git a/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme b/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme index 2dbd03a..8a06f84 100644 --- a/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme +++ b/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "YES"> @@ -28,9 +28,9 @@ buildForAnalyzing = "YES"> @@ -69,9 +69,9 @@ diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index ff4a521..13fbca3 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,9 +1,6 @@ import PackageConfig -let adapter = TypePreservingCodingAdapter() - .register(aliased: ExampleConfiguration.self) - -let example: ExampleConfiguration? = PackageConfig.load(.example, adapter: adapter) +let example = ExampleConfiguration.load() print(example) diff --git a/Sources/PackageConfig/Aliased.swift b/Sources/PackageConfig/Aliased.swift deleted file mode 100644 index 3851f28..0000000 --- a/Sources/PackageConfig/Aliased.swift +++ /dev/null @@ -1,15 +0,0 @@ - -import Foundation -import TypePreservingCodingAdapter - -public protocol Aliased: Codable { - - static var alias: Alias { get } -} - -extension TypePreservingCodingAdapter { - - public func register(aliased type: T.Type) -> TypePreservingCodingAdapter { - return register(type: type).register(alias: T.alias, for: type) - } -} diff --git a/Sources/PackageConfig/Configuration.swift b/Sources/PackageConfig/Configuration.swift new file mode 100644 index 0000000..873efc8 --- /dev/null +++ b/Sources/PackageConfig/Configuration.swift @@ -0,0 +1,53 @@ + +public protocol Configuration: Codable { + + static var dynamicLibraries: [String] { get } + + static func load() -> Self? + func write() +} + +extension Configuration { + + public static func load() -> Self? { + Package(dynamicLibraries: dynamicLibraries + ["PackageConfig"]).compile() + return Loader.load() + } + + public func write() { + Writer.write(configuration: self) + } +} + +import Foundation + +func debugLog(_ message: String) -> Void { + let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) + if isVerbose { + print(message) + } +} + +/* + + + So about how it should work. + + Dependency should conform to dependency and the all of its methods should be available for it. + So when executing the dependency like this `swift run yourDependency`. + It will Compile Package.swift dynamically injecting itself and this dependency as linked libraries. + + So when declarin the dependency configuration one would do as follows: + + #if canImport(YourDependency) + import YourDependency + + DependencyConfiguration().write() + + #endif + + Then in the dependency itself you can load configuration whenever by doing this: + + DependencyConfiguration().load() + +*/ diff --git a/Sources/PackageConfig/ExampleConfiguration.swift b/Sources/PackageConfig/ExampleConfiguration.swift index 1b17ae8..87e7fc4 100644 --- a/Sources/PackageConfig/ExampleConfiguration.swift +++ b/Sources/PackageConfig/ExampleConfiguration.swift @@ -1,17 +1,11 @@ -/// Just an example configuration to test against -public struct ExampleConfiguration: Aliased { +public struct ExampleConfiguration: Codable, Configuration { let value: String + public static var dynamicLibraries: [String] = [] + public init(value: String) { self.value = value } - - public static var alias: Alias = "ExampleConfiguration" -} - -extension PackageName { - - public static var example: PackageName = "ExampleConfiguration" } diff --git a/Sources/PackageConfig/Loader.swift b/Sources/PackageConfig/Loader.swift new file mode 100644 index 0000000..a2f887b --- /dev/null +++ b/Sources/PackageConfig/Loader.swift @@ -0,0 +1,16 @@ + +import Foundation + +enum Loader { + static func load() -> T? { + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" + + guard let data = FileManager.default.contents(atPath: packageConfigJSON) else { + debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") + return nil + } + + return try! JSONDecoder().decode(T.self, from: data) + } +} diff --git a/Sources/PackageConfig/Package.swift b/Sources/PackageConfig/Package.swift new file mode 100644 index 0000000..f1fe951 --- /dev/null +++ b/Sources/PackageConfig/Package.swift @@ -0,0 +1,108 @@ + +import Foundation + +struct Package { + + let dynamicLibraries: [String] + + func compile() { + let swiftC = runXCRun(tool: "swiftc") + + var args = [String]() + args += ["--driver-mode=swift"] // Eval in swift mode, I think? + + args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib + + args += libraryLinkingArguments() // link libraries + + args += ["-suppress-warnings"] // SPM does that too + args += ["Package.swift"] // The Package.swift in the CWD + + // Create a process to eval the Swift Package manifest as a subprocess + let proc = Process() + proc.launchPath = swiftC + proc.arguments = args + + debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") + + let standardOutput = FileHandle.standardOutput + proc.standardOutput = standardOutput + proc.standardError = standardOutput + + // Evaluation of the package swift code will end up + // creating a file in the tmpdir that stores the JSON + // settings when a new instance of PackageConfig is created + proc.launch() + proc.waitUntilExit() + + debugLog("Finished launching swiftc") + } + + func runXCRun(tool: String) -> String { + let proc = Process() + proc.launchPath = "/usr/bin/xcrun" + proc.arguments = ["--find", tool] + + debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") + + let pipe = Pipe() + proc.standardOutput = pipe + + proc.launch() + proc.waitUntilExit() + + let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! + return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) + } + + func libraryPath(for library: String) -> String? { + let fileManager = FileManager.default + let libPaths = [ + ".build/debug", + ".build/x86_64-unknown-linux/debug", + ".build/release", + ] + + func isLibPath(path: String) -> Bool { + return fileManager.fileExists(atPath: path + "/lib\(library).dylib") || // macOS + fileManager.fileExists(atPath: path + "/lib\(library).so") // Linux + } + + return libPaths.first(where: isLibPath) + } + + func libraryLinkingArguments() -> [String] { + return dynamicLibraries.map { libraryName in + guard let path = libraryPath(for: libraryName) else { + print("PackageConfig: Could not find lib\(libraryName) to link against, is it possible you've not built yet?") + exit(1) + } + + return [ + "-L", path, + "-I", path, + "-l\(libraryName)" + ] + }.reduce([], +) + } + + func getSwiftPMManifestArgs(swiftPath: String) -> [String] { + // using "xcrun --find swift" we get + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc + // we need to transform it to something like: + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 + let fileManager = FileManager.default + + let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") + let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) + // TODO: Handle the + // // swift-tools-version:4.2 + // declarations? + let latestSPM = versions.sorted().last! + let libraryPathSPM = swiftPMDir + "/" + latestSPM + + debugLog("Using SPM version: \(libraryPathSPM)") + return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] + } + +} diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift deleted file mode 100644 index bff1735..0000000 --- a/Sources/PackageConfig/PackageConfig.swift +++ /dev/null @@ -1,199 +0,0 @@ - -import Foundation -@_exported import TypePreservingCodingAdapter - -/// A facade to decorate any configurations we might think of -public struct PackageConfig { - - private let configurations: [PackageName: Aliased] - - public init(configurations: [PackageName: Aliased], adapter: TypePreservingCodingAdapter) { - self.configurations = configurations - write(adapter: adapter) - } - - /// Provides a specific package configuation by packageName - public subscript(package packageName: PackageName) -> Aliased? { - get { - return configurations[packageName] - } - } - - /// Loads the specific Configuration if capable - public static func load(_ packageName: PackageName, adapter: TypePreservingCodingAdapter) -> T? { - return read(adapter: adapter)?[package: packageName] as? T - } - - /// Loads the Configuration if capable - public static func load(_ adapter: TypePreservingCodingAdapter) -> PackageConfig? { - return read(adapter: adapter) - } -} - -extension PackageConfig: Codable { - - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - let keysAndValues = try container.decode([PackageName: Wrap].self).map { package, wrap in - (package, wrap.wrapped as! Aliased) - } - self.configurations = [PackageName: Aliased](uniqueKeysWithValues: keysAndValues) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - let wraps = [PackageName: Wrap](uniqueKeysWithValues: configurations.map { (package, configuration) in - (package, Wrap(wrapped: configuration, strategy: .alias)) - }) - try container.encode(wraps) - } -} - -extension PackageConfig { - - func write(adapter: TypePreservingCodingAdapter) { - let fileManager = FileManager.default - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" - let encoder = JSONEncoder() - encoder.userInfo[.typePreservingAdapter] = adapter - let data = try! encoder.encode(self) - - if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { - print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") - } - } - - /// Only prints when --verbose is in the arge, or when DEBUG exists - static func debugLog(_ message: String) -> Void { - let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) - if isVerbose { - print(message) - } - } - - /// Gets a config object from the user's Package.swift - /// by parsing the document by the same way that SwiftPM does it - /// - Returns: A dictionary of all settings - static func read(adapter: TypePreservingCodingAdapter) -> PackageConfig? { - let fileManager = FileManager.default - let swiftC = runXCRun(tool: "swiftc") - - var args = [String]() - args += ["--driver-mode=swift"] // Eval in swift mode, I think? - - args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib - args += getPackageConfigArgs() // This lib - - args += ["-suppress-warnings"] // SPM does that too - args += ["Package.swift"] // The Package.swift in the CWD - - // Create a process to eval the Swift Package manifest as a subprocess - let proc = Process() - proc.launchPath = swiftC - proc.arguments = args - - debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") - - let standardOutput = FileHandle.standardOutput - proc.standardOutput = standardOutput - proc.standardError = standardOutput - - // Evaluation of the package swift code will end up - // creating a file in the tmpdir that stores the JSON - // settings when a new instance of PackageConfig is created - - proc.launch() - proc.waitUntilExit() - - debugLog("Finished launching swiftc") - - // So read it - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" - - print(path) - - guard let data = fileManager.contents(atPath: packageConfigJSON) else { - // Package Manifest did not contain a config object at all - // so just return an empty dictionary - debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") - return nil - } - - debugLog("Got \(String(describing: String(data: data, encoding: .utf8)))") - - let decoder = JSONDecoder() - decoder.userInfo[.typePreservingAdapter] = adapter - - return try! decoder.decode(PackageConfig.self, from: data) - } - - /// Helper to run xcrun to get paths for things - static func runXCRun(tool: String) -> String { - let proc = Process() - proc.launchPath = "/usr/bin/xcrun" - proc.arguments = ["--find", tool] - - debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") - - let pipe = Pipe() - proc.standardOutput = pipe - - proc.launch() - proc.waitUntilExit() - - let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) - } - - // Finds args for the current version of Xcode's Swift Package Manager - static func getSwiftPMManifestArgs(swiftPath: String) -> [String] { - // using "xcrun --find swift" we get - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc - // we need to transform it to something like: - // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4_2 - let fileManager = FileManager.default - - let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") - let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) - // TODO: Handle the - // // swift-tools-version:4.2 - // declarations? - let latestSPM = versions.sorted().last! - let libraryPathSPM = swiftPMDir + "/" + latestSPM - - debugLog("Using SPM version: \(libraryPathSPM)") - return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] - } - - /// Finds a path to add at runtime to the compiler, which links - /// to the library Danger - static func getLibPackageConfigPath() -> String? { - let fileManager = FileManager.default - - // Check and find where we can link to libDanger from - let libPaths = [ - ".build/debug", // Working in Xcode / CLI - ".build/x86_64-unknown-linux/debug", // Danger Swift's CI - ".build/release", // Testing prod - ] - - func isTheDangerLibPath(path: String) -> Bool { - return fileManager.fileExists(atPath: path + "/libPackageConfig.dylib") || // OSX - fileManager.fileExists(atPath: path + "/libPackageConfig.so") // Linux - } - - return libPaths.first(where: isTheDangerLibPath) - } - - - /// Finds args for the locally built copy of PackageConfig - static func getPackageConfigArgs() -> [String] { - guard let libPackageConfig = getLibPackageConfigPath() else { - print("PackageConfig: Could not find a libPackageConfig to link against, is it possible you've not built yet?") - exit(1) - } - return ["-L", libPackageConfig, "-I", libPackageConfig, "-lPackageConfig"] - } -} diff --git a/Sources/PackageConfig/PackageName.swift b/Sources/PackageConfig/PackageName.swift deleted file mode 100644 index 343ad79..0000000 --- a/Sources/PackageConfig/PackageName.swift +++ /dev/null @@ -1,25 +0,0 @@ - -public struct PackageName: ExpressibleByStringLiteral, Codable, Hashable, Equatable { - - public typealias StringLiteralType = String - - private let name: String - - public init(_ name: String) { - self.name = name - } - - public init(stringLiteral name: String) { - self.name = name - } - - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - self.name = try container.decode(String.self) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(name) - } -} diff --git a/Sources/PackageConfig/Writer.swift b/Sources/PackageConfig/Writer.swift new file mode 100644 index 0000000..117237f --- /dev/null +++ b/Sources/PackageConfig/Writer.swift @@ -0,0 +1,18 @@ + +import Foundation + +enum Writer { + + static func write(configuration: T) { //}, adapter: TypePreservingCodingAdapter) { + let fileManager = FileManager.default + let path = NSTemporaryDirectory() + let packageConfigJSON = path + "package-config.json" + let encoder = JSONEncoder() +// encoder.userInfo[.typePreservingAdapter] = adapter + let data = try! encoder.encode(configuration) + + if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { + print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") + } + } +} From 1f28c472cd62ccacf14517faaf0dd050b1a1a0e5 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 19:55:14 +0200 Subject: [PATCH 14/41] minor improvements --- Package.swift | 2 +- Sources/Example/main.swift | 4 +- Sources/PackageConfig/Configuration.swift | 53 ------------------- ...onfiguration.swift => ExampleConfig.swift} | 2 +- Sources/PackageConfig/Loader.swift | 5 +- Sources/PackageConfig/Package.swift | 4 +- Sources/PackageConfig/PackageConfig.swift | 29 ++++++++++ Sources/PackageConfig/Writer.swift | 11 ++-- 8 files changed, 41 insertions(+), 69 deletions(-) delete mode 100644 Sources/PackageConfig/Configuration.swift rename Sources/PackageConfig/{ExampleConfiguration.swift => ExampleConfig.swift} (68%) create mode 100644 Sources/PackageConfig/PackageConfig.swift diff --git a/Package.swift b/Package.swift index e856409..f472863 100644 --- a/Package.swift +++ b/Package.swift @@ -25,6 +25,6 @@ let package = Package( #if canImport(PackageConfig) import PackageConfig -ExampleConfiguration(value: "lol kek").write() +ExampleConfig(value: "example value").write() #endif diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index 13fbca3..e11289b 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,6 +1,6 @@ import PackageConfig -let example = ExampleConfiguration.load() +let example = ExampleConfig.load() -print(example) +print(example!) diff --git a/Sources/PackageConfig/Configuration.swift b/Sources/PackageConfig/Configuration.swift deleted file mode 100644 index 873efc8..0000000 --- a/Sources/PackageConfig/Configuration.swift +++ /dev/null @@ -1,53 +0,0 @@ - -public protocol Configuration: Codable { - - static var dynamicLibraries: [String] { get } - - static func load() -> Self? - func write() -} - -extension Configuration { - - public static func load() -> Self? { - Package(dynamicLibraries: dynamicLibraries + ["PackageConfig"]).compile() - return Loader.load() - } - - public func write() { - Writer.write(configuration: self) - } -} - -import Foundation - -func debugLog(_ message: String) -> Void { - let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) - if isVerbose { - print(message) - } -} - -/* - - - So about how it should work. - - Dependency should conform to dependency and the all of its methods should be available for it. - So when executing the dependency like this `swift run yourDependency`. - It will Compile Package.swift dynamically injecting itself and this dependency as linked libraries. - - So when declarin the dependency configuration one would do as follows: - - #if canImport(YourDependency) - import YourDependency - - DependencyConfiguration().write() - - #endif - - Then in the dependency itself you can load configuration whenever by doing this: - - DependencyConfiguration().load() - -*/ diff --git a/Sources/PackageConfig/ExampleConfiguration.swift b/Sources/PackageConfig/ExampleConfig.swift similarity index 68% rename from Sources/PackageConfig/ExampleConfiguration.swift rename to Sources/PackageConfig/ExampleConfig.swift index 87e7fc4..0c5cf42 100644 --- a/Sources/PackageConfig/ExampleConfiguration.swift +++ b/Sources/PackageConfig/ExampleConfig.swift @@ -1,5 +1,5 @@ -public struct ExampleConfiguration: Codable, Configuration { +public struct ExampleConfig: Codable, PackageConfig { let value: String diff --git a/Sources/PackageConfig/Loader.swift b/Sources/PackageConfig/Loader.swift index a2f887b..342d293 100644 --- a/Sources/PackageConfig/Loader.swift +++ b/Sources/PackageConfig/Loader.swift @@ -2,9 +2,8 @@ import Foundation enum Loader { - static func load() -> T? { - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" + static func load() -> T? { + let packageConfigJSON = NSTemporaryDirectory() + "package-config.json" guard let data = FileManager.default.contents(atPath: packageConfigJSON) else { debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") diff --git a/Sources/PackageConfig/Package.swift b/Sources/PackageConfig/Package.swift index f1fe951..29e040d 100644 --- a/Sources/PackageConfig/Package.swift +++ b/Sources/PackageConfig/Package.swift @@ -95,9 +95,7 @@ struct Package { let swiftPMDir = swiftPath.replacingOccurrences(of: "bin/swiftc", with: "lib/swift/pm") let versions = try! fileManager.contentsOfDirectory(atPath: swiftPMDir) - // TODO: Handle the - // // swift-tools-version:4.2 - // declarations? + #warning("TODO: handle //swift-tools-version:4.2 declarations") let latestSPM = versions.sorted().last! let libraryPathSPM = swiftPMDir + "/" + latestSPM diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift new file mode 100644 index 0000000..e7beb48 --- /dev/null +++ b/Sources/PackageConfig/PackageConfig.swift @@ -0,0 +1,29 @@ + +public protocol PackageConfig: Codable { + + static var dynamicLibraries: [String] { get } + + static func load() -> Self? + func write() +} + +extension PackageConfig { + + public static func load() -> Self? { + Package(dynamicLibraries: dynamicLibraries + ["PackageConfig"]).compile() + return Loader.load() + } + + public func write() { + Writer.write(configuration: self) + } +} + +import Foundation + +func debugLog(_ message: String) -> Void { + let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) + if isVerbose { + print(message) + } +} diff --git a/Sources/PackageConfig/Writer.swift b/Sources/PackageConfig/Writer.swift index 117237f..da2c50c 100644 --- a/Sources/PackageConfig/Writer.swift +++ b/Sources/PackageConfig/Writer.swift @@ -3,16 +3,15 @@ import Foundation enum Writer { - static func write(configuration: T) { //}, adapter: TypePreservingCodingAdapter) { - let fileManager = FileManager.default - let path = NSTemporaryDirectory() - let packageConfigJSON = path + "package-config.json" + static func write(configuration: T) { + let packageConfigJSON = NSTemporaryDirectory() + "package-config.json" let encoder = JSONEncoder() -// encoder.userInfo[.typePreservingAdapter] = adapter let data = try! encoder.encode(configuration) - if !fileManager.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { + if !FileManager.default.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") } + + debugLog("written to path: \(packageConfigJSON)") } } From a0880c2a32611646fc09b21eeb192fe173848205 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 20:13:31 +0200 Subject: [PATCH 15/41] Updated README.md --- README.md | 97 +++++++++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 33144fc..867157f 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,73 @@ # PackageConfig -A Swift Package that allows you to define configuration settings inside a `Package.swift` - this is so that tools can all keep their configs consolidated inside a single place. Tool builders use this dependency to grab their config settings. +A Swift Package that allows you to define configuration settings inside a `Package.swift` - this is so that tools can all keep their configs consolidated inside a single place. -### User writes: - -```swift -// swift-tools-version:4.0 -import PackageDescription +Tool builders use this dependency to grab their config settings. -// Traditional Package.swift - -let package = Package( - name: "danger-swift", - // ... - swiftLanguageVersions: [4] -) +### User writes: -// Config lives under the package +At the very bottom of the `Package.swift` -#if canImport(PackageConfig) && canImport(YourPackage) -import PackageConfig -import YourPackage +```swift +#if canImport(ExampleConfig) +import ExampleConfig -let adapter = TypePreservingCodingAdapter() -let config = PackageConfig( - configurations: [ - .yourPackageName: YourPackageConfig(info: ["this", "and", "that", "whatever"]), - ], - adapter: TypePreservingCodingAdapter() - .register(aliase: YourPackageConfig.self) -) +ExampleConfig(value: "example value").write() #endif ``` ### Tool-dev writes: -Add this library to your tool's `Package.swift`: +For the sake of example lets assume your library is called Example then `Package.swift` would look like this: -```diff +```swift let package = Package( - name: "danger-swift", + name: "Example", products: [ - .library(name: "Danger", type: .dynamic, targets: ["Danger"]), - .executable(name: "danger-swift", targets: ["Runner"]) + // notice that library product with your config should be dynamic + .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), + .executable(name: "example", targets: ["Example"]), ], dependencies: [ - .package(url: "https://github.com/JohnSundell/Marathon.git", from: "3.1.0"), - .package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.1.0"), -+ .package(url: "https://github.com/orta/PackageConfig.git", from: "0.0.1"), + .package(url: "https://github.com/orta/PackageConfig.git", from: "0.0.2"), ], targets: [ - .target(name: "Danger", dependencies: ["ShellOut"]), -- .target(name: "Runner", dependencies: ["Danger", "MarathonCore"]), -+ .target(name: "Runner", dependencies: ["Danger", "MarathonCore", "PackageConfig"]), - .testTarget(name: "DangerTests", dependencies: ["Danger"]), - ], + .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), + .target(name: "Example", dependencies: ["ExampleConfig"]), + ] ) ``` -Define your Configuration and extend PackageName with your package name: +In your `ExampleConfig` target define `ExampleConfig` like this. ```swift import PackageConfig -// Define your config type. -// Just an example, it can be watever you want as long as it's `Codable`. -// It must conform to `Aliased` and provide an alias. -public struct YourPackageConfig: Aliased { - - public let info: [String] - public static var alias: Alias = "YourPackageConfig" // alias to preserve type when coding - - public init(info: [String]) { - self.info = info - } -} +// it must be public for you to use in your executable target +// also you must conform to Codable and PackageConfig +public struct ExampleConfig: Codable, PackageConfig { + + // here can be whatever you want as long as your config can stay `Codable` + let value: String -// Define your `PackageName` to make it possible to register and get the config by it in PackageConfig. -extension PackageName { + // here you define a name of ExampleConfig dynamic library product + public static var dynamicLibraries: [String] = ["ExampleConfig"] - public static var yourPackageName: PackageName = "YourPackageName" + // public init is also a requirement + public init(value: String) { + self.value = value + } } + + ``` -To grab your configuration: +Then in your `main.swift` in `Example` target you can load your config like this: ```swift -import PackageConfig - -let adapter = TypePreservingCodingAdapter() - .register(aliased: YourPackageConfig.self) -let yourConfig: YourPackageConfig? = PackageConfig.load(.yourPackageName, adapter: adapter) +import ExampleConfig -print(yourConfig!) +let config = ExampleConfig.load() ``` ---- From 42f744c946f4141f4ac7c3d27c9132db2a14435a Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 20:13:59 +0200 Subject: [PATCH 16/41] Removed xcodeproj and Test folder; generate Xcode project using swift package generate-xcodeproj --- .../PackageConfigTests_Info.plist | 25 - .../PackageConfig_Info.plist | 25 - PackageConfig.xcodeproj/project.pbxproj | 758 ------------------ .../contents.xcworkspacedata | 7 - .../xcshareddata/IDEWorkspaceChecks.plist | 8 - .../xcshareddata/WorkspaceSettings.xcsettings | 8 - .../xcshareddata/xcschemes/Example.xcscheme | 82 -- .../xcschemes/PackageConfig-Package.xcscheme | 95 --- Tests/LinuxMain.swift | 7 - .../PackageConfigTests.swift | 15 - .../PackageConfigTests/XCTestManifests.swift | 9 - 11 files changed, 1039 deletions(-) delete mode 100644 PackageConfig.xcodeproj/PackageConfigTests_Info.plist delete mode 100644 PackageConfig.xcodeproj/PackageConfig_Info.plist delete mode 100644 PackageConfig.xcodeproj/project.pbxproj delete mode 100644 PackageConfig.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings delete mode 100644 PackageConfig.xcodeproj/xcshareddata/xcschemes/Example.xcscheme delete mode 100644 PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme delete mode 100644 Tests/LinuxMain.swift delete mode 100644 Tests/PackageConfigTests/PackageConfigTests.swift delete mode 100644 Tests/PackageConfigTests/XCTestManifests.swift diff --git a/PackageConfig.xcodeproj/PackageConfigTests_Info.plist b/PackageConfig.xcodeproj/PackageConfigTests_Info.plist deleted file mode 100644 index 7c23420..0000000 --- a/PackageConfig.xcodeproj/PackageConfigTests_Info.plist +++ /dev/null @@ -1,25 +0,0 @@ - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/PackageConfig.xcodeproj/PackageConfig_Info.plist b/PackageConfig.xcodeproj/PackageConfig_Info.plist deleted file mode 100644 index 57ada9f..0000000 --- a/PackageConfig.xcodeproj/PackageConfig_Info.plist +++ /dev/null @@ -1,25 +0,0 @@ - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/PackageConfig.xcodeproj/project.pbxproj b/PackageConfig.xcodeproj/project.pbxproj deleted file mode 100644 index 02262a3..0000000 --- a/PackageConfig.xcodeproj/project.pbxproj +++ /dev/null @@ -1,758 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = "1"; - objectVersion = "46"; - objects = { - "OBJ_1" = { - isa = "PBXProject"; - attributes = { - LastUpgradeCheck = "9999"; - }; - buildConfigurationList = "OBJ_2"; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = "English"; - hasScannedForEncodings = "0"; - knownRegions = ( - "en" - ); - mainGroup = "OBJ_5"; - productRefGroup = "OBJ_20"; - projectDirPath = "."; - targets = ( - "PackageConfig::Example", - "PackageConfig::PackageConfig", - "PackageConfig::SwiftPMPackageDescription", - "PackageConfig::PackageConfigPackageTests::ProductTarget", - "PackageConfig::PackageConfigTests", - "PackageConfig::package-config-example::ProductTarget" - ); - }; - "OBJ_10" = { - isa = "PBXFileReference"; - path = "ExampleConfiguration.swift"; - sourceTree = ""; - }; - "OBJ_11" = { - isa = "PBXFileReference"; - path = "Loader.swift"; - sourceTree = ""; - }; - "OBJ_12" = { - isa = "PBXFileReference"; - path = "Package.swift"; - sourceTree = ""; - }; - "OBJ_13" = { - isa = "PBXFileReference"; - path = "Writer.swift"; - sourceTree = ""; - }; - "OBJ_14" = { - isa = "PBXGroup"; - children = ( - "OBJ_15" - ); - name = "Example"; - path = "Sources/Example"; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_15" = { - isa = "PBXFileReference"; - path = "main.swift"; - sourceTree = ""; - }; - "OBJ_16" = { - isa = "PBXGroup"; - children = ( - "OBJ_17" - ); - name = "Tests"; - path = ""; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_17" = { - isa = "PBXGroup"; - children = ( - "OBJ_18", - "OBJ_19" - ); - name = "PackageConfigTests"; - path = "Tests/PackageConfigTests"; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_18" = { - isa = "PBXFileReference"; - path = "PackageConfigTests.swift"; - sourceTree = ""; - }; - "OBJ_19" = { - isa = "PBXFileReference"; - path = "XCTestManifests.swift"; - sourceTree = ""; - }; - "OBJ_2" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_3", - "OBJ_4" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_20" = { - isa = "PBXGroup"; - children = ( - "PackageConfig::Example::Product", - "PackageConfig::PackageConfigTests::Product", - "PackageConfig::PackageConfig::Product" - ); - name = "Products"; - path = ""; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "OBJ_25" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_26", - "OBJ_27" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_26" = { - isa = "XCBuildConfiguration"; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "PackageConfig.xcodeproj/Example_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", - "@executable_path" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_FORCE_DYNAMIC_LINK_STDLIB = "YES"; - SWIFT_FORCE_STATIC_LINK_STDLIB = "NO"; - SWIFT_VERSION = "4.2"; - TARGET_NAME = "Example"; - }; - name = "Debug"; - }; - "OBJ_27" = { - isa = "XCBuildConfiguration"; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "PackageConfig.xcodeproj/Example_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx", - "@executable_path" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_FORCE_DYNAMIC_LINK_STDLIB = "YES"; - SWIFT_FORCE_STATIC_LINK_STDLIB = "NO"; - SWIFT_VERSION = "4.2"; - TARGET_NAME = "Example"; - }; - name = "Release"; - }; - "OBJ_28" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_29" - ); - }; - "OBJ_29" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_15"; - }; - "OBJ_3" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = "YES"; - COMBINE_HIDPI_IMAGES = "YES"; - COPY_PHASE_STRIP = "NO"; - DEBUG_INFORMATION_FORMAT = "dwarf"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_NS_ASSERTIONS = "YES"; - GCC_OPTIMIZATION_LEVEL = "0"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)" - ); - MACOSX_DEPLOYMENT_TARGET = "10.10"; - ONLY_ACTIVE_ARCH = "YES"; - OTHER_SWIFT_FLAGS = ( - "-DXcode" - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = "macosx"; - SUPPORTED_PLATFORMS = ( - "macosx", - "iphoneos", - "iphonesimulator", - "appletvos", - "appletvsimulator", - "watchos", - "watchsimulator" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "SWIFT_PACKAGE", - "DEBUG" - ); - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - USE_HEADERMAP = "NO"; - }; - name = "Debug"; - }; - "OBJ_30" = { - isa = "PBXFrameworksBuildPhase"; - files = ( - "OBJ_31" - ); - }; - "OBJ_31" = { - isa = "PBXBuildFile"; - fileRef = "PackageConfig::PackageConfig::Product"; - }; - "OBJ_32" = { - isa = "PBXTargetDependency"; - target = "PackageConfig::PackageConfig"; - }; - "OBJ_34" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_35", - "OBJ_36" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_35" = { - isa = "XCBuildConfiguration"; - buildSettings = { - ENABLE_TESTABILITY = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfig_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - PRODUCT_BUNDLE_IDENTIFIER = "PackageConfig"; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = "YES"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "PackageConfig"; - }; - name = "Debug"; - }; - "OBJ_36" = { - isa = "XCBuildConfiguration"; - buildSettings = { - ENABLE_TESTABILITY = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfig_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - PRODUCT_BUNDLE_IDENTIFIER = "PackageConfig"; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = "YES"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "PackageConfig"; - }; - name = "Release"; - }; - "OBJ_37" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_38", - "OBJ_39", - "OBJ_40", - "OBJ_41", - "OBJ_42" - ); - }; - "OBJ_38" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_9"; - }; - "OBJ_39" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_10"; - }; - "OBJ_4" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = "YES"; - COMBINE_HIDPI_IMAGES = "YES"; - COPY_PHASE_STRIP = "YES"; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_OPTIMIZATION_LEVEL = "s"; - MACOSX_DEPLOYMENT_TARGET = "10.10"; - OTHER_SWIFT_FLAGS = ( - "-DXcode" - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = "macosx"; - SUPPORTED_PLATFORMS = ( - "macosx", - "iphoneos", - "iphonesimulator", - "appletvos", - "appletvsimulator", - "watchos", - "watchsimulator" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "SWIFT_PACKAGE" - ); - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - USE_HEADERMAP = "NO"; - }; - name = "Release"; - }; - "OBJ_40" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_11"; - }; - "OBJ_41" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_12"; - }; - "OBJ_42" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_13"; - }; - "OBJ_43" = { - isa = "PBXFrameworksBuildPhase"; - files = ( - ); - }; - "OBJ_45" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_46", - "OBJ_47" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_46" = { - isa = "XCBuildConfiguration"; - buildSettings = { - LD = "/usr/bin/true"; - OTHER_SWIFT_FLAGS = ( - "-swift-version", - "4.2", - "-I", - "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", - "-target", - "x86_64-apple-macosx10.10", - "-sdk", - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" - ); - SWIFT_VERSION = "4.2"; - }; - name = "Debug"; - }; - "OBJ_47" = { - isa = "XCBuildConfiguration"; - buildSettings = { - LD = "/usr/bin/true"; - OTHER_SWIFT_FLAGS = ( - "-swift-version", - "4.2", - "-I", - "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", - "-target", - "x86_64-apple-macosx10.10", - "-sdk", - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" - ); - SWIFT_VERSION = "4.2"; - }; - name = "Release"; - }; - "OBJ_48" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_49" - ); - }; - "OBJ_49" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_6"; - }; - "OBJ_5" = { - isa = "PBXGroup"; - children = ( - "OBJ_6", - "OBJ_7", - "OBJ_16", - "OBJ_20" - ); - path = ""; - sourceTree = ""; - }; - "OBJ_51" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_52", - "OBJ_53" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_52" = { - isa = "XCBuildConfiguration"; - buildSettings = { - }; - name = "Debug"; - }; - "OBJ_53" = { - isa = "XCBuildConfiguration"; - buildSettings = { - }; - name = "Release"; - }; - "OBJ_54" = { - isa = "PBXTargetDependency"; - target = "PackageConfig::PackageConfigTests"; - }; - "OBJ_56" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_57", - "OBJ_58" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_57" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_MODULES = "YES"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfigTests_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@loader_path/../Frameworks", - "@loader_path/Frameworks" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "PackageConfigTests"; - }; - name = "Debug"; - }; - "OBJ_58" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_MODULES = "YES"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "PackageConfig.xcodeproj/PackageConfigTests_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@loader_path/../Frameworks", - "@loader_path/Frameworks" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "PackageConfigTests"; - }; - name = "Release"; - }; - "OBJ_59" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_60", - "OBJ_61" - ); - }; - "OBJ_6" = { - isa = "PBXFileReference"; - explicitFileType = "sourcecode.swift"; - path = "Package.swift"; - sourceTree = ""; - }; - "OBJ_60" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_18"; - }; - "OBJ_61" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_19"; - }; - "OBJ_62" = { - isa = "PBXFrameworksBuildPhase"; - files = ( - "OBJ_63" - ); - }; - "OBJ_63" = { - isa = "PBXBuildFile"; - fileRef = "PackageConfig::PackageConfig::Product"; - }; - "OBJ_64" = { - isa = "PBXTargetDependency"; - target = "PackageConfig::PackageConfig"; - }; - "OBJ_66" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_67", - "OBJ_68" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_67" = { - isa = "XCBuildConfiguration"; - buildSettings = { - }; - name = "Debug"; - }; - "OBJ_68" = { - isa = "XCBuildConfiguration"; - buildSettings = { - }; - name = "Release"; - }; - "OBJ_69" = { - isa = "PBXTargetDependency"; - target = "PackageConfig::Example"; - }; - "OBJ_7" = { - isa = "PBXGroup"; - children = ( - "OBJ_8", - "OBJ_14" - ); - name = "Sources"; - path = ""; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_8" = { - isa = "PBXGroup"; - children = ( - "OBJ_9", - "OBJ_10", - "OBJ_11", - "OBJ_12", - "OBJ_13" - ); - name = "PackageConfig"; - path = "Sources/PackageConfig"; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_9" = { - isa = "PBXFileReference"; - path = "Configuration.swift"; - sourceTree = ""; - }; - "PackageConfig::Example" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_25"; - buildPhases = ( - "OBJ_28", - "OBJ_30" - ); - dependencies = ( - "OBJ_32" - ); - name = "Example"; - productName = "Example"; - productReference = "PackageConfig::Example::Product"; - productType = "com.apple.product-type.tool"; - }; - "PackageConfig::Example::Product" = { - isa = "PBXFileReference"; - path = "Example"; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "PackageConfig::PackageConfig" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_34"; - buildPhases = ( - "OBJ_37", - "OBJ_43" - ); - dependencies = ( - ); - name = "PackageConfig"; - productName = "PackageConfig"; - productReference = "PackageConfig::PackageConfig::Product"; - productType = "com.apple.product-type.framework"; - }; - "PackageConfig::PackageConfig::Product" = { - isa = "PBXFileReference"; - path = "PackageConfig.framework"; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "PackageConfig::PackageConfigPackageTests::ProductTarget" = { - isa = "PBXAggregateTarget"; - buildConfigurationList = "OBJ_51"; - buildPhases = ( - ); - dependencies = ( - "OBJ_54" - ); - name = "PackageConfigPackageTests"; - productName = "PackageConfigPackageTests"; - }; - "PackageConfig::PackageConfigTests" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_56"; - buildPhases = ( - "OBJ_59", - "OBJ_62" - ); - dependencies = ( - "OBJ_64" - ); - name = "PackageConfigTests"; - productName = "PackageConfigTests"; - productReference = "PackageConfig::PackageConfigTests::Product"; - productType = "com.apple.product-type.bundle.unit-test"; - }; - "PackageConfig::PackageConfigTests::Product" = { - isa = "PBXFileReference"; - path = "PackageConfigTests.xctest"; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "PackageConfig::SwiftPMPackageDescription" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_45"; - buildPhases = ( - "OBJ_48" - ); - dependencies = ( - ); - name = "PackageConfigPackageDescription"; - productName = "PackageConfigPackageDescription"; - productType = "com.apple.product-type.framework"; - }; - "PackageConfig::package-config-example::ProductTarget" = { - isa = "PBXAggregateTarget"; - buildConfigurationList = "OBJ_66"; - buildPhases = ( - ); - dependencies = ( - "OBJ_69" - ); - name = "package-config-example"; - productName = "package-config-example"; - }; - }; - rootObject = "OBJ_1"; -} diff --git a/PackageConfig.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PackageConfig.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index fe1aa71..0000000 --- a/PackageConfig.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings deleted file mode 100644 index a72dc2b..0000000 --- a/PackageConfig.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded - - - \ No newline at end of file diff --git a/PackageConfig.xcodeproj/xcshareddata/xcschemes/Example.xcscheme b/PackageConfig.xcodeproj/xcshareddata/xcschemes/Example.xcscheme deleted file mode 100644 index 636d22a..0000000 --- a/PackageConfig.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme b/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme deleted file mode 100644 index 8a06f84..0000000 --- a/PackageConfig.xcodeproj/xcshareddata/xcschemes/PackageConfig-Package.xcscheme +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index 0a5efc7..0000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,7 +0,0 @@ -import XCTest - -import PackageConfigTests - -var tests = [XCTestCaseEntry]() -tests += PackageConfigTests.allTests() -XCTMain(tests) \ No newline at end of file diff --git a/Tests/PackageConfigTests/PackageConfigTests.swift b/Tests/PackageConfigTests/PackageConfigTests.swift deleted file mode 100644 index 52f9359..0000000 --- a/Tests/PackageConfigTests/PackageConfigTests.swift +++ /dev/null @@ -1,15 +0,0 @@ -import XCTest -@testable import PackageConfig - -final class PackageConfigTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(PackageConfig().text, "Hello, World!") - } - - static var allTests = [ - ("testExample", testExample), - ] -} diff --git a/Tests/PackageConfigTests/XCTestManifests.swift b/Tests/PackageConfigTests/XCTestManifests.swift deleted file mode 100644 index 9577b2f..0000000 --- a/Tests/PackageConfigTests/XCTestManifests.swift +++ /dev/null @@ -1,9 +0,0 @@ -import XCTest - -#if !os(macOS) -public func allTests() -> [XCTestCaseEntry] { - return [ - testCase(PackageConfigTests.allTests), - ] -} -#endif \ No newline at end of file From b5fcfa1a87129fc5fba4b18aafcf835506beed04 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 20:15:45 +0200 Subject: [PATCH 17/41] Removed test target from Package.swift --- Package.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Package.swift b/Package.swift index f472863..8d95ab8 100644 --- a/Package.swift +++ b/Package.swift @@ -17,8 +17,6 @@ let package = Package( // The app I use to verify it all works .target(name: "Example", dependencies: ["PackageConfig"]), - // Not used - .testTarget(name: "PackageConfigTests", dependencies: ["PackageConfig"]), ] ) From a1dd45c194ce1d853de12448200d7858a0e0c998 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 20:16:29 +0200 Subject: [PATCH 18/41] Updated README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 867157f..f00bbc2 100644 --- a/README.md +++ b/README.md @@ -115,11 +115,11 @@ And grab the bit out after the first sandbox. I then changed the final arg to `- I run this command: ```sh -swift build; env DEBUG="*" ./.build/x86_64-apple-macosx10.10/debug/package-config-example +swift build; env DEBUG="*" swift run package-config-example ``` if you don't use fish: ```sh -swift build; DEBUG="*" ./.build/x86_64-apple-macosx10.10/debug/package-config-example +swift build; DEBUG="*" swift run package-config-example ``` From 34aae32910524c48749c981f3c245bea6da8fd6d Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sat, 16 Mar 2019 20:38:25 +0200 Subject: [PATCH 19/41] Added /*.xcodeproj to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 98d68cc..9fce9ac 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ DerivedData/ *.perspectivev3 !default.perspectivev3 xcuserdata/ +/*.xcodeproj ## Other *.moved-aside From 03bd4969e26786c9f28205e6c02a852da217cf3a Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 06:20:56 +0200 Subject: [PATCH 20/41] Unmade PackageConfig a dynamic library --- Package.swift | 13 +++++++------ Sources/Example/main.swift | 4 ++-- .../ExampleConfig.swift | 5 ++++- Sources/PackageConfig/Loader.swift | 2 ++ Sources/PackageConfig/Package.swift | 7 +++++++ Sources/PackageConfig/PackageConfig.swift | 2 +- 6 files changed, 23 insertions(+), 10 deletions(-) rename Sources/{PackageConfig => ExampleConfig}/ExampleConfig.swift (55%) diff --git a/Package.swift b/Package.swift index 8d95ab8..abdcee3 100644 --- a/Package.swift +++ b/Package.swift @@ -6,22 +6,23 @@ import PackageDescription let package = Package( name: "PackageConfig", products: [ - .library(name: "PackageConfig", type: .dynamic, targets: ["PackageConfig"]), + .library(name: "PackageConfig", targets: ["PackageConfig"]), + + .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), .executable(name: "package-config-example", targets: ["Example"]) ], dependencies: [ ], targets: [ - // The lib .target(name: "PackageConfig", dependencies: []), - // The app I use to verify it all works - .target(name: "Example", dependencies: ["PackageConfig"]), + .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), + .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig"]), ] ) -#if canImport(PackageConfig) -import PackageConfig +#if canImport(ExampleConfig) +import ExampleConfig ExampleConfig(value: "example value").write() diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index e11289b..cfa2004 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,6 +1,6 @@ -import PackageConfig +import ExampleConfig let example = ExampleConfig.load() -print(example!) +print(example) diff --git a/Sources/PackageConfig/ExampleConfig.swift b/Sources/ExampleConfig/ExampleConfig.swift similarity index 55% rename from Sources/PackageConfig/ExampleConfig.swift rename to Sources/ExampleConfig/ExampleConfig.swift index 0c5cf42..176d755 100644 --- a/Sources/PackageConfig/ExampleConfig.swift +++ b/Sources/ExampleConfig/ExampleConfig.swift @@ -1,9 +1,12 @@ +import Foundation +import PackageConfig + public struct ExampleConfig: Codable, PackageConfig { let value: String - public static var dynamicLibraries: [String] = [] + public static var dynamicLibraries: [String] = ["ExampleConfig"] public init(value: String) { self.value = value diff --git a/Sources/PackageConfig/Loader.swift b/Sources/PackageConfig/Loader.swift index 342d293..967a3df 100644 --- a/Sources/PackageConfig/Loader.swift +++ b/Sources/PackageConfig/Loader.swift @@ -5,6 +5,8 @@ enum Loader { static func load() -> T? { let packageConfigJSON = NSTemporaryDirectory() + "package-config.json" + print(packageConfigJSON) + guard let data = FileManager.default.contents(atPath: packageConfigJSON) else { debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") return nil diff --git a/Sources/PackageConfig/Package.swift b/Sources/PackageConfig/Package.swift index 29e040d..af56baa 100644 --- a/Sources/PackageConfig/Package.swift +++ b/Sources/PackageConfig/Package.swift @@ -23,12 +23,17 @@ struct Package { proc.launchPath = swiftC proc.arguments = args + print(args) + debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") let standardOutput = FileHandle.standardOutput proc.standardOutput = standardOutput proc.standardError = standardOutput + + + // Evaluation of the package swift code will end up // creating a file in the tmpdir that stores the JSON // settings when a new instance of PackageConfig is created @@ -63,6 +68,8 @@ struct Package { ".build/release", ] + #warning("needs to be improved") + func isLibPath(path: String) -> Bool { return fileManager.fileExists(atPath: path + "/lib\(library).dylib") || // macOS fileManager.fileExists(atPath: path + "/lib\(library).so") // Linux diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index e7beb48..ed5b256 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -10,7 +10,7 @@ public protocol PackageConfig: Codable { extension PackageConfig { public static func load() -> Self? { - Package(dynamicLibraries: dynamicLibraries + ["PackageConfig"]).compile() + Package(dynamicLibraries: dynamicLibraries).compile() return Loader.load() } From 66f55d225c538fcc21b764b4b12475f331b0d296 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 07:23:40 +0200 Subject: [PATCH 21/41] Added executable package-config which would generate the directory for PackageConfigs target and build it to have listed dependencies dylibs also build --- Package.swift | 14 ++++++++------ Sources/Executable/main.swift | 17 +++++++++++++++++ Sources/{PackageConfig => Library}/Loader.swift | 0 .../{PackageConfig => Library}/Package.swift | 0 .../PackageConfig.swift | 0 Sources/{PackageConfig => Library}/Writer.swift | 0 .../PackageDependencies.swift | 0 7 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 Sources/Executable/main.swift rename Sources/{PackageConfig => Library}/Loader.swift (100%) rename Sources/{PackageConfig => Library}/Package.swift (100%) rename Sources/{PackageConfig => Library}/PackageConfig.swift (100%) rename Sources/{PackageConfig => Library}/Writer.swift (100%) create mode 100644 Sources/PackageDependencies/PackageDependencies.swift diff --git a/Package.swift b/Package.swift index abdcee3..cbf227b 100644 --- a/Package.swift +++ b/Package.swift @@ -6,18 +6,20 @@ import PackageDescription let package = Package( name: "PackageConfig", products: [ - .library(name: "PackageConfig", targets: ["PackageConfig"]), + .library(name: "PackageConfig", targets: ["Library"]), + .executable(name: "package-config", targets: ["Executable"]), .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), - .executable(name: "package-config-example", targets: ["Example"]) + .executable(name: "package-config-example", targets: ["Example"]) ], dependencies: [ - ], + ], targets: [ - .target(name: "PackageConfig", dependencies: []), + .target(name: "Library", dependencies: []), + .target(name: "Executable", dependencies: []), - .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), - .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig"]), + .target(name: "ExampleConfig", dependencies: ["Library"]), + .target(name: "Example", dependencies: ["Library", "ExampleConfig"]), ] ) diff --git a/Sources/Executable/main.swift b/Sources/Executable/main.swift new file mode 100644 index 0000000..9d7e2aa --- /dev/null +++ b/Sources/Executable/main.swift @@ -0,0 +1,17 @@ + +import Foundation + +let process = Process() +let script = +""" +swift build --target PackageConfigs +mkdir -p ./Sources/PackageConfigs/ +touch ./Sources/PackageConfigs/PackageConfigs.swift +echo '// Do not delete this file or it's target, it is requried to build dylibs for the Packages you installed which depend on PackageConfig for their own package configuration' > ./Sources/PackageConfigs/PackageConfigs.swift + +""" + +process.launchPath = "/bin/bash" +process.arguments = ["-c", script] +process.launch() +process.waitUntilExit() diff --git a/Sources/PackageConfig/Loader.swift b/Sources/Library/Loader.swift similarity index 100% rename from Sources/PackageConfig/Loader.swift rename to Sources/Library/Loader.swift diff --git a/Sources/PackageConfig/Package.swift b/Sources/Library/Package.swift similarity index 100% rename from Sources/PackageConfig/Package.swift rename to Sources/Library/Package.swift diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/Library/PackageConfig.swift similarity index 100% rename from Sources/PackageConfig/PackageConfig.swift rename to Sources/Library/PackageConfig.swift diff --git a/Sources/PackageConfig/Writer.swift b/Sources/Library/Writer.swift similarity index 100% rename from Sources/PackageConfig/Writer.swift rename to Sources/Library/Writer.swift diff --git a/Sources/PackageDependencies/PackageDependencies.swift b/Sources/PackageDependencies/PackageDependencies.swift new file mode 100644 index 0000000..e69de29 From f8c766d2a6d8b25a25e08d33c5f616bb342598aa Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 07:28:04 +0200 Subject: [PATCH 22/41] Fixed a mistake in order of script execution in executable --- Sources/Executable/main.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Executable/main.swift b/Sources/Executable/main.swift index 9d7e2aa..01cb503 100644 --- a/Sources/Executable/main.swift +++ b/Sources/Executable/main.swift @@ -4,11 +4,10 @@ import Foundation let process = Process() let script = """ -swift build --target PackageConfigs mkdir -p ./Sources/PackageConfigs/ touch ./Sources/PackageConfigs/PackageConfigs.swift echo '// Do not delete this file or it's target, it is requried to build dylibs for the Packages you installed which depend on PackageConfig for their own package configuration' > ./Sources/PackageConfigs/PackageConfigs.swift - +swift build --target PackageConfigs """ process.launchPath = "/bin/bash" From 3ee67c7113d97e975c76c92517732871bd16d74f Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 07:36:08 +0200 Subject: [PATCH 23/41] More fixes after messing up with Package.swift --- Package.swift | 12 ++++++------ Sources/{Library => PackageConfig}/Loader.swift | 0 Sources/{Library => PackageConfig}/Package.swift | 0 .../{Library => PackageConfig}/PackageConfig.swift | 0 Sources/{Library => PackageConfig}/Writer.swift | 0 .../main.swift | 0 .../PackageConfigs.swift} | 0 7 files changed, 6 insertions(+), 6 deletions(-) rename Sources/{Library => PackageConfig}/Loader.swift (100%) rename Sources/{Library => PackageConfig}/Package.swift (100%) rename Sources/{Library => PackageConfig}/PackageConfig.swift (100%) rename Sources/{Library => PackageConfig}/Writer.swift (100%) rename Sources/{Executable => PackageConfigExecutable}/main.swift (100%) rename Sources/{PackageDependencies/PackageDependencies.swift => PackageConfigs/PackageConfigs.swift} (100%) diff --git a/Package.swift b/Package.swift index cbf227b..83f4de4 100644 --- a/Package.swift +++ b/Package.swift @@ -6,8 +6,8 @@ import PackageDescription let package = Package( name: "PackageConfig", products: [ - .library(name: "PackageConfig", targets: ["Library"]), - .executable(name: "package-config", targets: ["Executable"]), + .library(name: "PackageConfig", targets: ["PackageConfig"]), + .executable(name: "package-config", targets: ["PackageConfigExecutable"]), .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), .executable(name: "package-config-example", targets: ["Example"]) @@ -15,11 +15,11 @@ let package = Package( dependencies: [ ], targets: [ - .target(name: "Library", dependencies: []), - .target(name: "Executable", dependencies: []), + .target(name: "PackageConfig", dependencies: []), + .target(name: "PackageConfigExecutable", dependencies: []), - .target(name: "ExampleConfig", dependencies: ["Library"]), - .target(name: "Example", dependencies: ["Library", "ExampleConfig"]), + .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), + .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig"]), ] ) diff --git a/Sources/Library/Loader.swift b/Sources/PackageConfig/Loader.swift similarity index 100% rename from Sources/Library/Loader.swift rename to Sources/PackageConfig/Loader.swift diff --git a/Sources/Library/Package.swift b/Sources/PackageConfig/Package.swift similarity index 100% rename from Sources/Library/Package.swift rename to Sources/PackageConfig/Package.swift diff --git a/Sources/Library/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift similarity index 100% rename from Sources/Library/PackageConfig.swift rename to Sources/PackageConfig/PackageConfig.swift diff --git a/Sources/Library/Writer.swift b/Sources/PackageConfig/Writer.swift similarity index 100% rename from Sources/Library/Writer.swift rename to Sources/PackageConfig/Writer.swift diff --git a/Sources/Executable/main.swift b/Sources/PackageConfigExecutable/main.swift similarity index 100% rename from Sources/Executable/main.swift rename to Sources/PackageConfigExecutable/main.swift diff --git a/Sources/PackageDependencies/PackageDependencies.swift b/Sources/PackageConfigs/PackageConfigs.swift similarity index 100% rename from Sources/PackageDependencies/PackageDependencies.swift rename to Sources/PackageConfigs/PackageConfigs.swift From 0451f4fef7a2606a85c85c8c412c4a905d22d137 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 07:39:21 +0200 Subject: [PATCH 24/41] Updated script --- Sources/PackageConfigExecutable/main.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/PackageConfigExecutable/main.swift b/Sources/PackageConfigExecutable/main.swift index 01cb503..68d58b2 100644 --- a/Sources/PackageConfigExecutable/main.swift +++ b/Sources/PackageConfigExecutable/main.swift @@ -6,7 +6,6 @@ let script = """ mkdir -p ./Sources/PackageConfigs/ touch ./Sources/PackageConfigs/PackageConfigs.swift -echo '// Do not delete this file or it's target, it is requried to build dylibs for the Packages you installed which depend on PackageConfig for their own package configuration' > ./Sources/PackageConfigs/PackageConfigs.swift swift build --target PackageConfigs """ From 6733876a3f31227b99d44ce06526277acecc0432 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 09:30:43 +0200 Subject: [PATCH 25/41] Updated README.md --- README.md | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f00bbc2..5d5b0ad 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,45 @@ Tool builders use this dependency to grab their config settings. ### User writes: +Anywhere in the list of targets in `Package.swift` + +```swift +.target(name: "PackageConfigs", dependencies: [ + "PackageConfig", // PackageConfig library + "ExampleConfig" // your library config dylib +]) +``` + At the very bottom of the `Package.swift` ```swift -#if canImport(ExampleConfig) +#if canImport(ExampleConfig) // your library config dynamic library import ExampleConfig ExampleConfig(value: "example value").write() #endif ``` +If more than one dependency uses `PackageConfig` be sure to wrap each in + +```swift +#if canImport(SomeLibraryConfig) +import SomeLibraryConfig + +SomeLibraryConfig().write() +#endif +``` + +Also be sure to invoke `write` method of the `Config` otherwise this won't work. + +And then to use your executable user would need to run this in the same directory as his/her project `Package.swift`: + +```bash +swift run resolve # resolves package dependencies +swift run package-config # compiles PackageConfigs target, thus ensures dylibs are built +swift run example # runs your library executable +``` + ### Tool-dev writes: For the sake of example lets assume your library is called Example then `Package.swift` would look like this: @@ -24,7 +53,7 @@ For the sake of example lets assume your library is called Example then `Package let package = Package( name: "Example", products: [ - // notice that library product with your config should be dynamic + // notice that library product with your library config should be dynamic .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), .executable(name: "example", targets: ["Example"]), ], @@ -44,13 +73,13 @@ In your `ExampleConfig` target define `ExampleConfig` like this. import PackageConfig // it must be public for you to use in your executable target -// also you must conform to Codable and PackageConfig +// also you must conform to `Codable` and `PackageConfig` public struct ExampleConfig: Codable, PackageConfig { // here can be whatever you want as long as your config can stay `Codable` let value: String - // here you define a name of ExampleConfig dynamic library product + // here you must define a name of ExampleConfig dynamic library product to be sure it gets linked when loading config public static var dynamicLibraries: [String] = ["ExampleConfig"] // public init is also a requirement @@ -58,11 +87,9 @@ public struct ExampleConfig: Codable, PackageConfig { self.value = value } } - - ``` -Then in your `main.swift` in `Example` target you can load your config like this: +Then for example in your `main.swift` in `Example` target you can load your config like this: ```swift import ExampleConfig From fbafd1f61047654344bf310d720516c00f300fc8 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 09:39:53 +0200 Subject: [PATCH 26/41] Updated README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 5d5b0ad..18e6bb2 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,16 @@ let config = ExampleConfig.load() This might be everything, so if in a month or two nothing really changes I'll v1 after this release. +# How it all works + +When you invoke `YourPackage.load()` it will compile the `Package.swift` in the current directory the using `swiftc`. + +While compiling it will try to link list of `dynamicLibraries: [String]` provided by your custom config conforming to `PackageConfig`. + +When it get's compiled it will run and when `YourPackage.write()` get's called your package configuration json will be written to temporary directory. + +After that the it will try to read that it and decode to `YourPackage` type back to from where you have invoked `load` method. + # Debugging ### How to see the JSON from a Package.swift file From e3ff450db8ab927dc4a06b74d12a5f9fea359a52 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 09:44:44 +0200 Subject: [PATCH 27/41] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 18e6bb2..0bb5e8a 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ Also be sure to invoke `write` method of the `Config` otherwise this won't work. And then to use your executable user would need to run this in the same directory as his/her project `Package.swift`: ```bash -swift run resolve # resolves package dependencies +swift run resolve # resolves package dependencies swift run package-config # compiles PackageConfigs target, thus ensures dylibs are built -swift run example # runs your library executable +swift run example # runs your library executable ``` ### Tool-dev writes: @@ -77,15 +77,15 @@ import PackageConfig public struct ExampleConfig: Codable, PackageConfig { // here can be whatever you want as long as your config can stay `Codable` - let value: String + let value: String // here you must define a name of ExampleConfig dynamic library product to be sure it gets linked when loading config - public static var dynamicLibraries: [String] = ["ExampleConfig"] + public static var dynamicLibraries: [String] = ["ExampleConfig"] // public init is also a requirement - public init(value: String) { - self.value = value - } + public init(value: String) { + self.value = value + } } ``` From 08ec74861255e2dfb05597cc03effc4d89edf7d2 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 09:46:53 +0200 Subject: [PATCH 28/41] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bb5e8a..e93dbc6 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ While compiling it will try to link list of `dynamicLibraries: [String]` provide When it get's compiled it will run and when `YourPackage.write()` get's called your package configuration json will be written to temporary directory. -After that the it will try to read that it and decode to `YourPackage` type back to from where you have invoked `load` method. +After that it will try to read the json and decode it as if it was `YourPackage` type, providing it back to where you have invoked `load` method. # Debugging From 374d99c507be9be4d0a8cc0676530b2a8d712b4c Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 15:45:30 +0200 Subject: [PATCH 29/41] Updated package-config executable script --- Sources/PackageConfigExecutable/main.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/PackageConfigExecutable/main.swift b/Sources/PackageConfigExecutable/main.swift index 68d58b2..fbfca1e 100644 --- a/Sources/PackageConfigExecutable/main.swift +++ b/Sources/PackageConfigExecutable/main.swift @@ -4,6 +4,7 @@ import Foundation let process = Process() let script = """ +swift package resolve mkdir -p ./Sources/PackageConfigs/ touch ./Sources/PackageConfigs/PackageConfigs.swift swift build --target PackageConfigs From 7b49aac0881118d7589b5b71c4a78c6c8da17fdb Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 16:04:21 +0200 Subject: [PATCH 30/41] Updated README.md; Removed unneeded files --- README.md | 5 ++++- Sources/PackageConfigs/PackageConfigs.swift | 0 2 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 Sources/PackageConfigs/PackageConfigs.swift diff --git a/README.md b/README.md index e93dbc6..0394df1 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ Also be sure to invoke `write` method of the `Config` otherwise this won't work. And then to use your executable user would need to run this in the same directory as his/her project `Package.swift`: ```bash -swift run resolve # resolves package dependencies swift run package-config # compiles PackageConfigs target, thus ensures dylibs are built swift run example # runs your library executable ``` @@ -97,6 +96,10 @@ import ExampleConfig let config = ExampleConfig.load() ``` +### Notes for library developers + +Since `YourConfig` target is a dynamic library you must ensure that you have built it everytime when using either `read` or `write` methods of `PackageConfig`. When building from terminal this can be done by just running `swift build`. + ---- # Changelog diff --git a/Sources/PackageConfigs/PackageConfigs.swift b/Sources/PackageConfigs/PackageConfigs.swift deleted file mode 100644 index e69de29..0000000 From 2e482847b97db481ab7c1c215d31113c68101734 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Sun, 17 Mar 2019 17:12:17 +0200 Subject: [PATCH 31/41] Added property to protocol --- Sources/ExampleConfig/ExampleConfig.swift | 1 + Sources/PackageConfig/Loader.swift | 2 +- Sources/PackageConfig/PackageConfig.swift | 1 + Sources/PackageConfig/Writer.swift | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/ExampleConfig/ExampleConfig.swift b/Sources/ExampleConfig/ExampleConfig.swift index 176d755..da63457 100644 --- a/Sources/ExampleConfig/ExampleConfig.swift +++ b/Sources/ExampleConfig/ExampleConfig.swift @@ -6,6 +6,7 @@ public struct ExampleConfig: Codable, PackageConfig { let value: String + public static var fileName: String = "example.config.json" public static var dynamicLibraries: [String] = ["ExampleConfig"] public init(value: String) { diff --git a/Sources/PackageConfig/Loader.swift b/Sources/PackageConfig/Loader.swift index 967a3df..c2408f5 100644 --- a/Sources/PackageConfig/Loader.swift +++ b/Sources/PackageConfig/Loader.swift @@ -3,7 +3,7 @@ import Foundation enum Loader { static func load() -> T? { - let packageConfigJSON = NSTemporaryDirectory() + "package-config.json" + let packageConfigJSON = NSTemporaryDirectory() + T.fileName print(packageConfigJSON) diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index ed5b256..0ed7a42 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -2,6 +2,7 @@ public protocol PackageConfig: Codable { static var dynamicLibraries: [String] { get } + static var fileName: String { get } static func load() -> Self? func write() diff --git a/Sources/PackageConfig/Writer.swift b/Sources/PackageConfig/Writer.swift index da2c50c..41fb231 100644 --- a/Sources/PackageConfig/Writer.swift +++ b/Sources/PackageConfig/Writer.swift @@ -3,8 +3,8 @@ import Foundation enum Writer { - static func write(configuration: T) { - let packageConfigJSON = NSTemporaryDirectory() + "package-config.json" + static func write(configuration: T) { + let packageConfigJSON = NSTemporaryDirectory() + T.fileName let encoder = JSONEncoder() let data = try! encoder.encode(configuration) From 21195dad0e7c96ad5f8ae0e60d8ff66f3bcaf433 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Tue, 19 Mar 2019 08:53:38 +0200 Subject: [PATCH 32/41] Resolving required dynamic libraries from PackageConfigs target --- Package.swift | 7 +- Sources/Example/main.swift | 9 ++- Sources/ExampleConfig/ExampleConfig.swift | 1 - Sources/PackageConfig/DynamicLibraries.swift | 52 +++++++++++++ Sources/PackageConfig/Error.swift | 17 ++++ Sources/PackageConfig/Loader.swift | 9 +-- Sources/PackageConfig/Package.swift | 82 +++++++++----------- Sources/PackageConfig/PackageConfig.swift | 9 +-- Sources/PackageConfig/Writer.swift | 11 ++- Sources/PackageConfigExecutable/main.swift | 1 - 10 files changed, 131 insertions(+), 67 deletions(-) create mode 100644 Sources/PackageConfig/DynamicLibraries.swift create mode 100644 Sources/PackageConfig/Error.swift diff --git a/Package.swift b/Package.swift index 83f4de4..d1a4130 100644 --- a/Package.swift +++ b/Package.swift @@ -10,7 +10,7 @@ let package = Package( .executable(name: "package-config", targets: ["PackageConfigExecutable"]), .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), - .executable(name: "package-config-example", targets: ["Example"]) + .executable(name: "package-config-example", targets: ["Example"]), ], dependencies: [ ], @@ -19,7 +19,9 @@ let package = Package( .target(name: "PackageConfigExecutable", dependencies: []), .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), - .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig"]), + .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig", "ShitConfig"]), + + .target(name: "PackageConfigs", dependencies: ["ExampleConfig"]), ] ) @@ -27,5 +29,4 @@ let package = Package( import ExampleConfig ExampleConfig(value: "example value").write() - #endif diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index cfa2004..30ddf07 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,6 +1,9 @@ import ExampleConfig -let example = ExampleConfig.load() - -print(example) +do { + let example = try ExampleConfig.load() + print(example) +} catch { + print(error) +} diff --git a/Sources/ExampleConfig/ExampleConfig.swift b/Sources/ExampleConfig/ExampleConfig.swift index da63457..b09d11e 100644 --- a/Sources/ExampleConfig/ExampleConfig.swift +++ b/Sources/ExampleConfig/ExampleConfig.swift @@ -7,7 +7,6 @@ public struct ExampleConfig: Codable, PackageConfig { let value: String public static var fileName: String = "example.config.json" - public static var dynamicLibraries: [String] = ["ExampleConfig"] public init(value: String) { self.value = value diff --git a/Sources/PackageConfig/DynamicLibraries.swift b/Sources/PackageConfig/DynamicLibraries.swift new file mode 100644 index 0000000..8c2be0e --- /dev/null +++ b/Sources/PackageConfig/DynamicLibraries.swift @@ -0,0 +1,52 @@ + +import Foundation + +enum DynamicLibraries { + + private static func read() -> [String] { + let process = Process() + let pipe = Pipe() + + process.launchPath = "/bin/bash" + process.arguments = ["-c", "cat Package.swift"] + process.standardOutput = pipe + process.launch() + process.waitUntilExit() + + return String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! + .split(separator: "\n").map(String.init) + } + + static func list() throws -> [String] { + let lines = read() + + guard let start = lines.lastIndex(where: { $0.contains("PackageConfigs") }) else { + throw Error("Could not find PackageConfigs target definition") + } + + let definition = lines.suffix(from: start) + .joined(separator: "\n") + .drop { !["["].contains($0) } + .map(String.init) + .joined() + .split(separator: "\n") + + guard let end = definition.firstIndex(where: { $0.contains("]") }) else { + throw Error("Could not end PackageConfigs target definition") + } + + return definition.prefix(end + 1) + .reversed() + .drop { "]".contains($0) } + .reversed() + .joined() + .replacingOccurrences(of: "\t", with: "") + .replacingOccurrences(of: " ", with: "") + .replacingOccurrences(of: "[", with: "") + .replacingOccurrences(of: "]", with: "") + .replacingOccurrences(of: ")", with: "") + .replacingOccurrences(of: ",", with: "") + .replacingOccurrences(of: "\"\"", with: "\"") + .split(separator: "\"").map(String.init) + } +} diff --git a/Sources/PackageConfig/Error.swift b/Sources/PackageConfig/Error.swift new file mode 100644 index 0000000..dafe31c --- /dev/null +++ b/Sources/PackageConfig/Error.swift @@ -0,0 +1,17 @@ + +struct Error: Swift.Error, ExpressibleByStringLiteral { + + let reason: String + + init(_ reason: String) { + self.reason = reason + } + + init(stringLiteral reason: String) { + self.reason = reason + } + + var localizedDescription: String { + return reason + } +} diff --git a/Sources/PackageConfig/Loader.swift b/Sources/PackageConfig/Loader.swift index c2408f5..19b79a1 100644 --- a/Sources/PackageConfig/Loader.swift +++ b/Sources/PackageConfig/Loader.swift @@ -2,16 +2,13 @@ import Foundation enum Loader { - static func load() -> T? { + static func load() throws -> T { let packageConfigJSON = NSTemporaryDirectory() + T.fileName - print(packageConfigJSON) - guard let data = FileManager.default.contents(atPath: packageConfigJSON) else { - debugLog("Could not find a file at \(packageConfigJSON) - so returning an empty object") - return nil + throw Error("Could not find a file at \(packageConfigJSON) - something went wrong with compilation step probably") } - return try! JSONDecoder().decode(T.self, from: data) + return try JSONDecoder().decode(T.self, from: data) } } diff --git a/Sources/PackageConfig/Package.swift b/Sources/PackageConfig/Package.swift index af56baa..aaaa7dc 100644 --- a/Sources/PackageConfig/Package.swift +++ b/Sources/PackageConfig/Package.swift @@ -1,66 +1,59 @@ import Foundation -struct Package { - - let dynamicLibraries: [String] - - func compile() { - let swiftC = runXCRun(tool: "swiftc") - - var args = [String]() - args += ["--driver-mode=swift"] // Eval in swift mode, I think? - - args += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib - - args += libraryLinkingArguments() // link libraries - - args += ["-suppress-warnings"] // SPM does that too - args += ["Package.swift"] // The Package.swift in the CWD +enum Package { + + static func compile() throws { + let swiftC = try runXCRun(tool: "swiftc") + let process = Process() + let linkedLibraries = try libraryLinkingArguments() + var arguments = [String]() + arguments += ["--driver-mode=swift"] // Eval in swift mode, I think? + arguments += getSwiftPMManifestArgs(swiftPath: swiftC) // SwiftPM lib + arguments += linkedLibraries + arguments += ["-suppress-warnings"] // SPM does that too + arguments += ["Package.swift"] // The Package.swift in the CWD // Create a process to eval the Swift Package manifest as a subprocess - let proc = Process() - proc.launchPath = swiftC - proc.arguments = args - print(args) + process.launchPath = swiftC + process.arguments = arguments - debugLog("CMD: \(swiftC) \( args.joined(separator: " "))") + debugLog("CMD: \(swiftC) \( arguments.joined(separator: " "))") - let standardOutput = FileHandle.standardOutput - proc.standardOutput = standardOutput - proc.standardError = standardOutput - + let standardOutput = FileHandle.standardOutput + process.standardOutput = standardOutput + process.standardError = standardOutput // Evaluation of the package swift code will end up // creating a file in the tmpdir that stores the JSON // settings when a new instance of PackageConfig is created - proc.launch() - proc.waitUntilExit() + process.launch() + process.waitUntilExit() debugLog("Finished launching swiftc") } - func runXCRun(tool: String) -> String { - let proc = Process() - proc.launchPath = "/usr/bin/xcrun" - proc.arguments = ["--find", tool] + static private func runXCRun(tool: String) throws -> String { + let process = Process() + let pipe = Pipe() - debugLog("CMD: \(proc.launchPath!) \( ["--find", tool].joined(separator: " "))") + process.launchPath = "/usr/bin/xcrun" + process.arguments = ["--find", tool] + process.standardOutput = pipe - let pipe = Pipe() - proc.standardOutput = pipe + debugLog("CMD: \(process.launchPath!) \( ["--find", tool].joined(separator: " "))") - proc.launch() - proc.waitUntilExit() + process.launch() + process.waitUntilExit() - let resultsWithNewline = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - return resultsWithNewline.trimmingCharacters(in: .whitespacesAndNewlines) + return String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! + .trimmingCharacters(in: .whitespacesAndNewlines) } - func libraryPath(for library: String) -> String? { + static private func libraryPath(for library: String) -> String? { let fileManager = FileManager.default let libPaths = [ ".build/debug", @@ -69,6 +62,7 @@ struct Package { ] #warning("needs to be improved") + #warning("consider adding `/usr/lib` to libPath maybe") func isLibPath(path: String) -> Bool { return fileManager.fileExists(atPath: path + "/lib\(library).dylib") || // macOS @@ -78,11 +72,10 @@ struct Package { return libPaths.first(where: isLibPath) } - func libraryLinkingArguments() -> [String] { - return dynamicLibraries.map { libraryName in + static private func libraryLinkingArguments() throws -> [String] { + return try DynamicLibraries.list().map { libraryName in guard let path = libraryPath(for: libraryName) else { - print("PackageConfig: Could not find lib\(libraryName) to link against, is it possible you've not built yet?") - exit(1) + throw Error("PackageConfig: Could not find lib\(libraryName) to link against, is it possible you've not built yet?") } return [ @@ -93,7 +86,7 @@ struct Package { }.reduce([], +) } - func getSwiftPMManifestArgs(swiftPath: String) -> [String] { + static private func getSwiftPMManifestArgs(swiftPath: String) -> [String] { // using "xcrun --find swift" we get // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc // we need to transform it to something like: @@ -109,5 +102,4 @@ struct Package { debugLog("Using SPM version: \(libraryPathSPM)") return ["-L", libraryPathSPM, "-I", libraryPathSPM, "-lPackageDescription"] } - } diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index 0ed7a42..c0cb090 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -1,18 +1,17 @@ public protocol PackageConfig: Codable { - static var dynamicLibraries: [String] { get } static var fileName: String { get } - static func load() -> Self? + static func load() throws -> Self func write() } extension PackageConfig { - public static func load() -> Self? { - Package(dynamicLibraries: dynamicLibraries).compile() - return Loader.load() + public static func load() throws -> Self { + try Package.compile() + return try Loader.load() } public func write() { diff --git a/Sources/PackageConfig/Writer.swift b/Sources/PackageConfig/Writer.swift index 41fb231..1623f63 100644 --- a/Sources/PackageConfig/Writer.swift +++ b/Sources/PackageConfig/Writer.swift @@ -6,10 +6,15 @@ enum Writer { static func write(configuration: T) { let packageConfigJSON = NSTemporaryDirectory() + T.fileName let encoder = JSONEncoder() - let data = try! encoder.encode(configuration) - if !FileManager.default.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { - print("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") + do { + let data = try encoder.encode(configuration) + + if !FileManager.default.createFile(atPath: packageConfigJSON, contents: data, attributes: nil) { + debugLog("PackageConfig: Could not create a temporary file for the PackageConfig: \(packageConfigJSON)") + } + } catch { + debugLog("Package config failed to encode configuration \(configuration)") } debugLog("written to path: \(packageConfigJSON)") diff --git a/Sources/PackageConfigExecutable/main.swift b/Sources/PackageConfigExecutable/main.swift index fbfca1e..64d5ff8 100644 --- a/Sources/PackageConfigExecutable/main.swift +++ b/Sources/PackageConfigExecutable/main.swift @@ -9,7 +9,6 @@ mkdir -p ./Sources/PackageConfigs/ touch ./Sources/PackageConfigs/PackageConfigs.swift swift build --target PackageConfigs """ - process.launchPath = "/bin/bash" process.arguments = ["-c", script] process.launch() From 8852c64a43e21186b5c96722ffafa2758ba92c55 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Tue, 19 Mar 2019 23:32:16 +0200 Subject: [PATCH 33/41] minor improvements --- Sources/Example/main.swift | 2 +- Sources/ExampleConfig/ExampleConfig.swift | 3 +-- Sources/PackageConfig/DynamicLibraries.swift | 3 ++- Sources/PackageConfig/Loader.swift | 4 +++- Sources/PackageConfig/Package.swift | 5 ++++- Sources/PackageConfig/Writer.swift | 4 +++- Sources/PackageConfigExecutable/main.swift | 4 ++-- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Sources/Example/main.swift b/Sources/Example/main.swift index 30ddf07..1d8ebc4 100644 --- a/Sources/Example/main.swift +++ b/Sources/Example/main.swift @@ -1,5 +1,5 @@ -import ExampleConfig +import struct ExampleConfig.ExampleConfig do { let example = try ExampleConfig.load() diff --git a/Sources/ExampleConfig/ExampleConfig.swift b/Sources/ExampleConfig/ExampleConfig.swift index b09d11e..54342e1 100644 --- a/Sources/ExampleConfig/ExampleConfig.swift +++ b/Sources/ExampleConfig/ExampleConfig.swift @@ -1,6 +1,5 @@ -import Foundation -import PackageConfig +import protocol PackageConfig.PackageConfig public struct ExampleConfig: Codable, PackageConfig { diff --git a/Sources/PackageConfig/DynamicLibraries.swift b/Sources/PackageConfig/DynamicLibraries.swift index 8c2be0e..c679c99 100644 --- a/Sources/PackageConfig/DynamicLibraries.swift +++ b/Sources/PackageConfig/DynamicLibraries.swift @@ -1,5 +1,6 @@ -import Foundation +import class Foundation.Process +import class Foundation.Pipe enum DynamicLibraries { diff --git a/Sources/PackageConfig/Loader.swift b/Sources/PackageConfig/Loader.swift index 19b79a1..3d4c6f6 100644 --- a/Sources/PackageConfig/Loader.swift +++ b/Sources/PackageConfig/Loader.swift @@ -1,5 +1,7 @@ -import Foundation +import func Foundation.NSTemporaryDirectory +import class Foundation.FileManager +import class Foundation.JSONDecoder enum Loader { static func load() throws -> T { diff --git a/Sources/PackageConfig/Package.swift b/Sources/PackageConfig/Package.swift index aaaa7dc..19fb03a 100644 --- a/Sources/PackageConfig/Package.swift +++ b/Sources/PackageConfig/Package.swift @@ -1,5 +1,8 @@ -import Foundation +import class Foundation.Process +import class Foundation.Pipe +import class Foundation.FileHandle +import class Foundation.FileManager enum Package { diff --git a/Sources/PackageConfig/Writer.swift b/Sources/PackageConfig/Writer.swift index 1623f63..110e3fb 100644 --- a/Sources/PackageConfig/Writer.swift +++ b/Sources/PackageConfig/Writer.swift @@ -1,5 +1,7 @@ -import Foundation +import class Foundation.JSONEncoder +import class Foundation.FileManager +import func Foundation.NSTemporaryDirectory enum Writer { diff --git a/Sources/PackageConfigExecutable/main.swift b/Sources/PackageConfigExecutable/main.swift index 64d5ff8..1250c25 100644 --- a/Sources/PackageConfigExecutable/main.swift +++ b/Sources/PackageConfigExecutable/main.swift @@ -1,12 +1,12 @@ -import Foundation +import class Foundation.Process let process = Process() let script = """ -swift package resolve mkdir -p ./Sources/PackageConfigs/ touch ./Sources/PackageConfigs/PackageConfigs.swift +swift package resolve swift build --target PackageConfigs """ process.launchPath = "/bin/bash" From 8c9a63c448d8057488fa49873c9fffdcefed4b82 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Tue, 19 Mar 2019 23:39:26 +0200 Subject: [PATCH 34/41] Commented out PackageConfigs target --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index d1a4130..3a661ff 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig", "ShitConfig"]), - .target(name: "PackageConfigs", dependencies: ["ExampleConfig"]), +// .target(name: "PackageConfigs", dependencies: ["ExampleConfig"]), ] ) From ad7941d2eddab91d2d6674daef4aed6124d32e3c Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Tue, 19 Mar 2019 23:40:40 +0200 Subject: [PATCH 35/41] commented out test target --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 3a661ff..8436a8f 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,7 @@ let package = Package( .target(name: "PackageConfigExecutable", dependencies: []), .target(name: "ExampleConfig", dependencies: ["PackageConfig"]), - .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig", "ShitConfig"]), + .target(name: "Example", dependencies: ["PackageConfig", "ExampleConfig"]), // .target(name: "PackageConfigs", dependencies: ["ExampleConfig"]), ] From f4426acf87265cd7fb18b1ab77a749d77125f927 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Wed, 20 Mar 2019 01:14:18 +0200 Subject: [PATCH 36/41] Improved Package.swift parsing to ignore comments --- Sources/PackageConfig/DynamicLibraries.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/PackageConfig/DynamicLibraries.swift b/Sources/PackageConfig/DynamicLibraries.swift index c679c99..c03a230 100644 --- a/Sources/PackageConfig/DynamicLibraries.swift +++ b/Sources/PackageConfig/DynamicLibraries.swift @@ -40,6 +40,11 @@ enum DynamicLibraries { .reversed() .drop { "]".contains($0) } .reversed() + .map(String.init) + .map { + guard let comment = $0.range(of: "//")?.lowerBound else { return $0 } + return String($0.prefix(comment.encodedOffset)) + } .joined() .replacingOccurrences(of: "\t", with: "") .replacingOccurrences(of: " ", with: "") From 7d93c417c4c3cee7074c55645d564bb24242d0b6 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Wed, 20 Mar 2019 01:40:24 +0200 Subject: [PATCH 37/41] Updated README.md --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0394df1..854fd4f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Anywhere in the list of targets in `Package.swift` ```swift .target(name: "PackageConfigs", dependencies: [ - "PackageConfig", // PackageConfig library "ExampleConfig" // your library config dylib ]) ``` @@ -40,7 +39,7 @@ Also be sure to invoke `write` method of the `Config` otherwise this won't work. And then to use your executable user would need to run this in the same directory as his/her project `Package.swift`: ```bash -swift run package-config # compiles PackageConfigs target, thus ensures dylibs are built +swift run package-config # compiles PackageConfigs target, expecting to find a dylib in `.build` directory for each of the listed libraries configs swift run example # runs your library executable ``` @@ -52,8 +51,9 @@ For the sake of example lets assume your library is called Example then `Package let package = Package( name: "Example", products: [ - // notice that library product with your library config should be dynamic + // notice that product with your library config should be dynamic library in order to produce dylib and allow PackageConfig to link it when building Package.swift .library(name: "ExampleConfig", type: .dynamic, targets: ["ExampleConfig"]), + // .executable(name: "example", targets: ["Example"]), ], dependencies: [ @@ -78,8 +78,8 @@ public struct ExampleConfig: Codable, PackageConfig { // here can be whatever you want as long as your config can stay `Codable` let value: String - // here you must define a name of ExampleConfig dynamic library product to be sure it gets linked when loading config - public static var dynamicLibraries: [String] = ["ExampleConfig"] + // here you must define your config fileName which will be used to write and read it to/from temporary directory + public static var fileName: String { return "example-config.json" } // public init is also a requirement public init(value: String) { @@ -93,7 +93,12 @@ Then for example in your `main.swift` in `Example` target you can load your conf ```swift import ExampleConfig -let config = ExampleConfig.load() +do { + let config = try ExampleConfig.load() + print(config) +} catch { + print(error) +} ``` ### Notes for library developers From 03fae7d446706f00092914a5bc794d967afddc6e Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Wed, 20 Mar 2019 01:48:51 +0200 Subject: [PATCH 38/41] minor improvements --- Sources/PackageConfig/Package.swift | 11 ++--------- Sources/PackageConfig/PackageConfig.swift | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Sources/PackageConfig/Package.swift b/Sources/PackageConfig/Package.swift index 19fb03a..0b13193 100644 --- a/Sources/PackageConfig/Package.swift +++ b/Sources/PackageConfig/Package.swift @@ -18,24 +18,18 @@ enum Package { arguments += ["Package.swift"] // The Package.swift in the CWD // Create a process to eval the Swift Package manifest as a subprocess - process.launchPath = swiftC process.arguments = arguments + process.standardOutput = FileHandle.standardOutput + process.standardError = FileHandle.standardOutput debugLog("CMD: \(swiftC) \( arguments.joined(separator: " "))") - - - let standardOutput = FileHandle.standardOutput - process.standardOutput = standardOutput - process.standardError = standardOutput - // Evaluation of the package swift code will end up // creating a file in the tmpdir that stores the JSON // settings when a new instance of PackageConfig is created process.launch() process.waitUntilExit() - debugLog("Finished launching swiftc") } @@ -51,7 +45,6 @@ enum Package { process.launch() process.waitUntilExit() - return String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! .trimmingCharacters(in: .whitespacesAndNewlines) } diff --git a/Sources/PackageConfig/PackageConfig.swift b/Sources/PackageConfig/PackageConfig.swift index c0cb090..7a92c83 100644 --- a/Sources/PackageConfig/PackageConfig.swift +++ b/Sources/PackageConfig/PackageConfig.swift @@ -19,7 +19,7 @@ extension PackageConfig { } } -import Foundation +import class Foundation.ProcessInfo func debugLog(_ message: String) -> Void { let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil) From 765d99092f343749f25409466faae8443f52de81 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Wed, 20 Mar 2019 01:58:07 +0200 Subject: [PATCH 39/41] Updated README.md --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 854fd4f..c16df3d 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,22 @@ Tool builders use this dependency to grab their config settings. ### User writes: -Anywhere in the list of targets in `Package.swift` +List all the required package configs anywhere in the list of targets in `Package.swift` like this. ```swift +// PackageConfig parses PackageConfigs target in Package.swift to extract list of dylibs to link when compiling Package.swift with configurations .target(name: "PackageConfigs", dependencies: [ - "ExampleConfig" // your library config dylib + "ExampleConfig" // some executable configuration definition dylib ]) ``` At the very bottom of the `Package.swift` ```swift -#if canImport(ExampleConfig) // your library config dynamic library +#if canImport(ExampleConfig) // example config dynamic library import ExampleConfig +// invoking write is mandatory, otherwise the config won't be written // thanks captain obvious ExampleConfig(value: "example value").write() #endif ``` @@ -34,7 +36,7 @@ SomeLibraryConfig().write() #endif ``` -Also be sure to invoke `write` method of the `Config` otherwise this won't work. +Be sure to invoke `write` method of the `Config` otherwise this won't work. And then to use your executable user would need to run this in the same directory as his/her project `Package.swift`: @@ -45,7 +47,7 @@ swift run example # runs your library executable ### Tool-dev writes: -For the sake of example lets assume your library is called Example then `Package.swift` would look like this: +For the sake of example lets assume your library is called **Example** then `Package.swift` would look like this: ```swift let package = Package( @@ -88,7 +90,7 @@ public struct ExampleConfig: Codable, PackageConfig { } ``` -Then for example in your `main.swift` in `Example` target you can load your config like this: +Then for example in your `main.swift` in executable `Example` target you can load your config like this: ```swift import ExampleConfig @@ -129,9 +131,9 @@ Since `YourConfig` target is a dynamic library you must ensure that you have bui # How it all works -When you invoke `YourPackage.load()` it will compile the `Package.swift` in the current directory the using `swiftc`. +When you invoke `YourPackage.load()` it will compile the `Package.swift` in the current directory using `swiftc`. -While compiling it will try to link list of `dynamicLibraries: [String]` provided by your custom config conforming to `PackageConfig`. +While compiling it will try to link list of dynamic libraries listed in `PackageConfigs` target. When it get's compiled it will run and when `YourPackage.write()` get's called your package configuration json will be written to temporary directory. From 89d8045366eff4f66614ddfcbb12c3f90e370d74 Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Wed, 20 Mar 2019 19:22:16 +0200 Subject: [PATCH 40/41] Updated README.md --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c16df3d..2ff9937 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,15 @@ Tool builders use this dependency to grab their config settings. ### User writes: -List all the required package configs anywhere in the list of targets in `Package.swift` like this. +Run this line to have empty source for `PackageConfigs` target generated for you. + +```bash +swift run package-config +``` + +First time it should return an error `error: no target named 'PackageConfigs'`. + +Now you can list all the required package configs anywhere in the list of targets in `Package.swift` like this. ```swift // PackageConfig parses PackageConfigs target in Package.swift to extract list of dylibs to link when compiling Package.swift with configurations @@ -38,7 +46,7 @@ SomeLibraryConfig().write() Be sure to invoke `write` method of the `Config` otherwise this won't work. -And then to use your executable user would need to run this in the same directory as his/her project `Package.swift`: +And then to use executable user would need to run this in the same directory as his/her project `Package.swift` ```bash swift run package-config # compiles PackageConfigs target, expecting to find a dylib in `.build` directory for each of the listed libraries configs From 242ae21f9e4ca861305d53c6752ecac1b1add04e Mon Sep 17 00:00:00 2001 From: Igor Muzyka Date: Wed, 20 Mar 2019 21:30:35 +0200 Subject: [PATCH 41/41] minor improvements --- Sources/PackageConfig/DynamicLibraries.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PackageConfig/DynamicLibraries.swift b/Sources/PackageConfig/DynamicLibraries.swift index c03a230..337eeb8 100644 --- a/Sources/PackageConfig/DynamicLibraries.swift +++ b/Sources/PackageConfig/DynamicLibraries.swift @@ -27,7 +27,7 @@ enum DynamicLibraries { let definition = lines.suffix(from: start) .joined(separator: "\n") - .drop { !["["].contains($0) } + .drop { !"[".contains($0) } .map(String.init) .joined() .split(separator: "\n")