From 7a510b311d03cfe96ee5cd505321f342a8505bb4 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 20 Jun 2019 13:53:35 -0700 Subject: [PATCH] Fixup incremental builds with ApplicationPartsDiscovery (dotnet/aspnetcore-tooling#693) \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/df3c4d533ab31c6fbef5ac9178d4ae309eb85159 --- ...Razor.MvcApplicationPartsDiscovery.targets | 11 ++-- ...ApplicationPartDiscoveryIntegrationTest.cs | 58 ++++++++++++++----- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.MvcApplicationPartsDiscovery.targets b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.MvcApplicationPartsDiscovery.targets index 5f1182be43..669cfd40c9 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.MvcApplicationPartsDiscovery.targets +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.MvcApplicationPartsDiscovery.targets @@ -25,12 +25,13 @@ Copyright (c) .NET Foundation. All rights reserved. <_MvcApplicationPartAttributeGeneratedFile>$(IntermediateOutputPath)$(TargetName).MvcApplicationPartsAssemblyInfo$(DefaultLanguageSourceExtension) + <_MvcApplicationPartCacheFile>$(IntermediateOutputPath)$(TargetName).MvcApplicationPartsAssemblyInfo.cache @@ -73,7 +74,7 @@ Copyright (c) .NET Foundation. All rights reserved. In this case, delete the file so that future incremental builds can no longer pick it up. --> @@ -82,6 +83,8 @@ Copyright (c) .NET Foundation. All rights reserved. + + - + diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/ApplicationPartDiscoveryIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/ApplicationPartDiscoveryIntegrationTest.cs index d0eb4978c6..1f07c59299 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/ApplicationPartDiscoveryIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/ApplicationPartDiscoveryIntegrationTest.cs @@ -45,9 +45,10 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildPassed(result); - Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.MvcApplicationPartsAssemblyInfo.cs"); - // We should produced an empty file for build incrementalism - Assert.Empty(File.ReadAllText(Path.Combine(result.Project.DirectoryPath, IntermediateOutputPath, "SimpleMvc.MvcApplicationPartsAssemblyInfo.cs"))); + Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.MvcApplicationPartsAssemblyInfo.cs"); + + // We should produced a cache file for build incrementalism + Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.MvcApplicationPartsAssemblyInfo.cache"); } [Fact] @@ -59,18 +60,30 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildPassed(result); var generatedAttributeFile = Path.Combine(IntermediateOutputPath, "AppWithP2PReference.MvcApplicationPartsAssemblyInfo.cs"); + var cacheFile = Path.Combine(IntermediateOutputPath, "AppWithP2PReference.MvcApplicationPartsAssemblyInfo.cache"); + var outputFile = Path.Combine(IntermediateOutputPath, "AppWithP2PReference.dll"); Assert.FileExists(result, generatedAttributeFile); Assert.FileContains(result, generatedAttributeFile, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute(\"ClassLibrary\")]"); - var thumbPrint = GetThumbPrint(generatedAttributeFile); + var generatedFilethumbPrint = GetThumbPrint(generatedAttributeFile); + var cacheFileThumbPrint = GetThumbPrint(cacheFile); + var outputFileThumbPrint = GetThumbPrint(outputFile); - result = await DotnetMSBuild("Build"); + await AssertIncrementalBuild(); + await AssertIncrementalBuild(); - Assert.BuildPassed(result); + async Task AssertIncrementalBuild() + { + result = await DotnetMSBuild("Build"); - Assert.FileExists(result, generatedAttributeFile); - Assert.Equal(thumbPrint, GetThumbPrint(generatedAttributeFile)); - Assert.AssemblyHasAttribute(result, Path.Combine(OutputPath, "AppWithP2PReference.dll"), "Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute"); + Assert.BuildPassed(result); + + Assert.FileExists(result, generatedAttributeFile); + Assert.Equal(generatedFilethumbPrint, GetThumbPrint(generatedAttributeFile)); + Assert.Equal(cacheFileThumbPrint, GetThumbPrint(cacheFile)); + Assert.Equal(outputFileThumbPrint, GetThumbPrint(outputFile)); + Assert.AssemblyHasAttribute(result, Path.Combine(OutputPath, "AppWithP2PReference.dll"), "Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute"); + } } // Regression test for https://github.com/aspnet/AspNetCore/issues/11315 @@ -128,17 +141,30 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildPassed(result); var generatedAttributeFile = Path.Combine(IntermediateOutputPath, "SimpleMvc.MvcApplicationPartsAssemblyInfo.cs"); - Assert.FileExists(result, generatedAttributeFile); - Assert.Empty(File.ReadAllText(Path.Combine(result.Project.DirectoryPath, generatedAttributeFile))); + var cacheFile = Path.Combine(IntermediateOutputPath, "SimpleMvc.MvcApplicationPartsAssemblyInfo.cache"); + var outputFile = Path.Combine(IntermediateOutputPath, "SimpleMvc.dll"); + Assert.FileDoesNotExist(result, generatedAttributeFile); + Assert.FileExists(result, cacheFile); - var thumbPrint = GetThumbPrint(generatedAttributeFile); + var cacheFilethumbPrint = GetThumbPrint(cacheFile); + var outputFilethumbPrint = GetThumbPrint(outputFile); - result = await DotnetMSBuild("Build"); + // Couple rounds of incremental builds. + await AssertIncrementalBuild(); + await AssertIncrementalBuild(); + await AssertIncrementalBuild(); - Assert.BuildPassed(result); + async Task AssertIncrementalBuild() + { + result = await DotnetMSBuild("Build"); - Assert.FileExists(result, generatedAttributeFile); - Assert.Equal(thumbPrint, GetThumbPrint(generatedAttributeFile)); + Assert.BuildPassed(result); + + Assert.FileDoesNotExist(result, generatedAttributeFile); + Assert.FileExists(result, cacheFile); + Assert.Equal(cacheFilethumbPrint, GetThumbPrint(cacheFile)); + Assert.Equal(outputFilethumbPrint, GetThumbPrint(outputFile)); + } } } }