-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Avoid doing unncecessary work when generating component declaration files #24445
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,7 @@ private int ExecuteCore( | |
if (GenerateDeclaration.HasValue()) | ||
{ | ||
b.Features.Add(new SetSuppressPrimaryMethodBodyOptionFeature()); | ||
b.Features.Add(new SuppressChecksumOptionsFeature()); | ||
} | ||
|
||
if (RootNamespace.HasValue()) | ||
|
@@ -227,6 +228,7 @@ private int ExecuteCore( | |
}); | ||
|
||
var results = GenerateCode(engine, sourceItems); | ||
var isGeneratingDeclaration = GenerateDeclaration.HasValue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular reason the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does a linq |
||
|
||
foreach (var result in results) | ||
{ | ||
|
@@ -255,6 +257,18 @@ private int ExecuteCore( | |
{ | ||
// Only output the file if we generated it without errors. | ||
var outputFilePath = result.InputItem.OutputPath; | ||
var generatedCode = result.CSharpDocument.GeneratedCode; | ||
if (isGeneratingDeclaration) | ||
{ | ||
// When emiting declarations, only write if it the contents are different. | ||
// This allows build incrementalism to kick in when the declaration remains unchanged between builds. | ||
if (File.Exists(outputFilePath) && | ||
string.Equals(File.ReadAllText(outputFilePath), generatedCode, StringComparison.Ordinal)) | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
File.WriteAllText(outputFilePath, result.CSharpDocument.GeneratedCode); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<!-- Used for tracking inputs to component generation --> | ||
<_RazorComponentInputHash></_RazorComponentInputHash> | ||
<_RazorComponentInputCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).RazorComponent.input.cache</_RazorComponentInputCacheFile> | ||
<_RazorComponentDeclarationOutputCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).RazorComponent.output.cache</_RazorComponentDeclarationOutputCacheFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
@@ -85,7 +86,7 @@ Copyright (c) .NET Foundation. All rights reserved. | |
Name="RazorGenerateComponentDeclaration" | ||
DependsOnTargets="$(RazorGenerateComponentDeclarationDependsOn)" | ||
Inputs="$(MSBuildAllProjects);@(RazorComponentWithTargetPath);$(_RazorComponentInputCacheFile)" | ||
Outputs="@(_RazorComponentDeclaration)" | ||
Outputs="$(_RazorComponentDeclarationOutputCacheFile)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prior to this, we relied on the declaration files being older than the inputs to determine if the targets need to be executed. This now uses an explicit marker file. This allows declaration files to not be updated, but for us to track if we at least tried regenerating the declaration file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do the contents of this declaration file look like? Does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The declaration files are the outline of the components with out any body (they kinda look like ref assemblies). It lets us know what components exist and what parameters are on them. Prior to this change, if you were editing
|
||
Condition="'@(RazorComponentWithTargetPath->Count())'!='0'"> | ||
|
||
<ItemGroup> | ||
|
@@ -120,8 +121,13 @@ Copyright (c) .NET Foundation. All rights reserved. | |
TagHelperManifest="$(_RazorComponentDeclarationManifest)" | ||
GenerateDeclaration="true" /> | ||
|
||
<Touch | ||
Files="$(_RazorComponentDeclarationOutputCacheFile)" | ||
AlwaysCreate="true" /> | ||
|
||
<ItemGroup> | ||
<FileWrites Include="@(_RazorComponentDeclaration)" /> | ||
<FileWrites Include="$(_RazorComponentDeclarationOutputCacheFile)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents the pragma checksum from being generated on declaration files. The checksum is used by debugger. Declaration files aren't used as part of debugging, they're only used for component discovery. Having the checksum is actively harmful since any changes to the input would result in the checksum being different.