-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be48b2a
commit a7df916
Showing
5 changed files
with
89 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 33 additions & 29 deletions
62
Plugins/LicenseProviderPlugin/LicenseProviderPlugin.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,78 @@ | ||
import PackagePlugin | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main | ||
struct LicenseViewPlugin { | ||
static let commandName = "LicenseProviderExec" | ||
|
||
func sourcePackagesPath(workDirectory: URL) -> URL? { | ||
var workDirectory = workDirectory | ||
|
||
guard workDirectory.absoluteString.contains("SourcePackages") else { | ||
return nil | ||
} | ||
|
||
while workDirectory.lastPathComponent != "SourcePackages" { | ||
workDirectory = workDirectory.deletingLastPathComponent() | ||
} | ||
|
||
return workDirectory | ||
} | ||
|
||
func buildCommands(executablePath: URL, workDirectory: URL) -> Command? { | ||
let fileName = "LicenseProvider.swift" | ||
|
||
let output = workDirectory.appending(path: fileName) | ||
guard let sourcePackages = sourcePackagesPath(workDirectory: workDirectory) else { | ||
return nil | ||
} | ||
|
||
return .buildCommand( | ||
displayName: "LicenseProviderPlugin", | ||
executable: executablePath, | ||
arguments: [ | ||
output.path(), | ||
sourcePackages.path() | ||
sourcePackages.path(), | ||
], | ||
outputFiles: [ output ] | ||
outputFiles: [output] | ||
) | ||
} | ||
} | ||
|
||
extension LicenseViewPlugin: BuildToolPlugin { | ||
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] { | ||
let executablePath = try context.tool(named: LicenseViewPlugin.commandName).url | ||
|
||
guard let command = buildCommands( | ||
executablePath: executablePath, | ||
workDirectory: context.pluginWorkDirectoryURL | ||
) else { | ||
|
||
guard | ||
let command = buildCommands( | ||
executablePath: executablePath, | ||
workDirectory: context.pluginWorkDirectoryURL | ||
) | ||
else { | ||
return [] | ||
} | ||
|
||
return [command] | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
import XcodeProjectPlugin | ||
import XcodeProjectPlugin | ||
|
||
extension LicenseViewPlugin: XcodeBuildToolPlugin { | ||
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] { | ||
let executablePath = try context.tool(named: LicenseViewPlugin.commandName).url | ||
|
||
guard let command = buildCommands( | ||
executablePath: executablePath, | ||
workDirectory: context.pluginWorkDirectoryURL | ||
) else { | ||
return [] | ||
extension LicenseViewPlugin: XcodeBuildToolPlugin { | ||
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] { | ||
let executablePath = try context.tool(named: LicenseViewPlugin.commandName).url | ||
|
||
guard | ||
let command = buildCommands( | ||
executablePath: executablePath, | ||
workDirectory: context.pluginWorkDirectoryURL | ||
) | ||
else { | ||
return [] | ||
} | ||
|
||
return [command] | ||
} | ||
|
||
return [command] | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters