diff --git a/Sources/Frontend/Commands/ScanCommand.swift b/Sources/Frontend/Commands/ScanCommand.swift index 76fe38b32..ae78b4b0e 100644 --- a/Sources/Frontend/Commands/ScanCommand.swift +++ b/Sources/Frontend/Commands/ScanCommand.swift @@ -114,6 +114,9 @@ struct ScanCommand: FrontendCommand { @Flag(help: "Only output results") var quiet: Bool = defaultConfiguration.$quiet.defaultValue + @Option(parsing: .upToNextOption, help: "JSON package manifest path (obtained using `swift package describe --type json` or manually)") + var jsonPackageManifestPath: [FilePath] = defaultConfiguration.$jsonPackageManifestPath.defaultValue + private static let defaultConfiguration = Configuration() func run() throws { @@ -162,6 +165,7 @@ struct ScanCommand: FrontendCommand { configuration.apply(\.$buildArguments, buildArguments) configuration.apply(\.$relativeResults, relativeResults) configuration.apply(\.$retainCodableProperties, retainCodableProperties) + configuration.apply(\.$jsonPackageManifestPath, jsonPackageManifestPath) try scanBehavior.main { project in try Scan().perform(project: project) diff --git a/Sources/PeripheryKit/SPM/SPM.swift b/Sources/PeripheryKit/SPM/SPM.swift index 9657d3586..f1782aba3 100644 --- a/Sources/PeripheryKit/SPM/SPM.swift +++ b/Sources/PeripheryKit/SPM/SPM.swift @@ -10,12 +10,21 @@ public struct SPM { } public struct Package: Decodable { - public static func load() throws -> Self { + public static func load(jsonPackageManifestPath: [FilePath] = []) throws -> Self { Logger().contextualized(with: "spm:package").debug("Loading \(FilePath.current)") - let jsonString = try Shell.shared.exec(["swift", "package", "describe", "--type", "json"], stderr: false) - guard let jsonData = jsonString.data(using: .utf8) else { - throw PeripheryError.packageError(message: "Failed to read swift package description.") + let jsonData: Data + + if let path = jsonPackageManifestPath.first { + jsonData = try Data(contentsOf: path.url) + } else { + let jsonString = try Shell.shared.exec(["swift", "package", "describe", "--type", "json"], stderr: false) + + guard let data = jsonString.data(using: .utf8) else { + throw PeripheryError.packageError(message: "Failed to read swift package description.") + } + + jsonData = data } let decoder = JSONDecoder() diff --git a/Sources/PeripheryKit/SPM/SPMProjectDriver.swift b/Sources/PeripheryKit/SPM/SPMProjectDriver.swift index 7e7fa1aa8..66ca666da 100644 --- a/Sources/PeripheryKit/SPM/SPMProjectDriver.swift +++ b/Sources/PeripheryKit/SPM/SPMProjectDriver.swift @@ -5,7 +5,7 @@ import Shared public final class SPMProjectDriver { public static func build() throws -> Self { let configuration = Configuration.shared - let package = try SPM.Package.load() + let package = try SPM.Package.load(jsonPackageManifestPath: configuration.jsonPackageManifestPath) let targets: [SPM.Target] if !configuration.schemes.isEmpty { diff --git a/Sources/Shared/Configuration.swift b/Sources/Shared/Configuration.swift index b6fb24726..0275ccaaf 100644 --- a/Sources/Shared/Configuration.swift +++ b/Sources/Shared/Configuration.swift @@ -110,6 +110,9 @@ public final class Configuration { @Setting(key: "relative_results", defaultValue: false) public var relativeResults: Bool + @Setting(key: "json_package_manifest_path", defaultValue: []) + public var jsonPackageManifestPath: [FilePath] + // Non user facing. public var guidedSetup: Bool = false public var removalOutputBasePath: FilePath?