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

Add a restore task report on whether the build files changed #1831

Closed
wants to merge 7 commits into from

Conversation

nkolev92
Copy link
Member

@nkolev92 nkolev92 commented Nov 29, 2017

Bug

Fixes: NuGet/Home#6122
Regression: No
If Regression then when did it last work:
If Regression then how are we preventing it in future:

Fix

Details:
Make restore task report whether the build files changed to optimize double evaluation on build /restore.

It's possible that restore did not happen, yet we save on evaluation if the build assets have not changed.

Right the result is a property that contains the project paths of projects whose assets have changed.

Chatting with @AndyGerlicher to understand if we want the property or we want an item group with more information

Testing/Validation

Tests Added: Yes, only basic tests, can't really test the full integration on our side.
Reason for not adding tests:
Validation done: Manual.

@nkolev92 nkolev92 changed the title [WIP, need to add tests] Add a restore task report on whether the build files changed Add a restore task report on whether the build files changed Nov 30, 2017
Copy link
Member

@emgarten emgarten left a comment

Choose a reason for hiding this comment

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

Looks like a great way to solve this 🚀

foreach (var summary in restoreSummaries)
{
// Success does not matter here, as long as the files are not changed
if(summary.BuildFilesChanged)
Copy link
Member

Choose a reason for hiding this comment

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

nit: spacing

@@ -68,6 +69,9 @@ public class RestoreTask : Microsoft.Build.Utilities.Task, ICancelableTask, IDis
/// </summary>
public bool HideWarningsAndErrors { get; set; }

[Output]
public string OutputRestoreChangedImportsProjectList { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Add a summary for this

// Success does not matter here, as long as the files are not changed
if(summary.BuildFilesChanged)
{
projectsWithImportsChanged.Append(summary.InputPath).Append(';');
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 be easier to just do:
string.Join(";", restoreSummaries.Where(e => e.BuildFilesChanged).Select(e => e.InputPath))

instead of the string builder and loops?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is....didn't think too much about it, my instinct was to not add the extra linq overhead lol :)
This is called only once though :D
So I can change to make it more readable

Copy link
Member

Choose a reason for hiding this comment

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

I get avoiding Linq, it's always a trade off it seems. I'm fine with either one.

@@ -65,6 +65,12 @@ public class RestoreResult : IRestoreResult
/// </summary>
protected string CacheFilePath { get; }

/// <summary>
/// Indicates whether the build files have changed. It will only be updated after the restore result has been committed. It will false Commit has not be called.
Copy link
Member

Choose a reason for hiding this comment

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

It will be false if Commit

@@ -89,7 +89,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Main entry point for restoring packages
============================================================
-->
<Target Name="Restore" DependsOnTargets="_GenerateRestoreGraph">
<Target Name="Restore" DependsOnTargets="_GenerateRestoreGraph" Returns="$(RestoreChangedImportsProjectList)">
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a comment to the targets about this, it is covered in the task but users don't always see that source.

@nkolev92 nkolev92 force-pushed the dev-nkolev92-restoreTaskStatus branch from 572e659 to 352f51e Compare November 30, 2017 07:06
@@ -87,9 +87,11 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
Restore
Main entry point for restoring packages
Returns a property with comma delimited projects whose imports

Choose a reason for hiding this comment

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

is it comma delimited or semicolon delimited list?

Copy link
Member Author

Choose a reason for hiding this comment

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

semicolon...nice catch :)

// Success does not matter here, as long as the files are not changed
if(summary.BuildFilesChanged)
{
projectsWithImportsChanged.Append(summary.InputPath).Append(';');

Choose a reason for hiding this comment

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

i think it shouldn't add an additional ; at the end of the list. It will unnecessary increase load for msbuild to always ignore last item when they split on semicolon.

foreach (var summary in restoreSummaries)
{
// Success does not matter here, as long as the files are not changed
if(summary.BuildFilesChanged)

Choose a reason for hiding this comment

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

will there be a case where restore failed but still changed the targets/props file?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jainaashish
Yeah, restoreSuccess is part of the props.

@nkolev92
Copy link
Member Author

@jainaashish Addressed your feedback.

@ghost ghost removed the cla-already-signed label Dec 6, 2017
@mishra14
Copy link
Contributor

mishra14 commented Dec 9, 2017

🔔

@nkolev92
Copy link
Member Author

nkolev92 commented Dec 9, 2017

@mishra14
Rainer needs to take a look at the changes needed on MSBuild side, so this PR is waiting on an OK from their side.

@rainersigwald
Copy link
Contributor

Hey folks, I'm back from vacation but I've been gone for the lifetime of this. Can someone bring me up to speed?

@emgarten
Copy link
Member

emgarten commented Jan 3, 2018

@rainersigwald the idea here is that restore will tell MSBuild whether or not it changed props/targets files. If it didn't make any changes then MSBuild can avoid clearing the cache.

Since then we found that this may not change much. Restore needs to run with ExcludeRestorePackageImports=true to avoid the outputs of restore becoming inputs and changing the result.

Would avoiding clearing the cache still help even if a global property changed? Is this change still useful for MSBuild?

@AndyGerlicher
Copy link

Unfortunately it's not really useful for MSBuild if that's always the case :(

The easy way to test this is to run msbuild /t:Restore;Build and compare the time to msbuild /restore /t:Build. If they're the same, this optimization won't work (this assumes that evaluation is a significant portion of the build to show up). If the property can be removed and /t:Restore;Build (where it reuses the cached evaluation) becomes faster we should be able to implement this fairly easily.

@nkolev92
Copy link
Member Author

nkolev92 commented Jan 4, 2018

Yeah, we did do some of those before @emgarten improved some of the target perf.

For OrchardCore:

/t:build /restore
Time Elapsed 00:00:57.75
Time Elapsed 00:00:58.31

/t:restore,build
Time Elapsed 00:00:57.81
Time Elapsed 00:00:58.82

Closing this as redundant right now.

@nkolev92 nkolev92 closed this Jan 4, 2018
@nkolev92 nkolev92 deleted the dev-nkolev92-restoreTaskStatus branch January 4, 2018 19:42
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.

7 participants