Skip to content

Commit

Permalink
Misc fixes for /question build (dotnet#8881)
Browse files Browse the repository at this point in the history
Fix an merge error in GenerateResource.NothingOutOfDate
Avoid the complex state in WriteLines when Lines are empty. /question just always returns true. Add a test.
Add Tracker to bootstrap, makes dogfooding C++ easier.
Add SkipUnchangedFiles to avoid extra copy.

* Dev/yuehuang/main rar (#1)

* Add Question switch to stop the build when targets are not incremental.

* Add question property to tasks.

* Add tests

* Clean up IIncrementalTask interface.

* Add additional tasks.

* Test and Question on this repro.

* fix build

* Fix question in -m.  Fix BindingRedirect to target incremental.

* Fix tests for Linux.

* WIP

* Fix feedbacks

* .

* Revert condition.

* fix feedback.

* touch to rerun.

* Fix merge.

* Fix merge pt2

* Fix merge p3

* Fix fileState when it couldn't resolve some files.

* Fix merge

* Address feedbacks

* Fix test.

* Clean up.

* WIP

* Fix Feedback

* Fix Feedback.

* Update tests

* Address some feedbacks.

* Fix merge conflict

* .

* Improve the messaging for ResGen in question mode.

* Fix Style

* Revert GenerateResource into separate PR.
  • Loading branch information
yuehuang010 authored Aug 4, 2023
1 parent 885df7d commit e08f8d9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
3 changes: 3 additions & 0 deletions eng/BootStrapMSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<ItemGroup>
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\*.targets" />
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\*.props" />
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\Tracker*.dll" />
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\Tracker*.exe" />
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\FileTracker*.dll" />
<SdkResolverFiles Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver\**\*.*" />
<NuGetSdkResolverManifest Include= "$(RepoRoot)src\MSBuild\SdkResolvers\VS\Microsoft.Build.NuGetSdkResolver.xml" Condition="'$(MonoBuild)' != 'true'" />
<NuGetSdkResolverManifest Include= "$(RepoRoot)src\MSBuild\SdkResolvers\Standalone\Microsoft.Build.NuGetSdkResolver.xml" Condition="'$(MonoBuild)' == 'true'" />
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuild/MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@

<!-- Xsds are not TF or arch-specific so copy once them in the outer build -->
<Target Name="CopyXsds" BeforeTargets="Build" Condition="'$(IsInnerBuild)' != 'true'">
<Copy SourceFiles="@(XsdsForVS)" DestinationFiles="@(XsdsForVS-&gt;'$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'xsd'))%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="$(SkipCopyUnchangedFiles)" />
<Copy SourceFiles="@(XsdsForVS)" DestinationFiles="@(XsdsForVS-&gt;'$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'xsd'))%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>

<!-- Include MSBuild.deps.json and MSBuild.runtimeconfig.json in ContentWithTargetPath so they will be copied to the output folder of projects
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/PortableTask/PortableTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

<!-- This is only needed for a test in the MSBuild repo; it is unrelated to the PortableTask sample itself. -->
<Target Name="CopyMSBuildUtilitiesToNewFolder" BeforeTargets="CopyFilesToOutputDirectory">
<Copy SourceFiles="$(PkgMicrosoft_Build_Utilities_Core)\lib\net46\Microsoft.Build.Utilities.Core.dll" DestinationFiles="$(OutDir)\OldMSBuild\Microsoft.Build.Utilities.Core.dll" />
<Copy SourceFiles="$(PkgMicrosoft_Build_Utilities_Core)\lib\net46\Microsoft.Build.Utilities.Core.dll" DestinationFiles="$(OutDir)\OldMSBuild\Microsoft.Build.Utilities.Core.dll" SkipUnchangedFiles="true"/>
</Target>
</Project>
51 changes: 51 additions & 0 deletions src/Tasks.UnitTests/WriteLinesToFile_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,57 @@ public void QuestionWriteLinesWriteOnlyWhenDifferentTest()
}
}

/// <summary>
/// Question WriteLines to return true when Lines are empty.
/// </summary>
[Fact]
public void QuestionWriteLinesWhenLinesAreEmpty()
{
// Test the combination of:
// 1) File exists
// 2) Overwrite
// 3) WriteOnlyWhenDifferent

var fileExists = FileUtilities.GetTemporaryFile();
var fileNotExists = FileUtilities.GetTemporaryFileName();
try
{
TestWriteLines(fileExists, fileNotExists, Overwrite: true, WriteOnlyWhenDifferent: true);
TestWriteLines(fileExists, fileNotExists, Overwrite: false, WriteOnlyWhenDifferent: true);
TestWriteLines(fileExists, fileNotExists, Overwrite: true, WriteOnlyWhenDifferent: false);
TestWriteLines(fileExists, fileNotExists, Overwrite: false, WriteOnlyWhenDifferent: false);
}
finally
{
File.Delete(fileExists);
}

void TestWriteLines(string fileExists, string fileNotExists, bool Overwrite, bool WriteOnlyWhenDifferent)
{
var test1 = new WriteLinesToFile
{
Overwrite = Overwrite,
BuildEngine = new MockEngine(_output),
File = new TaskItem(fileExists),
WriteOnlyWhenDifferent = WriteOnlyWhenDifferent,
FailIfNotIncremental = true,
// Tests Lines = null.
};
test1.Execute().ShouldBeTrue();

var test2 = new WriteLinesToFile
{
Overwrite = Overwrite,
BuildEngine = new MockEngine(_output),
File = new TaskItem(fileNotExists),
WriteOnlyWhenDifferent = WriteOnlyWhenDifferent,
FailIfNotIncremental = true,
Lines = Array.Empty<ITaskItem>(), // Test empty.
};
test2.Execute().ShouldBeTrue();
}
}

/// <summary>
/// Should create directory structure when target <see cref="WriteLinesToFile.File"/> does not exist.
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions src/Tasks/FileIO/WriteLinesToFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ public override bool Execute()

if (FailIfNotIncremental)
{
Log.LogErrorWithCodeFromResources("WriteLinesToFile.ErrorReadingFile", File.ItemSpec);
return false;
if (Lines?.Length > 0)
{
Log.LogErrorWithCodeFromResources("WriteLinesToFile.ErrorReadingFile", File.ItemSpec);
return false;
}
}
else
{
Expand All @@ -143,7 +146,7 @@ public override bool Execute()
}
else
{
if (FailIfNotIncremental)
if (FailIfNotIncremental && Lines?.Length > 0)
{
Log.LogErrorWithCodeFromResources("WriteLinesToFile.ErrorOrWarning", File.ItemSpec, string.Empty);
return false;
Expand Down

0 comments on commit e08f8d9

Please sign in to comment.