-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make build plugin communicate files via a file list rather than space-separated CLI arguments #10
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main | ||
|
@@ -26,8 +27,20 @@ struct SafeDIGenerateDependencyTree: BuildToolPlugin { | |
.map(\.path) | ||
} | ||
|
||
let arguments = (targetSwiftFiles + dependenciesSourceFiles).map(\.string) | ||
+ ["--dependency-tree-output", outputSwiftFile.string] | ||
let inputSwiftFilesFilePath = context.pluginWorkDirectory.appending(subpath: "InputSwiftFiles.txt").string | ||
try Data( | ||
(targetSwiftFiles + dependenciesSourceFiles) | ||
.map(\.string) | ||
.joined(separator: "\n") | ||
.utf8 | ||
) | ||
.write(toPath: inputSwiftFilesFilePath) | ||
let arguments = [ | ||
"--swift-file-paths-file-path", | ||
inputSwiftFilesFilePath, | ||
"--dependency-tree-output", | ||
outputSwiftFile.string | ||
] | ||
|
||
return [ | ||
.buildCommand( | ||
|
@@ -93,9 +106,17 @@ extension SafeDIGenerateDependencyTree: XcodeBuildToolPlugin { | |
} | ||
|
||
let outputSwiftFile = context.pluginWorkDirectory.appending(subpath: "SafeDI.swift") | ||
let arguments = inputSwiftFiles | ||
.map(\.string) | ||
+ [ | ||
let inputSwiftFilesFilePath = context.pluginWorkDirectory.appending(subpath: "InputSwiftFiles.txt").string | ||
try Data( | ||
inputSwiftFiles | ||
.map(\.string) | ||
.joined(separator: "\n") | ||
.utf8 | ||
) | ||
.write(toPath: inputSwiftFilesFilePath) | ||
let arguments = [ | ||
"--swift-file-paths-file-path", | ||
inputSwiftFilesFilePath, | ||
"--dependency-tree-output", | ||
outputSwiftFile.string | ||
] | ||
|
@@ -112,3 +133,17 @@ extension SafeDIGenerateDependencyTree: XcodeBuildToolPlugin { | |
} | ||
} | ||
#endif | ||
|
||
extension Data { | ||
fileprivate func write(toPath filePath: String) throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extension also exists in another module, but this plug in module cannot depend on any other library we have in this package |
||
#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 | ||
} | ||
Comment on lines
+137
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can't be simplified?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah nvm, it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup. tried that 🙂. Took me awhile to get this right. Linux availability support is... bad (read: nonexistent). |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this argument name. If you've got better ideas, I am all ears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--swift-sources-file-path
--swift-source-files-file-path
--swift-source-list-file-path
Best I got
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooooh
swiftSources
is good.