Skip to content

Fixing overbuilding of platform negotiated projects#8106

Merged
rokonec merged 13 commits intodotnet:mainfrom
MIchaelRShea:main
Nov 3, 2022
Merged

Fixing overbuilding of platform negotiated projects#8106
rokonec merged 13 commits intodotnet:mainfrom
MIchaelRShea:main

Conversation

@MIchaelRShea
Copy link
Copy Markdown
Contributor

@MIchaelRShea MIchaelRShea commented Oct 31, 2022

Context

Platform negotiation still ends up in situations where project A explicitly tells project B to build as B's default platform. This leads to an unnecessary global property being passed, which leads to an unnecessary evaluation, and in some cases an overbuild.

This PR adds a catch-all that empties out the global Platform property whenever we fall into this case.

Changes Made

Add catch-all if statement that prevents global property Platform to be passed to referenced projects when redundant (the project would have built as that platform anyway).

Testing

Notes

This will unblock the implementation of this feature in VS. the only thing currently blocking adoption of this in VS is our datacenter build(cloudbuild) graph validation. it sees two project nodes with different platform global properties evaluating to the same configuration and throws an error to prevent race conditions.

}
// If the referenced project has a defined `Platform` that's compatible, it will build that way by default.
// Don't set `buildProjectReferenceAs` and the `_GetProjectReferencePlatformProperties` target will handle the rest.
if (!string.IsNullOrEmpty(referencedProjectPlatform) && referencedProjectPlatform.Equals(buildProjectReferenceAs, StringComparison.OrdinalIgnoreCase))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Context: This if statement translates to "Are we about to tell the referenced project to build using its default? Then don't." It's a catch-all check that gets around the other ways in which users could end up in this situation.

@benvillalobos
Copy link
Copy Markdown
Member

Also needs a test 😁

Copy link
Copy Markdown
Member

@benvillalobos benvillalobos left a comment

Choose a reason for hiding this comment

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

Can you add a test that looks like ResolvesViaAnyCPUDefault, but the referenced project has AnyCPU as its default platform? This should result in an empty NearestPlatform, instead of passing AnyCPU.

Note: ResolvesViaAnyCPUDefault doesn't need to be changed, because that captures the scenario where AnyCPU isn't the default platform, but we default to it because there is no match, but AnyCPU is contained in Platforms

Copy link
Copy Markdown
Member

@benvillalobos benvillalobos left a comment

Choose a reason for hiding this comment

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

LGTM!

@benvillalobos benvillalobos added merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. Partner request labels Oct 31, 2022
benvillalobos added a commit to benvillalobos/setplatform-repro that referenced this pull request Oct 31, 2022
@Forgind Forgind removed the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Nov 1, 2022
@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Nov 2, 2022
@rokonec rokonec merged commit 207f713 into dotnet:main Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. Partner request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants