Skip to content
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

Fix DescriptionPackage resolves targets not exported via products #131

Conversation

dmhts
Copy link
Contributor

@dmhts dmhts commented Jun 27, 2024

Issue

The DescriptionPackage in createPackage mode may currently export internal targets that are not intended to be exported via products. This occurs because PackageBuilder implicitly generates additional products in ResolvedPackage.products for executable and test targets (in addition to the actually exported products). These generated products may depend on internal targets that must not be built by Scipio.

Solution

Unlike ResolvedPackage, the Manifest object accurately reflects all the original manifest properties and is not affected by the issue/feature described above. I suggest using the products from Manifest instead of the ones from ResolvedPackage.

Example

Swift-DocC Plugin exports two products: "Swift-DocC" and "Swift-DocC Preview", but Scipio in the current implementation resolves (for the reason described above) 4 products:

po package.products
▿ 4 elements
  ▿ 0 : <Product: Swift-DocC Preview>
  ▿ 1 : <Product: Swift-DocC>
  ▿ 2 : <Product: SwiftDocCPluginPackageTests>
  ▿ 3 : <Product: snippet-extract>

The last two products SwiftDocCPluginPackageTests and snippet-extract are test and executable targets respectively that were implicitly generated by SwiftPM. In addition, these generated products export some internal targets that should be ignored and not pre-built by Scipio.

Detailed description

products for ResolvedPackage are constructed in PackageBuilder.constructProducts. During the product construction process the builder treats test and executable targets in a special way, including them in the resulting product arrays, namely:

Questions

  • @giginet Would it be fine to open PRs for similar issues right away in the future, or would it be better to discuss them in Issues first?

Copy link
Owner

@giginet giginet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution!
Never mind making a new issue about this.

This PR seems to be almost good, but I found some minor points. Could you resolve them?

I'll check this patch for our product and merge this after them.

["SomeBinary"]
[
"Logging",
"TestingPackage"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just add a trailing comma here to follow the SwiftLint violation.

Suggested change
"TestingPackage"
"TestingPackage",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, it's fixed now. I forgot to run the linter locally.

@@ -65,17 +65,20 @@ final class DescriptionPackageTests: XCTestCase {
}

func testBuildProductsInCreateMode() throws {
let rootPath = fixturePath.appendingPathComponent("BinaryPackage")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing test might aim to test whether it can extract binary targets correctly so it's better to remain the existing tests.

Could you make a new test case for this change and rename the existing tests to testBuildProductsForBinaryPackage or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, my reasoning was that BinaryPackage was already involved in the integration tests, unlike TestingPackage, so I felt safer replacing the former. Of course, keeping the previous test in place makes sense for extra peace of mind. Just fixed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you'd like to change the test name. I thought a package couldn't really be binary, unlike its targets (or wrapping them build products).

@dmhts
Copy link
Contributor Author

dmhts commented Jun 30, 2024

By the way, I also found that this PR fixes the issue of violating Hashable's requirements in debug builds. My guess is that it was somehow related to these implicitly generated products. I'll close the issue for now and keep an eye on it.

Screenshot 2024-06-25 at 15 22 43

Copy link
Owner

@giginet giginet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for everything!

I'll check this PR for our product next week and I'll merge this and publish a new release

@giginet giginet merged commit 205cb96 into giginet:main Jul 1, 2024
3 checks passed
@giginet
Copy link
Owner

giginet commented Jul 2, 2024

Released as 0.20.3 🎉
https://github.com/giginet/Scipio/releases/tag/0.20.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants