-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Incremental build improvements for generated AssemblyInfo.cs #1007
Incremental build improvements for generated AssemblyInfo.cs #1007
Conversation
|
||
<PropertyGroup> | ||
<GeneratedAssemblyInfoFile Condition=" '$(_AssemblyAttributeContentHash)' != '' "> | ||
$(IntermediateOutputPath)$(MSBuildProjectName).AssemblyInfo.$(_AssemblyAttributeContentHash.SubString(0,6))$(DefaultLanguageSourceExtension) |
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.
While I appreciate the effort to keep line lengths down, the whitespace is going to be part of the property value, which will affect log readability, etc.
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.
Is using only 6 chars of hash to avoid long path issues?
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.
No, I was trying to figure out how much is actually needed to have a high probability of changing but not get too long and ugly. Since this is autogenerated and purely aesthetic (like short git commit hashes), i might was well use the full string.
Any preference?
<PropertyGroup> | ||
<GeneratedAssemblyInfoFile Condition=" '$(_AssemblyAttributeContentHash)' != '' "> | ||
$(IntermediateOutputPath)$(MSBuildProjectName).AssemblyInfo.$(_AssemblyAttributeContentHash.SubString(0,6))$(DefaultLanguageSourceExtension) | ||
</GeneratedAssemblyInfoFile> |
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.
I guess everything chomp
s input strings that are file paths, but I'd probably rather see this on one long awful line than have the newline+whitespace in the property.
var assemblyPath = Path.Combine(incrementalBuildCommand.GetOutputDirectory(targetFramework).FullName, "HelloWorld.dll"); | ||
var info = AssemblyInfo.Get(assemblyPath); | ||
|
||
info["AssemblyVersionAttribute"].Should().Be("1.2.4.0"); |
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.
I'd also like to see a check that the previous hashed-name generated AssemblyInfo file is deleted (by IncrementalClean
but that is an implementation detail) after changing it.
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.
@rainersigwald thx, restructured the test completely.
aa528ff
to
59b01e7
Compare
59b01e7
to
f233bec
Compare
@dotnet-bot test Ubuntu16.04 Release please
|
Regarding hash length, I'd prefer if we included all of it just to avoid any question of truncating too aggressively. I am a little concerned about the path length, though. I was thinking we could drop the project name since the file name is already unique for its contents. |
@nguerrera i see your concern. If it doesn't have to be human "understandable" at all, |
@nguerrera Seeing that the file name pops up in the compile error when colliding with attributes defined in user code (e.g. trying to add a custom assembly info file or not using the right TL;DR After some thinking I believe the current form of this PR is what should be done, maybe add some more characters to the hash... |
Why do all the complex hashing stuff? Isn't it faster to just regenerate the file on every build? Sort of like package restore does for project.lock.json where it generates it at an alternate location and copies it over the one actually used to compile if its contents are different, thereby preserving a skip-build feature when the file doesn't actually need to change? |
That's not obvious to me. I'd like to see measurements. The I/O followed by a full comparison could be slower. @davkean was very concerned about this hitting the disk too much on every design-time build when it was first implemented. |
On further thought, if we stick with hashing, we should not include a full source file path. The source file name will go in to the PDB and break PDB determinism if it changes only because the local path to the repo is different. (It can also break the assembly determinism if the PDB is embedded.) $(MSBuildProjectFile) is good enough because that's how other things in obj disambiguate themselves. It has never worked to have to projects with the same file name and the same obj directory. |
I don't follow. If there is no difference in the hash fragment between any two inputs, then those two inputs have colliding hash fragments. A collision of the hash fragments means that the wrong assembly info will be used. |
A while back when I was looking at UI delays, I was seeing a non-trivial amount of tracers where I/O was extremely slooow, probably due to devs opening projects on network shares and the like. You'd hope that %TEMP% was fast (if that's where we'd generate the throwaway) - but if you can avoid hitting the disk that would be best. |
Sry that explanation of mine was sh*. |
Devs who have projects on networks shares are doomed to a meaningless life of drudgery and boredom. Avoiding I/O during a build to cater to them is ... I mean come on, build is all about I/O. Making design-time builds fast is goodness, of course. |
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.
LGTM. @nguerrera are we ready to merge this or do we need to think more about the hash length vs path length limits?
How about using Base64 to encode the hash? Is that short enough to alleviate file length concerns? I don't want to be in the business of picking how many bits are good enough. |
Base64 is a good idea. It would need 28 characters for a SHA1 hash. Another alternative: |
I like "another alternative" a lot. :) |
Then there's no sign of ugly name in PDBs, error messages, just in a stub file for bookkeeping. |
That stub file could even be |
Dont use Maybe |
Closing in favor of #1255 |
…015.2 (dotnet#1007) - Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19515.2
Addresses #967 by:
CoreGenerateAssemblyInfo
into:_CalculateAssemblyAttributes
which producesAssemblyAttribute
items._CalculateGeneratedAssemblyInfoFileName
which uses the presentAssemblyAttribute
items to product the name of the generated assembly info file, using theHash
task introduced in Improve incremental build in presence of globs msbuild#1328:VersionPrefix=1.0.0
=>obj/Debug/netstandard2.0/lib1.AssemblyInfo.e32ef0.cs
VersionPrefix=1.0.1
=>obj/Debug/netstandard2.0/lib1.AssemblyInfo.5be252.cs
Generate*AssemblyAttribute
set tofalse
=>obj/Debug/netstandard2.0/lib1.AssemblyInfo.cs
CoreGenerateAssemblyInfo
then uses the generated file name asOutputs
and is executed on incremental builds only when any of theAssemblyAttribute
items change (even custom ones not generated by the SDK).