-
Notifications
You must be signed in to change notification settings - Fork 3
Add Swift Build Tool Plugin for automatic dependency validation #3
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
Changes from 1 commit
fde7f85
6d3e436
3f166c0
ee23c93
8081e2f
001e04f
73ecb4f
5850957
b9b8cdc
9f8f95b
9d6d1b2
04068f8
305819c
8bba0c9
a2ffb54
236e24c
c4c6d03
5badd8b
77b95c0
ed0d7ef
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||
| import PackagePlugin | ||||||||||||
| import Foundation | ||||||||||||
|
|
||||||||||||
| /// Swift Package Manager build tool plugin that automatically validates dependencies during builds | ||||||||||||
| @main | ||||||||||||
| struct DependencyAuditPlugin: BuildToolPlugin { | ||||||||||||
|
|
||||||||||||
| /// Creates build commands to run dependency validation | ||||||||||||
| func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { | ||||||||||||
| // Only run on source-based targets that could have dependencies | ||||||||||||
| guard shouldAnalyzeTarget(target) else { | ||||||||||||
| return [] | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Create output directory for plugin results | ||||||||||||
| let outputDir = context.pluginWorkDirectoryURL.appendingPathComponent("DependencyAudit") | ||||||||||||
|
|
||||||||||||
| // Build script content that will execute swift run with our tool | ||||||||||||
| var scriptContent = """ | ||||||||||||
| #!/bin/bash | ||||||||||||
| set -e | ||||||||||||
|
|
||||||||||||
| # Change to package directory | ||||||||||||
| cd "\(context.package.directoryURL.path)" | ||||||||||||
|
|
||||||||||||
| # Run dependency audit for specific target | ||||||||||||
| swift run swift-dependency-audit \\ | ||||||||||||
| "\(context.package.directoryURL.path)" \\ | ||||||||||||
| --target "\(target.name)" \\ | ||||||||||||
| --output-format xcode \\ | ||||||||||||
| --quiet | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| // Add additional arguments based on target type | ||||||||||||
| // Check if target name contains "Test" to identify test targets | ||||||||||||
| if !target.name.lowercased().contains("test") { | ||||||||||||
|
||||||||||||
| // Check if target name contains "Test" to identify test targets | |
| if !target.name.lowercased().contains("test") { | |
| // Check if the target is not a TestTarget to identify non-test targets | |
| if !(target is TestTarget) { |
Outdated
Copilot
AI
Jul 17, 2025
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.
[nitpick] Analyzing all targets can lead to unnecessary executions on non-source modules; consider filtering to SourceModuleTarget instances within shouldAnalyzeTarget to reduce overhead.
| // For now, analyze all targets and let the tool itself filter appropriately | |
| // The tool will skip targets that don't have source directories | |
| return true | |
| // Only analyze source-based targets | |
| return target is SourceModuleTarget |
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.
[nitpick] Invoking the audit tool via
swift runcan be slower and less robust; consider using the PackagePlugin API (context.tool(named:)) to locate and execute theswift-dependency-auditexecutable directly.