Merge pull request #5661 from dotnet/dev/jgoshi/refactorTasks

Refactor tasks used in generate static props files
This commit is contained in:
Piotr Puszkiewicz 2017-02-10 18:01:11 -08:00 committed by GitHub
commit e9561f949f
9 changed files with 80 additions and 86 deletions

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,7 +16,6 @@
<Target Name="InitializeCommonProps"
DependsOnTargets="BuildDotnetCliBuildFramework" >
<!-- Common Properties -->
<PropertyGroup>
<IsDesktopAvailable>False</IsDesktopAvailable>
@ -49,6 +48,11 @@
<VersionSuffix>$(ReleaseSuffix)-$(CommitCount)</VersionSuffix>
<NugetVersion>$(VersionMajor).$(VersionMinor).$(VersionPatch)-$(VersionSuffix)</NugetVersion>
<VersionBadgeMoniker>$(OSName)_$(Architecture)</VersionBadgeMoniker>
<VersionBadgeMoniker Condition=" '$(Rid)' == 'ubuntu.16.04-x64' ">Ubuntu_16_04_x64</VersionBadgeMoniker>
<VersionBadgeMoniker Condition=" '$(Rid)' == 'fedora.23-x64' ">Fedora_23_x64</VersionBadgeMoniker>
<VersionBadgeMoniker Condition=" '$(Rid)' == 'opensuse.13.2-x64' ">openSUSE_13_2_x64</VersionBadgeMoniker>
<VersionBadge>$(BaseOutputDirectory)/$(VersionBadgeMoniker)_$(Configuration)_version_badge.svg</VersionBadge>
<SdkVersion>$(NugetVersion)</SdkVersion>

View file

@ -17,10 +17,11 @@
<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="MakeRelative" 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

@ -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

@ -7,66 +7,11 @@ using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build
{
public class GenerateBuildVersionInfo : ToolTask
public class GetCommitCount : 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"; }
@ -91,7 +36,12 @@ namespace Microsoft.DotNet.Cli.Build
protected override void LogEventsFromTextOutput(string line, MessageImportance importance)
{
_commitCount = int.Parse(line);
var buildVersion = new BuildVersion()
{
CommitCount = int.Parse(line)
};
CommitCount = buildVersion.CommitCountString;
}
}
}
}

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();