diff --git a/Plugins/SafeDIGenerateDependencyTree/SafeDIGenerateDependencyTree.swift b/Plugins/SafeDIGenerateDependencyTree/SafeDIGenerateDependencyTree.swift index 57f2816d..309988a5 100644 --- a/Plugins/SafeDIGenerateDependencyTree/SafeDIGenerateDependencyTree.swift +++ b/Plugins/SafeDIGenerateDependencyTree/SafeDIGenerateDependencyTree.swift @@ -1,3 +1,4 @@ +import Foundation import PackagePlugin @main @@ -26,8 +27,19 @@ struct SafeDIGenerateDependencyTree: BuildToolPlugin { .map(\.path) } - let arguments = (targetSwiftFiles + dependenciesSourceFiles).map(\.string) - + ["--dependency-tree-output", outputSwiftFile.string] + let inputSourcesFilePath = context.pluginWorkDirectory.appending(subpath: "InputSwiftFiles.csv").string + try Data( + (targetSwiftFiles + dependenciesSourceFiles) + .map(\.string) + .joined(separator: ",") + .utf8 + ) + .write(toPath: inputSourcesFilePath) + let arguments = [ + inputSourcesFilePath, + "--dependency-tree-output", + outputSwiftFile.string + ] return [ .buildCommand( @@ -93,9 +105,16 @@ extension SafeDIGenerateDependencyTree: XcodeBuildToolPlugin { } let outputSwiftFile = context.pluginWorkDirectory.appending(subpath: "SafeDI.swift") - let arguments = inputSwiftFiles - .map(\.string) - + [ + let inputSourcesFilePath = context.pluginWorkDirectory.appending(subpath: "InputSwiftFiles.csv").string + try Data( + inputSwiftFiles + .map(\.string) + .joined(separator: ",") + .utf8 + ) + .write(toPath: inputSourcesFilePath) + let arguments = [ + inputSourcesFilePath, "--dependency-tree-output", outputSwiftFile.string ] @@ -112,3 +131,17 @@ extension SafeDIGenerateDependencyTree: XcodeBuildToolPlugin { } } #endif + +extension Data { + fileprivate func write(toPath filePath: String) throws { +#if os(Linux) + try write(to: URL(fileURLWithPath: filePath)) +#else + if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) { + try write(to: URL(filePath: filePath)) + } else { + try write(to: URL(fileURLWithPath: filePath)) + } +#endif + } +} diff --git a/Sources/SafeDITool/SafeDITool.swift b/Sources/SafeDITool/SafeDITool.swift index 5a33e846..9db0ba1c 100644 --- a/Sources/SafeDITool/SafeDITool.swift +++ b/Sources/SafeDITool/SafeDITool.swift @@ -29,8 +29,8 @@ struct SafeDITool: AsyncParsableCommand { // MARK: Arguments - @Argument(help: "The swift files to parse") - var swiftFilePaths: [String] + @Argument(help: "A path to a CSV file containing paths of Swift files to parse.") + var swiftSourcesFilePath: String @Option(parsing: .upToNextOption, help: "The names of modules to import in the generated dependency tree. This list is in addition to the import statements found in files that declare @Instantiable types.") var additionalImportedModules: [String] = [] @@ -123,6 +123,8 @@ struct SafeDITool: AsyncParsableCommand { of: String.self, returning: [String].self ) { taskGroup in + let swiftFilePaths = try String(contentsOfFile: swiftSourcesFilePath) + .components(separatedBy: CharacterSet(arrayLiteral: ",")) for filePath in swiftFilePaths { taskGroup.addTask { let swiftFile = try String(contentsOfFile: filePath)