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 cache issues with graph exempt projects #5222

Closed
wants to merge 11 commits into from

Conversation

cdmihai
Copy link
Contributor

@cdmihai cdmihai commented Apr 1, 2020

Fixes #4386

This PR fixes the bug cascade that results when exempting projects from graph isolation that also exist in the graph. It implements this region of the docs: https://github.com/microsoft/msbuild/compare/master...cdmihai:cacheAndIsolationDocumentation?expand=1#diff-5de82af4d8f52787d69b38fd58c509caR44

When a reference is exempt from isolation constraints, there can be multiple situations:

  • the reference does not exist in the graph, or in the input caches files. This is what the original exemption feature was designed for, and it worked great for enabling WPF's on the fly generated projects work with isolation. All the following scenarios were not supported, and fixed in this PR.
  • the reference exists in one or more input cache files. This causes part of the failures in Projects excluded from static graph constraint checks should not appear in the caches #4386. There are multiple sub cases here:
    • the reference is in the input cache, but its build results are not a superset of the current project's requests. This happens when the exempt project is in the input cache with results for other targets than the ones requested by the current project.
    • the reference is in the input cache and is a superset of the current project's requests.

Things this PR changes:

  1. If the CacheAggregator detects conflicting incoming cache entries (conflicting instances of BuldRequestConfiguration and BuildResult), instead of erroring it will now merge them using the "first entry wins" strategy. BuildResults are merged at the level of individual target results. This allows multiple projects to exempt the same reference.
  2. A BuildRequestConfiguration is marked as exempt (new bool field) whenever a building project marks it as exempt.
  3. The override caches (ConfigCacheWithOverride, BuildResultsWithOverride) always ensure an entry is either in the override cache, or the current cache, but not in both.
    a. An exception here is the BuildResultsWithOverride cache, where an exempt configuration can appear in both caches, This happens when the exempt project is present in the input caches, but does not have target results that the current project wants to build. In this case, two things happen. In the ConfigWithOverride cache, the entry is migrated from the override cache to the current cache. In the BuildResultsWithOverride cache, The override entry gets the new, additional targets (not ideal, but it would be super hard to change), and the current cache gets only the newly built targets, to ensure the invariant that the current cache should only contain newly built things, and should never contain results from deserialized caches..

@@ -511,22 +513,24 @@ void InitializeCaches()
_configCache = ((IBuildComponentHost)this).GetComponent(BuildComponentType.ConfigCache) as IConfigCache;
_resultsCache = ((IBuildComponentHost)this).GetComponent(BuildComponentType.ResultsCache) as IResultsCache;

if (!usesInputCaches && (_buildParameters.ResetCaches || _configCache.IsConfigCacheSizeLargerThanThreshold()))
if (usesInputCaches)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Affects non-isolation execution: just a condition simplification, should be benign.

@@ -547,6 +548,12 @@ internal int ResultsNodeId
set => _resultsNodeId = value;
}

public bool SkippedFromStaticGraphIsolationConstraints
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Affects non-isolation execution: new translatable bool that never gets set or read outside isolation execution

@cdmihai
Copy link
Contributor Author

cdmihai commented Apr 3, 2020

I've commented on all the diffs that affect non-isolation code paths, you can search for them with the string Affects non-isolation execution:

@@ -36,58 +51,65 @@ if ($runtime -eq "Desktop") {
$targetFramework = "netcoreapp2.1"
}

$bootstrapBinDirectory = "artifacts\bin\MSBuild.Bootstrap\$configuration\$targetFramework"
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between artifacts\bin\MSBuild.Bootstrap\... vs. artifacts\bin\bootstrap\...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I do not know. I also saw that, but envisioned the hell of trying to understand the diffs so I didn't get into it. @rainersigwald, do you know more? :)

)
}

$filesToCopyToBin += $runtimeSpecificFiles

foreach ($file in $filesToCopyToBin) {
Copy-WithBackup $([IO.Path]::Combine($PSScriptRoot, "..", $file))
Copy-WithBackup $file
}

Write-Host -ForegroundColor Green "Copy succeeded"
Copy link
Member

Choose a reason for hiding this comment

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

Would it sense to break the script change into its own PR?

cdmihai added a commit that referenced this pull request May 1, 2020
Transitive project references are a thing now. Added support to static graph, so that buildxl and qb can avoid adding the transitive refs.
This PR is independent of #5222. Ideally, review this one first, as QB has a stronger dependency on this PR than on #5222.

Design

- transitive references are opt-in, per project evaluation
- once a project opts-in, transitivity is applied for all ProjectReference items
- a project opt-ins by setting the property AddTransitiveProjectReferencesInStaticGraph to true. The sdk does this automatically in Microsoft.Managed.After.Targets.
- interaction with crosstargeting: transitive refs are added only to inner builds, not the outer builds. This mimics vanilla msbuild.

