-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow build & run to reference unreachable targets #1284
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 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,17 @@ | ||
| // swift-tools-version:4.0 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "A", | ||
| products: [ | ||
| .executable(name: "aexec", targets: ["ATarget"]) | ||
| ], | ||
| dependencies: [ | ||
| .package(url: "../B", from: "1.0.0"), | ||
| .package(url: "../C", from: "1.0.0") | ||
| ], | ||
| targets: [ | ||
| .target(name: "ATarget", dependencies: [ | ||
| .product(name: "BLibrary") | ||
| ]) | ||
| ]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import BTarget1 | ||
|
|
||
| BTarget1() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // swift-tools-version:4.0 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "B", | ||
| products: [ | ||
| .library(name: "BLibrary", targets: ["BTarget1"]), | ||
| .executable(name: "bexec", targets: ["BTarget2"]) | ||
| ], | ||
| targets: [ | ||
| .target(name: "BTarget1", dependencies: []), | ||
| .target(name: "BTarget2", dependencies: []) | ||
| ]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| public struct BTarget1 { | ||
| public init() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| print("BTarget2") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // swift-tools-version:4.0 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "C", | ||
| products: [ | ||
| .executable(name: "cexec", targets: ["CTarget"]) | ||
| ], | ||
| targets: [ | ||
| .target(name: "CTarget", dependencies: []) | ||
| ]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| print("CTarget") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,27 +126,30 @@ public class SwiftRunTool: SwiftTool<RunToolOptions> { | |
|
|
||
| /// Returns the path to the correct executable based on options. | ||
| private func findProduct(in plan: BuildPlan) throws -> ResolvedProduct { | ||
| let executableProducts = plan.graph.products.filter({ $0.type == .executable }) | ||
|
|
||
| // Error out if the product contains no executable. | ||
| guard executableProducts.count > 0 else { | ||
| throw RunError.noExecutableFound | ||
| } | ||
|
|
||
| if let executable = options.executable { | ||
| // If the exectuable is explicitly specified, verify that it exists. | ||
| guard let executableProduct = executableProducts.first(where: { $0.name == executable }) else { | ||
| // If the exectuable is explicitly specified, search through all products. | ||
| guard let executableProduct = plan.graph.allProducts.first(where: { | ||
| $0.type == .executable && $0.name == executable | ||
| }) else { | ||
| throw RunError.executableNotFound(executable) | ||
| } | ||
|
|
||
| return executableProduct | ||
| } else { | ||
| // If the executably is implicit, search through root products. | ||
| let rootExecutables = plan.graph.rootPackages.flatMap({ $0.products }).filter({ $0.type == .executable }) | ||
|
Contributor
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. nit:
Contributor
Author
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 don't mind, but is it really more explicit? The predicate we are matching against is already in the name: it's the list of "root executables". |
||
|
|
||
| // Error out if the package contains no executables. | ||
| guard rootExecutables.count > 0 else { | ||
| throw RunError.noExecutableFound | ||
| } | ||
|
|
||
| // Only implicitly deduce the executable if it is the only one. | ||
| guard executableProducts.count == 1 else { | ||
| throw RunError.multipleExecutables(executableProducts.map({ $0.name })) | ||
| guard rootExecutables.count == 1 else { | ||
| throw RunError.multipleExecutables(rootExecutables.map({ $0.name })) | ||
| } | ||
|
|
||
| return executableProducts[0] | ||
| return rootExecutables[0] | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Won't this start building all the targets when
swift buildis invoked?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.
Fixed now.