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

[Build/PackageGraph] Sink fallback logic for macro/plugin/test products and packages identification into ModulesGraph #7646

Merged
merged 3 commits into from
Jun 10, 2024

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 7, 2024

This is a temporary fix until we can figure out a proper way to
handle situations were all we get is a name of a product or a
target.

Motivation:

Callers or ModulesGraph.{product, target}(for:destination:) cannot always know the right destination to use at the moment because i.e. for test products and targets its contextual. We need a proper fix for this at the level or BuildSystem but for now sinking the logic down into ModulesGraph is the safest option.

Modifications:

  • ModulesGraph.{product, target}(for:destination:) can handle fallback if product/target turn out to be a macro, a plugin or a test.

Result:

--target and --product options should work correctly regardless of underlying product/target kind.

Resolves: rdar://129400066

…ts and packages identification into `ModulesGraph`

This is a temporary fix until we can figure out a proper way to
handle situations were all we get is a name of a product or a
target.

Resolves: rdar://129400066
@xedin
Copy link
Contributor Author

xedin commented Jun 7, 2024

@swift-ci please test

// a macro, plugin, or a test. Ideally we'd ask a build system for a`BuildSubset`
// and get the destination from there but there are other places that need
// refactoring in that way as well.
let buildParameters = if target.buildTriple == .tools {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rauhul FYI, I also fixed problem in symbol graph creation.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to close #7629 when this merges!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

@xedin xedin force-pushed the rdar-129400066 branch from e89c2bc to 3d6473c Compare June 7, 2024 18:45
@xedin
Copy link
Contributor Author

xedin commented Jun 7, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jun 7, 2024

@swift-ci please test Windows platform

@MaxDesiatov MaxDesiatov added the needs tests This change needs test coverage label Jun 9, 2024
Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

IIUC this can be covered in BuildPlanTests, or in SwiftCommandStateTests otherwise?

@MaxDesiatov MaxDesiatov added bug modules graph Modules dependency resolution labels Jun 9, 2024
@xedin
Copy link
Contributor Author

xedin commented Jun 9, 2024

Yeah, I need to figure out where to put the tests for this…

@xedin xedin requested a review from MaxDesiatov June 10, 2024 07:20
@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

@MaxDesiatov I added tests to cross-compilation suite and build operation. While doing that I had an idea:

  1. Change BuildSubset to use an optional for destination parameter and default that to .none
  2. Switch destination parameter of ModulesGraph.{product, target}(for:destination:) to use optional as well which is also defaulted to .none.
  3. This might make "check .destination first and fallback to .tools" better scoped - only applicable when a specific destination is not requested and lets all of the commands use the graph without guessing the destination when its not clear.

WDYT?

@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

@swift-ci please test

@MaxDesiatov
Copy link
Contributor

@MaxDesiatov I added tests to cross-compilation suite and build operation. While doing that I had an idea:

  1. Change BuildSubset to use an optional for destination parameter and default that to .none
  2. Switch destination parameter of ModulesGraph.{product, target}(for:destination:) to use optional as well which is also defaulted to .none.
  3. This might make "check .destination first and fallback to .tools" better scoped - only applicable when a specific destination is not requested and lets all of the commands use the graph without guessing the destination when its not clear.

WDYT?

SGTM

@MaxDesiatov
Copy link
Contributor

@xedin would you be able to confirm that this issue is fixed in this PR? rdar://129400066

@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

@MaxDesiatov Indeed it does!

@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

🤦 forgot to stage private -> internal change last night for computeLLBuildName...

@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

@MaxDesiatov I'll follow-up with optional destination: changes.

@xedin
Copy link
Contributor Author

xedin commented Jun 10, 2024

@swift-ci please test Windows platform

@xedin xedin removed the needs tests This change needs test coverage label Jun 10, 2024
@xedin xedin merged commit 160018b into swiftlang:main Jun 10, 2024
5 checks passed
xedin added a commit that referenced this pull request Jun 14, 2024
…`Modu… (#7668)

…lesGraph.{product, target}(...)` to use optional destination

- Explanation:

  Follow-up to #7646
  
This is mostly NFC change. It makes more sense to default `destination`
to "undefined" when applicable because it's not always possible to know
intended destination based on user input.

This kind of design makes more sense for internal APIs, instead of
having users to pass `.destination` even though it might not be always
correct.

- Main Branch PRs:
#7650

- Risk: Very Low

- Reviewed By: @MaxDesiatov 

- Testing: Existing test-cases were modified and new tests were added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug modules graph Modules dependency resolution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants