-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Store the correct package name in PackagePIFBuilder.LinkedPackageBinary metadata #9436
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?
Conversation
| } | ||
|
|
||
| init?(dependency: ResolvedModule.Dependency, package: ResolvedPackage) { | ||
| init?(dependency: ResolvedModule.Dependency) { |
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 was the root cause: Note how we wrongly forward the client package name (i.e., package.name) to PackagePIFBuilder.LinkedPackageBinary, binding it to the incorrect package.
bkhouri
left a comment
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.
Can we add automated test to ensure we don't the behaviour does not regress?
|
@swift-ci test |
@bkhouri We do have a few tests in the Xcode side of things... but nothing in SwiftPM OSS touches |
|
@swift-ci test windows |
|
@swift-ci test |
@pmattos : Just because tests exists in the Xcode side of this, it does not mean test in SwiftPM should be omitted :) Submitting tests in a future PR does not guarantee we will not regress the behaviour between now and then. Every change should have an associated tests to validate the behaviour. We have a framework in place to verify PIF changes. Have a look at https://github.com/swiftlang/swift-package-manager/blob/main/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift, so hopefully writting an automated tests can be trivial. |
Motivation:
When using the new PIF builder (i.e.,
--build-system swiftbuild), the returned[PackagePIFBuilder.LinkedPackageBinary]objects were lacking package dependencies information.For instance, given this simple sample package:
This would be the expected build graph (by traversing the returned
[PackagePIFBuilder.ModuleOrProduct]array):...but this is what we would be getting instead (ie, note that all
swift-collectionsdependencies are missing from the graph):Why this issue wasn't breaking the package build too?
Good question! The sample package built just fine with the new PIF builder (i.e.,
--build-system swiftbuild) even thoughPackagePIFBuilder.LinkedPackageBinaryencoded the wrong information, as outlined above. This happened because the build is driven exclusively by the PIF, which is correct.The broken
PackagePIFBuilder.LinkedPackageBinaryobjects are only a side effect of computing the PIF and don't effect the build at all. The bug would only manifest in clients who calledPackagePIFBuilderdirectly and then inspected the resulting build graph from such auxiliary metadata (e.g., Xcode).Modifications:
The root cause was how we initialized
LinkedPackageBinaryobjects during the PIF construction. For a given package dependency, we were incorrectly reusing the client package as the package name (i.e., it should be the package name where the dependency is coming from instead).This PR also replaces
packageName: StringwithPackageIdentityfor tracking packages inLinkedPackageBinaryobjects, ensuring unique IDs for packages (and exposing a more typesafe API too).Result:
This fixes rdar://154408350 (New SwiftPM PIF packages builder breaks previews in Xcode).