Refactor tasks

This commit is contained in:
Justin Goshi 2017-02-10 12:13:44 -08:00
parent 0986cc079a
commit 33d83d6639
14 changed files with 144 additions and 130 deletions

View file

@ -7,6 +7,9 @@
<Import Project="build/Microsoft.DotNet.Cli.Monikers.props" />
<PropertyGroup>
<Architecture Condition=" '$(OverrideArchitecture)' != '' ">$(OverrideArchitecture)</Architecture>
<Rid Condition=" '$(OverrideRid)' != '' ">$(OverrideRid)</Rid>
<!--
$(OS) is set to Unix/Windows_NT. This comes from an environment variable on Windows and MSBuild on Unix.
-->

View file

@ -1,34 +1,24 @@
<Project ToolsVersion="15.0">
<Target Name="WriteGitCommitInfoProps"
DependsOnTargets="BuildDotnetCliBuildFramework">
<GetCommitHash RepoRoot="$(RepoRoot)">
<GetCommitCount>
<Output TaskParameter="CommitCount" PropertyName="GitInfoCommitCount" />
</GetCommitCount>
<GetCommitHash>
<Output TaskParameter="CommitHash" PropertyName="GitInfoCommitHash" />
</GetCommitHash>
<GenerateBuildVersionInfo RepoRoot="$(RepoRoot)"
VersionMajor="$(VersionMajor)"
VersionMinor="$(VersionMinor)"
VersionPatch="$(VersionPatch)"
ReleaseSuffix="$(ReleaseSuffix)">
<Output TaskParameter="CommitCount" PropertyName="GitInfoCommitCount" />
<Output TaskParameter="MsiVersion" PropertyName="BuildInfoMsiVersion" />
<Output TaskParameter="VersionBadgeMoniker" PropertyName="BuildInfoVersionBadgeMoniker" />
</GenerateBuildVersionInfo>
<PropertyGroup>
<ShouldOverWriteThePropsFile
Condition=" '$(CommitHash)' != '$(GitInfoCommitHash)' Or
'$(CommitCount)' != '$(GitInfoCommitCount)' Or
'$(MsiVersion)' != '$(BuildInfoMsiVersion)' Or
'$(VersionBadgeMoniker)' != '$(BuildInfoVersionBadgeMoniker)' ">true</ShouldOverWriteThePropsFile>
Condition=" '$(DefaultCommitCount)' != '$(GitInfoCommitCount)' Or
'$(CommitHash)' != '$(GitInfoCommitHash)' ">true</ShouldOverWriteThePropsFile>
<GitCommitInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
&lt;DefaultCommitCount&gt;$(GitInfoCommitCount)&lt;/DefaultCommitCount&gt;
&lt;CommitHash&gt;$(GitInfoCommitHash)&lt;/CommitHash&gt;
&lt;CommitCount&gt;$(GitInfoCommitCount)&lt;/CommitCount&gt;
&lt;MsiVersion&gt;$(BuildInfoMsiVersion)&lt;/MsiVersion&gt;
&lt;VersionBadgeMoniker&gt;$(BuildInfoVersionBadgeMoniker)&lt;/VersionBadgeMoniker&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</GitCommitInfoPropsContent>

View file

@ -3,7 +3,7 @@
Condition=" !Exists('$(HostInfoProps)') "
DependsOnTargets="BuildDotnetCliBuildFramework">
<!-- Current Runtime Information -->
<GetCurrentRuntimeInformation OverrideRid="$(OverrideRid)">
<GetCurrentRuntimeInformation>
<Output TaskParameter="Rid" PropertyName="HostRid" />
<Output TaskParameter="Architecture" PropertyName="HostArchitecture" />
<Output TaskParameter="OSName" PropertyName="HostOSName" />

View file

@ -16,6 +16,9 @@
<Target Name="InitializeCommonProps"
DependsOnTargets="BuildDotnetCliBuildFramework" >
<GetVersionBadgeMoniker>
<Output TaskParameter="VersionBadgeMoniker" PropertyName="VersionBadgeMoniker" />
</GetVersionBadgeMoniker>
<!-- Common Properties -->
<PropertyGroup>

View file