Co-authored-by: Rainer Sigwald <raines@microsoft.com>
Forgind added a commit that referenced this pull request May 4, 2020
* LOC CHECKIN | microsoft/msbuild vs16.6 | 20200420 (#5299)

* Final branding_16.6 (#5273)

* merge

* Enable handshake timeout on Mono (#5318)

I am seeing consistent test hangs on macOS Mono. A node is getting into a bad state and is failing to respond to handshakes. While I do not yet understand the root cause, it is clear that having a timeout on the handshake operation mitigates the issue. The test is now failing but does not hang, saving developer time as well as test pipeline resources.

* Revert "Reverted and rebuilt for localizable strings." (#5246)

This adds back support for logging an error when a task returns false
without logging an error. This was originally added in #4940 but was
reverted because of multiple difficulties.

* Changed error code

* Add escape hatch

* Fix typo

* Filtering for duplicate content files with referencing projects (#4931)

* Updating content filtering based on content copying changes

* Add a flag that is enabled by default on Core; otherwise disabled by default.

* Adding Shutdown Message to Worker Nodes (#5262)

* Changed where Trace is being called and removed old functionality.

* Updating .NET Core branding to .NET (#5286)

* Override default Arcade Xunit configuration (#5302)

* Update Directory.Build.targets

* prevent arcade from injecting its own xunit file

* Don't log @(ReferencePath) at the end of ImplicitlyExpandDesignTimeFacades (#5317)

The actual ItemGroups inside the target already do a good job of logging exactly what items were added and/or removed and in what order and with what metadata.

Emitting an extra low-pri message which is unstructured here just adds noise, slows the builds down, wastes binlog space and is otherwise redundant.

* Compute hashes in parallel in GetFileHash (#5303)

* Compute hashes in parallel. This scales better for larger number of files.

* Use a dedicated write lock

* Allow disabling logging of task parameters and item metadata (#5268)

This enables fine-grained control over whether:

 * to log log each parameter (whether input or output)
 * or whether to log item metadata for each ITaskItem[] parameter.

When LogTaskInputs is set the default behavior is still to log all parameters and all item metadata for ITaskItem[] parameters. Since this is very verbose and hurts performance without adding any useful information it is valuable to be able to turn this logging off in certain situations.

This approach allows controlling logging via setting simple properties or environment variables.

I've identified the specific tasks and parameters that we want to restrict logging for that would give us the most gains without losing any significant useful info:

https://github.com/KirillOsenkov/MSBuildStructuredLog/wiki/Task-Parameter-Logging

* Update dependencies from https://github.com/dotnet/arcade build 20200430.5 (#5325)

- Microsoft.DotNet.Arcade.Sdk: 1.0.0-beta.20221.2 -> 1.0.0-beta.20230.5

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>

* Use environment variable for handshake Resolves #4961 (#5196)

* Use environment variable for handshake Resolves #4961

* Combine means of hashing

* Support transitive project references in static graph (#5326)

Transitive project references are a thing now. Added support to static graph, so that buildxl and qb can avoid adding the transitive refs.
This PR is independent of #5222. Ideally, review this one first, as QB has a stronger dependency on this PR than on #5222.

Design

- transitive references are opt-in, per project evaluation
- once a project opts-in, transitivity is applied for all ProjectReference items
- a project opt-ins by setting the property AddTransitiveProjectReferencesInStaticGraph to true. The sdk does this automatically in Microsoft.Managed.After.Targets.
- interaction with crosstargeting: transitive refs are added only to inner builds, not the outer builds. This mimics vanilla msbuild.

Co-authored-by: Rainer Sigwald <raines@microsoft.com>

Co-authored-by: Martin Chromecek (Moravia IT) <v-chmart@microsoft.com>
Co-authored-by: Ladi Prosek <laprosek@microsoft.com>
Co-authored-by: Sarah Oslund <sfoslund@microsoft.com>
Co-authored-by: Ben Villalobos <villalobosb93@gmail.com>
Co-authored-by: Mihai Codoban <codobanmihai@gmail.com>
Co-authored-by: Kirill Osenkov <KirillOsenkov@users.noreply.github.com>
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
sfoslund pushed a commit to sfoslund/msbuild that referenced this pull request May 15, 2020
Transitive project references are a thing now. Added support to static graph, so that buildxl and qb can avoid adding the transitive refs.
This PR is independent of dotnet#5222. Ideally, review this one first, as QB has a stronger dependency on this PR than on dotnet#5222.

Design

- transitive references are opt-in, per project evaluation
- once a project opts-in, transitivity is applied for all ProjectReference items
- a project opt-ins by setting the property AddTransitiveProjectReferencesInStaticGraph to true. The sdk does this automatically in Microsoft.Managed.After.Targets.
- interaction with crosstargeting: transitive refs are added only to inner builds, not the outer builds. This mimics vanilla msbuild.

Co-authored-by: Rainer Sigwald <raines@microsoft.com>
@rainersigwald
Copy link
Member

Talked to @cdmihai offline; the plan is to go a different direction.

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.

Projects excluded from static graph constraint checks should not appear in the caches
3 participants