-
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
Allow build & run to reference unreachable targets #1284
Conversation
6c97ff5 to
e3583b5
Compare
| // Create build target description for each target which we need to plan. | ||
| var targetMap = [ResolvedTarget: TargetDescription]() | ||
| for target in graph.targets { | ||
| for target in graph.allTargets { |
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 build is 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.
| }) else { | ||
| throw RunError.executableNotFound(executable) | ||
| } | ||
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.
nit: avoid whitespace diffs
| guard rootExecutables.count == 1 else { | ||
| throw RunError.multipleExecutables(rootExecutables.map({ $0.name })) | ||
| } | ||
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.
nit: avoid whitespace diffs
| XCTAssert(!output.contains("BLibrary")) | ||
| XCTAssert(!output.contains("bexec")) | ||
| XCTAssert(!output.contains("BTarget1")) | ||
| XCTAssert(!output.contains("BTarget2")) |
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.
I'll land some APIs for string pattern matching. That should help a lot in this type of asserts.
e3583b5 to
a5edec5
Compare
Sources/Build/llbuild.swift
Outdated
| switch description { | ||
| case .swift(let description): | ||
| targets.append(createSwiftCompileTarget(description), | ||
| isReachable: plan.graph.targets.contains(target), |
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.
This will be slow. We can add a method in package graph which internally uses a set for fast lookup.
Sources/Build/llbuild.swift
Outdated
| switch description { | ||
| case .swift(let description): | ||
| targets.append(createSwiftCompileTarget(description), | ||
| isReachable: plan.graph.targets.contains(target), |
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.
We should also add some comments here about the isReachable and why it is needed.
Sources/Build/llbuild.swift
Outdated
|
|
||
| /// Append a command. | ||
| mutating func append(_ target: Target, isTest: Bool) { | ||
| mutating func append(_ target: Target, isReachable: Bool, isTest: Bool) { |
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.
How about buildByDefault?
| return executableProduct | ||
| } else { | ||
| // If the executably is implicit, search through root products. | ||
| let rootExecutables = plan.graph.rootPackages.flatMap({ $0.products }).filter({ $0.type == .executable }) |
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.
nit: matchingRootExecutables
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.
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".
24c09eb to
7a87824
Compare
| let plan = try BuildPlan(buildParameters: mockBuildParameters(), graph: graph) | ||
|
|
||
| XCTAssertEqual(Set(plan.buildProducts.map({ $0.product.name })), ["aexec", "ATarget", "BLibrary", "bexec", "cexec"]) | ||
| XCTAssertEqual(Set(plan.targets.map({ |
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.
We have BuildPlanResult to assert the build plan in an easier way.
| } | ||
| } | ||
|
|
||
| func testNonReachableProductsAndTargets() throws { |
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.
This test should be in `BuildPlanTests``
7a87824 to
d11e5a7
Compare
| import Basic | ||
| import Build | ||
| import Commands | ||
| import PackageDescription4 |
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.
Are these imports required?
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.
Nope, nice catch!
| import PackageDescription | ||
| import PackageDescription4 | ||
|
|
||
| private struct MockToolchain: Toolchain { |
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.
This doesn't need to be moved now, right?
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.
Correct!
d11e5a7 to
cb71bd7
Compare
|
@swift-ci please smoke test |
cb71bd7 to
0e6f30d
Compare
|
@swift-ci please smoke test |
No description provided.