@ -17,12 +17,14 @@
<UsingTask TaskName="DotNetRestorePJ" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="DotNetTest" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="DownloadFile" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateBuildVersionInfo" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateChecksums" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateGuidFromName" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateMsiVersion" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateNuGetPackagesArchiveVersion" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GetCommitCount" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GetCommitHash" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GetCurrentRuntimeInformation" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GetVersionBadgeMoniker" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="MakeRelative" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="RemoveAssetFromDepsPackages" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="ReplaceFileContents" AssemblyFile="$(CLIBuildDll)" />

View file

@ -31,6 +31,14 @@
<GeneratedInstallers Include="$(SdkInstallerFile);$(CombinedFrameworkSdkHostInstallerFile)" />
</ItemGroup>
<GenerateMsiVersion CommitCount="$(CommitCount)"
VersionMajor="$(VersionMajor)"
VersionMinor="$(VersionMinor)"
VersionPatch="$(VersionPatch)"
ReleaseSuffix="$(ReleaseSuffix)">
<Output TaskParameter="MsiVersion" PropertyName="MsiVersion" />
</GenerateMsiVersion>
<GenerateGuidFromName Name="$(SdkInstallerFile)">
<Output TaskParameter="OutputGuid"
PropertyName="SdkInstallerUpgradeCode" />

View file

@ -1,97 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build
{
public class GenerateBuildVersionInfo : ToolTask
{
[Required]
public string RepoRoot { get; set; }
[Required]
public int VersionMajor { get; set; }
[Required]
public int VersionMinor { get; set; }
[Required]
public int VersionPatch { get; set; }
[Required]
public string ReleaseSuffix { get; set; }
[Output]
public string CommitCount { get; set; }
[Output]
public string VersionSuffix { get; set; }
[Output]
public string SimpleVersion { get; set; }
[Output]
public string NugetVersion { get; set; }
[Output]
public string MsiVersion { get; set; }
[Output]
public string VersionBadgeMoniker { get; set; }
private int _commitCount;
public override bool Execute()
{
base.Execute();
var buildVersion = new BuildVersion()
{
Major = VersionMajor,
Minor = VersionMinor,
Patch = VersionPatch,
ReleaseSuffix = ReleaseSuffix,
CommitCount = _commitCount
};
CommitCount = buildVersion.CommitCountString;
VersionSuffix = buildVersion.VersionSuffix;
SimpleVersion = buildVersion.SimpleVersion;
NugetVersion = buildVersion.NuGetVersion;
MsiVersion = buildVersion.GenerateMsiVersion();
VersionBadgeMoniker = Monikers.GetBadgeMoniker();
return true;
}
protected override string ToolName
{
get { return "git"; }
}
protected override MessageImportance StandardOutputLoggingImportance
{
get { return MessageImportance.High; } // or else the output doesn't get logged by default
}
protected override string GenerateFullPathToTool()
{
// Workaround: https://github.com/Microsoft/msbuild/issues/1215
// There's a "git" folder on the PATH in VS 2017 Developer command prompt and it causes msbuild to fail to execute git.
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "git.exe" : "git";
}
protected override string GenerateCommandLineCommands()
{
return $"rev-list --count HEAD";
}
protected override void LogEventsFromTextOutput(string line, MessageImportance importance)
{
_commitCount = int.Parse(line);
}
}
}

View file

@ -0,0 +1,46 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build
{
public class GenerateMsiVersion : Task
{
[Required]
public int CommitCount { get; set; }
[Required]
public int VersionMajor { get; set; }
[Required]
public int VersionMinor { get; set; }
[Required]
public int VersionPatch { get; set; }
[Required]
public string ReleaseSuffix { get; set; }
[Output]
public string MsiVersion { get; set; }
public override bool Execute()
{
var buildVersion = new BuildVersion()
{
Major = VersionMajor,
Minor = VersionMinor,
Patch = VersionPatch,
ReleaseSuffix = ReleaseSuffix,
CommitCount = CommitCount
};
MsiVersion = buildVersion.GenerateMsiVersion();
return true;
}
}
}

View file

