Allow host info passed in from the command line to override machine settings (#5904)

* Allow host info passed in from the command line to override machine settings

* Simplify the logic

* Address PR comments to keep a separate HostRid and HostOSName that are static

* Rename to BuildInfo.props

* Address PR comments

* Fix the previous merge

* Fix spacing

* Address PR comments
This commit is contained in:
Justin Goshi 2017-03-08 09:10:53 -10:00 committed by GitHub
parent 22816d7958
commit 45a1e9e56c
13 changed files with 73 additions and 25 deletions

39
build/BuildInfo.targets Normal file
View file

@ -0,0 +1,39 @@
<Project ToolsVersion="15.0">
<Target Name="WriteBuildInfoProps"
DependsOnTargets="BuildDotnetCliBuildFramework">
<GetCurrentRuntimeInformation>
<Output TaskParameter="Rid" PropertyName="HostRid" />
<Output TaskParameter="OSName" PropertyName="HostOSName" />
</GetCurrentRuntimeInformation>
<PropertyGroup>
<Rid Condition=" '$(Rid)' == '' ">$(HostRid)</Rid>
<Architecture Condition=" '$(Architecture)' == '' ">x64</Architecture>
<OSName Condition=" '$(OSName)' == '' ">$(HostOSName)</OSName>
<BuildInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
&lt;Rid&gt;$(Rid)&lt;/Rid&gt;
&lt;Architecture&gt;$(Architecture)&lt;/Architecture&gt;
&lt;OSName&gt;$(OSName)&lt;/OSName&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</BuildInfoPropsContent>
<ExistingBuildInfoPropsContent Condition=" Exists('$(BuildInfoProps)') ">
$([System.IO.File]::ReadAllText($(BuildInfoProps)))
</ExistingBuildInfoPropsContent>
<ShouldOverwriteBuildInfoPropsFile>false</ShouldOverwriteBuildInfoPropsFile>
<ShouldOverwriteBuildInfoPropsFile
Condition=" '$(ExistingBuildInfoPropsContent.Trim())' != '$(BuildInfoPropsContent.Trim())' ">true</ShouldOverwriteBuildInfoPropsFile>
</PropertyGroup>
<WriteLinesToFile File="$(BuildInfoProps)"
Lines="$(BuildInfoPropsContent)"
Condition=" '$(ShouldOverwriteBuildInfoPropsFile)' == 'true' "
Overwrite="true" />
</Target>
</Project>

View file

@ -22,10 +22,6 @@
<GitInfoCommitHash>%(GitInfoCommitHashLines.Identity)</GitInfoCommitHash>
<ShouldOverWriteThePropsFile
Condition=" 'ForceStringComparison$(CommitCount)' != 'ForceStringComparison$(GitInfoCommitCount)' Or
'$(CommitHash)' != '$(GitInfoCommitHash)' ">true</ShouldOverWriteThePropsFile>
<GitCommitInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
@ -34,12 +30,19 @@
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</GitCommitInfoPropsContent>
<ExistingGitCommitInfoProps Condition=" Exists('$(GitCommitInfoProps)') ">
$([System.IO.File]::ReadAllText($(GitCommitInfoProps)))
</ExistingGitCommitInfoProps>
<ShouldOverwriteGitCommitInfoPropsFile>false</ShouldOverwriteGitCommitInfoPropsFile>
<ShouldOverwriteGitCommitInfoPropsFile
Condition=" '$(ExistingGitCommitInfoProps.Trim())' != '$(GitCommitInfoPropsContent.Trim())' ">true</ShouldOverwriteGitCommitInfoPropsFile>
</PropertyGroup>
<WriteLinesToFile File="$(GitCommitInfoProps)"
Lines="$(GitCommitInfoPropsContent)"
Condition=" '$(ShouldOverwriteThePropsFile)' == 'true' "
Condition=" '$(ShouldOverwriteGitCommitInfoPropsFile)' == 'true' "
Overwrite="true" />
</Target>
</Project>

View file

@ -2,10 +2,9 @@
<Target Name="WriteHostInfoProps"
Condition=" !Exists('$(HostInfoProps)') "
DependsOnTargets="BuildDotnetCliBuildFramework">
<!-- Current Runtime Information -->
<GetCurrentRuntimeInformation>
<Output TaskParameter="Rid" PropertyName="HostRid" />
<Output TaskParameter="Architecture" PropertyName="HostArchitecture" />
<Output TaskParameter="OSName" PropertyName="HostOSName" />
</GetCurrentRuntimeInformation>
@ -13,9 +12,8 @@
<HostInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
&lt;Rid&gt;$(HostRid)&lt;/Rid&gt;
&lt;Architecture&gt;$(HostArchitecture)&lt;/Architecture&gt;
&lt;OSName&gt;$(HostOSName)&lt;/OSName&gt;
&lt;HostRid&gt;$(HostRid)&lt;/HostRid&gt;
&lt;HostOSName&gt;$(HostOSName)&lt;/HostOSName&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</HostInfoPropsContent>

View file

@ -3,5 +3,6 @@
<GeneratedPropsDir>$(RepoRoot)/artifacts/obj</GeneratedPropsDir>
<GitCommitInfoProps>$(GeneratedPropsDir)/GitCommitInfo.props</GitCommitInfoProps>
<HostInfoProps>$(GeneratedPropsDir)/HostInfo.props</HostInfoProps>
<BuildInfoProps>$(GeneratedPropsDir)/BuildInfo.props</BuildInfoProps>
</PropertyGroup>
</Project>

View file

@ -3,7 +3,8 @@
DependsOnTargets="BuildDotnetCliBuildFramework;
EnsureGeneratedPropsDirectory;
WriteGitCommitInfoProps;
WriteHostInfoProps"/>
WriteHostInfoProps;
WriteBuildInfoProps"/>
<Target Name="EnsureGeneratedPropsDirectory">
<MakeDir Condition=" !Exists('$(GeneratedPropsDir)') "

View file

@ -7,11 +7,19 @@
DependsOnTargets="Init;DownloadHostAndSharedFxArtifacts;RestoreSrcPackages;RestoreToolsPackages" />
<Target Name="Init"
DependsOnTargets="SetTelemetryProfile;
DependsOnTargets="PrintBuildInfo;
SetTelemetryProfile;
BuildDotnetCliBuildFramework;
CheckPrereqs;">
</Target>
<Target Name="PrintBuildInfo">
<Message Text="Host info - Rid: $(HostRid), OSName: $(HostOSName)" Importance="High" />
<Message Text="Build info - Rid: $(Rid), Architecture: $(Architecture), OSName: $(OSName)" Importance="High" />
<Message Text="If you intended to use a different Rid, Architecture, or OSName run the following command to generate your build state:" Importance="High" />
<Message Text="dotnet msbuild build.proj /p:Architecture=Architecture /p:Rid=Rid /p:OSName=OSName /p:GeneratePropsFile=true /t:WriteDynamicPropsToStaticPropsFiles" Importance="High" />
</Target>
<Target Name="SetTelemetryProfile"
DependsOnTargets="BuildDotnetCliBuildFramework" >
<SetEnvVar Name="DOTNET_CLI_TELEMETRY_PROFILE" Value="$(DOTNET_CLI_TELEMETRY_PROFILE);https://github.com/dotnet/cli;$(CommitHash)" />