-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix crash in PIF generation #9217
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,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"] | ||
} | ||
] | ||
} | ||
} | ||
} |
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" |
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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// swift-tools-version: 5.6 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MyBinaryTargetExePlugin", | ||
|
||
products: [ | ||
.executable( | ||
name: "MyPluginExe", | ||
targets: ["MyPluginExe"] | ||
), | ||
.plugin( | ||
name: "MyPlugin", | ||
targets: ["MyPlugin"] | ||
), | ||
.executable( | ||
name: "MyBinaryTargetExe", | ||
targets: ["MyBinaryTargetExeArtifactBundle"] | ||
), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "MyPluginExe", | ||
dependencies: [], | ||
exclude: [], | ||
), | ||
|
||
.plugin( | ||
name: "MyPlugin", | ||
capability: .buildTool(), | ||
dependencies: ["MyPluginExe", "MyBinaryTargetExeArtifactBundle"] | ||
), | ||
.binaryTarget( | ||
name: "MyBinaryTargetExeArtifactBundle", | ||
path: "Dependency/MyBinaryTargetExeArtifactBundle.artifactbundle" | ||
), | ||
] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import PackagePlugin | ||
|
||
@main | ||
struct MyPlugin: BuildToolPlugin { | ||
|
||
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] { | ||
print("Hello from MyPlugin!") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("It's Me MyPluginExe\n") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,32 @@ struct PIFBuilderTests { | |
#expect(releaseConfig.settings.platformSpecificSettings[.windows]?[.SWIFT_ACTIVE_COMPILATION_CONDITIONS] == ["$(inherited)"]) | ||
} | ||
} | ||
|
||
@Test func pluginWithBinaryTargetDependency() async 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. praise: Great to see more PIF tests in OSS SPM 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. I agree with @pmattos. We should expand the PIF test coverage. Although this is a great test, it's a |
||
try await withGeneratedPIF(fromFixture: "Miscellaneous/Plugins/BinaryTargetExePlugin") { pif, observabilitySystem in | ||
// Verify that PIF generation succeeds for a package with a plugin that depends on a binary target | ||
#expect(pif.workspace.projects.count > 0) | ||
|
||
let project = try pif.workspace.project(named: "MyBinaryTargetExePlugin") | ||
|
||
// Verify the plugin target exists | ||
let pluginTarget = try project.target(named: "MyPlugin") | ||
#expect(pluginTarget.common.name == "MyPlugin") | ||
|
||
// Verify the executable target that uses the plugin exists | ||
let executableTarget = try project.target(named: "MyPluginExe") | ||
#expect(executableTarget.common.name == "MyPluginExe") | ||
|
||
// Verify no errors were emitted during PIF generation | ||
let errors = observabilitySystem.diagnostics.filter { $0.severity == .error } | ||
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. question: do we expect warnings to occur? If no, should we also ensure no warnings exist? if the answer is "we don't care about warning", is there benefits adding a comment indicating so? |
||
#expect(errors.isEmpty, "Expected no errors during PIF generation, but got: \(errors)") | ||
|
||
// Verify that the plugin target has a dependency (binary targets are handled differently in PIF) | ||
// The key test is that PIF generation succeeds without errors when a plugin depends on a binary target | ||
let binaryArtifactMessages = observabilitySystem.diagnostics.filter { | ||
$0.message.contains("found binary artifact") | ||
} | ||
#expect(binaryArtifactMessages.count > 0, "Expected to find binary artifact processing messages") | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.