@ -0,0 +1,42 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build
{
public class GetCommitCount : ToolTask
{
[Output]
public string CommitCount { get; set; }
protected override string ToolName
{
get { return "git"; }
}
protected override MessageImportance StandardOutputLoggingImportance
{
get { return MessageImportance.High; } // or else the output doesn't get logged by default
}
protected override string GenerateFullPathToTool()
{
// Workaround: https://github.com/Microsoft/msbuild/issues/1215
// There's a "git" folder on the PATH in VS 2017 Developer command prompt and it causes msbuild to fail to execute git.
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "git.exe" : "git";
}
protected override string GenerateCommandLineCommands()
{
return $"rev-list --count HEAD";
}
protected override void LogEventsFromTextOutput(string line, MessageImportance importance)
{
CommitCount = line;
}
}
}

View file

@ -9,9 +9,6 @@ namespace Microsoft.DotNet.Cli.Build
{
public class GetCommitHash : ToolTask
{
[Required]
public string RepoRoot { get; set; }
[Output]
public string CommitHash { get; set; }
@ -42,4 +39,4 @@ namespace Microsoft.DotNet.Cli.Build
CommitHash = line;
}
}
}
}

View file

@ -9,8 +9,6 @@ namespace Microsoft.DotNet.Cli.Build
{
public class GetCurrentRuntimeInformation : Task
{
public string OverrideRid { get; set; }
[Output]
public string Rid { get; set; }
@ -22,7 +20,7 @@ namespace Microsoft.DotNet.Cli.Build
public override bool Execute()
{
Rid = string.IsNullOrEmpty(OverrideRid) ? RuntimeEnvironment.GetRuntimeIdentifier() : OverrideRid;
Rid = RuntimeEnvironment.GetRuntimeIdentifier();
Architecture = RuntimeEnvironment.RuntimeArchitecture;
OSName = Monikers.GetOSShortName();

View file

@ -0,0 +1,22 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build
{
public class GetVersionBadgeMoniker : Task
{
[Output]
public string VersionBadgeMoniker { get; set; }
public override bool Execute()
{
VersionBadgeMoniker = Monikers.GetBadgeMoniker();
return true;
}
}
}

View file

@ -110,11 +110,11 @@ $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
if ($NoBuild)
{
Write-Host "Not building due to --nobuild"
Write-Host "Command that would be run: 'dotnet msbuild build.proj /m /p:Architecture=$Architecture $ExtraParameters'"
Write-Host "Command that would be run: 'dotnet msbuild build.proj /m /p:OverrideArchitecture=$Architecture $ExtraParameters'"
}
else
{
dotnet msbuild build.proj /p:Architecture=$Architecture /p:GeneratingPropsFile=true /t:WriteDynamicPropsToStaticPropsFiles
dotnet msbuild build.proj /m /v:diag /p:Architecture=$Architecture $ExtraParameters
dotnet msbuild build.proj /p:OverrideArchitecture=$Architecture /p:GeneratingPropsFile=true /t:WriteDynamicPropsToStaticPropsFiles
dotnet msbuild build.proj /m /v:diag /p:OverrideArchitecture=$Architecture $ExtraParameters
if($LASTEXITCODE -ne 0) { throw "Failed to build" }
}

View file

@ -179,9 +179,9 @@ export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
echo "${args[@]}"
if [ $BUILD -eq 1 ]; then
dotnet msbuild build.proj /p:Architecture=$ARCHITECTURE /p:GeneratingPropsFile=true /t:WriteDynamicPropsToStaticPropsFiles
dotnet msbuild build.proj /m /v:diag /p:Architecture=$ARCHITECTURE "${args[@]}"
dotnet msbuild build.proj /p:OverrideArchitecture=$ARCHITECTURE /p:GeneratingPropsFile=true /t:WriteDynamicPropsToStaticPropsFiles
dotnet msbuild build.proj /m /v:diag /p:OverrideArchitecture=$ARCHITECTURE "${args[@]}"
else
echo "Not building due to --nobuild"
echo "Command that would be run is: 'dotnet msbuild build.proj /m /p:Architecture=$ARCHITECTURE ${args[@]}'"
echo "Command that would be run is: 'dotnet msbuild build.proj /m /p:OverrideArchitecture=$ARCHITECTURE ${args[@]}'"
fi