-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support vending products that are backed by binaryTargets
This adds support for vending an executable product that consists solely of a binary target that is backed by an artifact bundle. This allows vending binary executables as their own separate package, independently of the plugins that are using them. rdar://101096803
- Loading branch information
Showing
21 changed files
with
259 additions
and
82 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
Fixtures/Miscellaneous/Plugins/BinaryToolProductPlugin/Dependency/.gitignore
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
19 changes: 19 additions & 0 deletions
19
...ToolProductPlugin/Dependency/Binaries/MyVendedSourceGenBuildTool.artifactbundle/info.json
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"schemaVersion": "1.0", | ||
"artifacts": { | ||
"mytool": { | ||
"type": "executable", | ||
"version": "1.2.3", | ||
"variants": [ | ||
{ | ||
"path": "mytool-macos/mytool", | ||
"supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"] | ||
}, | ||
{ | ||
"path": "mytool-linux/mytool", | ||
"supportedTriples": ["x86_64-unknown-linux-gnu"] | ||
} | ||
] | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...tPlugin/Dependency/Binaries/MyVendedSourceGenBuildTool.artifactbundle/mytool-linux/mytool
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
print_usage() { | ||
echo "usage: ${0##*/} [--verbose] <in> <out>" | ||
} | ||
|
||
# Parse arguments until we find '--' or an argument that isn't an option. | ||
until [ $# -eq 0 ] | ||
do | ||
case "$1" in | ||
--verbose) verbose=1; shift;; | ||
--) shift; break;; | ||
-*) echo "unknown option: ${1}"; print_usage; exit 1; shift;; | ||
*) break;; | ||
esac | ||
done | ||
|
||
# Print usage and leave if we don't have exactly two arguments. | ||
if [ $# -ne 2 ]; then | ||
print_usage | ||
exit 1 | ||
fi | ||
|
||
# For our sample tool we just copy from one to the other. | ||
if [ $verbose != 0 ]; then | ||
echo "[${0##*/}-linux] '$1' '$2'" | ||
fi | ||
|
||
cp "$1" "$2" |
29 changes: 29 additions & 0 deletions
29
...tPlugin/Dependency/Binaries/MyVendedSourceGenBuildTool.artifactbundle/mytool-macos/mytool
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
print_usage() { | ||
echo "usage: ${0##*/} [--verbose] <in> <out>" | ||
} | ||
|
||
# Parse arguments until we find '--' or an argument that isn't an option. | ||
until [ $# -eq 0 ] | ||
do | ||
case "$1" in | ||
--verbose) verbose=1; shift;; | ||
--) shift; break;; | ||
-*) echo "unknown option: ${1}"; print_usage; exit 1; shift;; | ||
*) break;; | ||
esac | ||
done | ||
|
||
# Print usage and leave if we don't have exactly two arguments. | ||
if [ $# -ne 2 ]; then | ||
print_usage | ||
exit 1 | ||
fi | ||
|
||
# For our sample tool we just copy from one to the other. | ||
if [ $verbose != 0 ]; then | ||
echo "[${0##*/}-macosx] '$1' '$2'" | ||
fi | ||
|
||
cp "$1" "$2" |
18 changes: 18 additions & 0 deletions
18
Fixtures/Miscellaneous/Plugins/BinaryToolProductPlugin/Dependency/Package.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// swift-tools-version: 5.6 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MyBinaryProduct", | ||
products: [ | ||
.executable( | ||
name: "MyVendedSourceGenBuildTool", | ||
targets: ["MyVendedSourceGenBuildTool"] | ||
), | ||
], | ||
targets: [ | ||
.binaryTarget( | ||
name: "MyVendedSourceGenBuildTool", | ||
path: "Binaries/MyVendedSourceGenBuildTool.artifactbundle" | ||
), | ||
] | ||
) |
26 changes: 26 additions & 0 deletions
26
Fixtures/Miscellaneous/Plugins/BinaryToolProductPlugin/Package.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swift-tools-version: 5.6 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MyBinaryToolPlugin", | ||
dependencies: [ | ||
.package(path: "Dependency"), | ||
], | ||
targets: [ | ||
// A local tool that uses a build tool plugin. | ||
.executableTarget( | ||
name: "MyLocalTool", | ||
plugins: [ | ||
"MySourceGenBuildToolPlugin", | ||
] | ||
), | ||
// The plugin that generates build tool commands to invoke MySourceGenBuildTool. | ||
.plugin( | ||
name: "MySourceGenBuildToolPlugin", | ||
capability: .buildTool(), | ||
dependencies: [ | ||
.product(name: "MyVendedSourceGenBuildTool", package: "Dependency"), | ||
] | ||
), | ||
] | ||
) |
34 changes: 34 additions & 0 deletions
34
...ellaneous/Plugins/BinaryToolProductPlugin/Plugins/MySourceGenBuildToolPlugin/plugin.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PackagePlugin | ||
|
||
@main | ||
struct MyPlugin: BuildToolPlugin { | ||
|
||
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { | ||
print("Hello from the Build Tool Plugin!") | ||
guard let target = target as? SourceModuleTarget else { return [] } | ||
let inputFiles = target.sourceFiles.filter({ $0.path.extension == "dat" }) | ||
return try inputFiles.map { | ||
let inputFile = $0 | ||
let inputPath = inputFile.path | ||
let outputName = inputPath.stem + ".swift" | ||
let outputPath = context.pluginWorkDirectory.appending(outputName) | ||
return .buildCommand( | ||
displayName: | ||
"Generating \(outputName) from \(inputPath.lastComponent)", | ||
executable: | ||
try context.tool(named: "mytool").path, | ||
arguments: [ | ||
"--verbose", | ||
"\(inputPath)", | ||
"\(outputPath)" | ||
], | ||
inputFiles: [ | ||
inputPath, | ||
], | ||
outputFiles: [ | ||
outputPath | ||
] | ||
) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Fixtures/Miscellaneous/Plugins/BinaryToolProductPlugin/Sources/MyLocalTool/foo.dat
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
let foo = "I am Foo!" |
1 change: 1 addition & 0 deletions
1
Fixtures/Miscellaneous/Plugins/BinaryToolProductPlugin/Sources/MyLocalTool/main.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
print("Generated string Foo: '\(foo)'") |
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
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
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
Oops, something went wrong.