Skip to content
Permalink
Browse files

[Build] Moved PackageUpdateVersionTask to a separate assembly to simp…

…lify build
  • Loading branch information
xen2 committed Nov 26, 2018
1 parent 0032576 commit 75ea086465b4821afc20d1d96d759629d3e40ed3
@@ -20,7 +20,7 @@ Example of use:
<AdvancedInstallerPath Condition="'$(AdvancedInstallerPath)' == '' And Exists('$(MSBuildProgramFiles32)\Caphyon\Advanced Installer 14.4.2\bin\x86\advinst.exe')">$(MSBuildProgramFiles32)\Caphyon\Advanced Installer 14.4.2\bin\x86\advinst.exe</AdvancedInstallerPath>
</PropertyGroup>

<UsingTask TaskName="Xenko.Core.Tasks.PackageUpdateVersionTask" AssemblyFile="$(XenkoRoot)sources\core\Xenko.Core.Tasks\bin\Release\Xenko.Core.Tasks.exe" />
<UsingTask TaskName="Xenko.GitVersioning.GenerateVersionFile" AssemblyFile="$(XenkoRoot)deps\Xenko.GitVersioning\bin\Debug\net472\Xenko.GitVersioning.dll" />
<!-- TODO: those tasks will work only if the Direct3D11 files have been copied to top folder (currently works thanks to BuildEditorShaders being run before) -->
<UsingTask TaskName="Xenko.Assets.Tasks.PackageGetVersionTask" AssemblyFile="$(XenkoRootBin)Xenko.Assets.dll" />

@@ -88,19 +88,20 @@ Example of use:
</Target>

<!-- Package -->
<Target Name="PreparePackageBuild" DependsOnTargets="RestoreWindows">
<Target Name="PreparePackageBuild">
<PropertyGroup>
<BuildProperties>$(BuildProperties);XenkoGenerateDoc=true;XenkoPackageBuild=true</BuildProperties>
</PropertyGroup>

<!-- Make sure Xenko.Core.Assets is built to run the task to update package version.
<!-- Make sure Xenko.GitVersioning is built to run the task to update package version.
It might be better to move it to a prebuilt assembly if that becomes a problem.
-->
<MSBuild Targets="30-CoreDesign\Xenko_Core_Tasks" Projects="$(XenkoSolution).sln" Properties="$(BuildProperties);Platform=Mixed Platforms"/>
<MSBuild Targets="Restore" Projects="$(XenkoRoot)deps\Xenko.GitVersioning\Xenko.GitVersioning.csproj"/>
<MSBuild Targets="Build" Projects="$(XenkoRoot)deps\Xenko.GitVersioning\Xenko.GitVersioning.csproj"/>

<!-- Create SharedAssemblyInfo.NuGet.cs with Git information (different between official build and internal builds) -->
<PackageUpdateVersionTask Condition="'$(XenkoOfficialBuild)' == 'true'" RootDirectory="$(XenkoRoot)" VersionFile="$(XenkoRoot)sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="$(XenkoRoot)sources\shared\SharedAssemblyInfo.NuGet.cs" />
<PackageUpdateVersionTask Condition="'$(XenkoOfficialBuild)' != 'true'" RootDirectory="$(XenkoRoot)" VersionFile="$(XenkoRoot)sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="$(XenkoRoot)sources\shared\SharedAssemblyInfo.NuGet.cs" SpecialVersion="beta" SpecialVersionGitHeight="true" SpecialVersionGitCommit="true" />
<GenerateVersionFile Condition="'$(XenkoOfficialBuild)' == 'true'" RootDirectory="$(XenkoRoot)" VersionFile="sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="sources\shared\SharedAssemblyInfo.NuGet.cs" SpecialVersionGitCommit="true" />
<GenerateVersionFile Condition="'$(XenkoOfficialBuild)' != 'true'" RootDirectory="$(XenkoRoot)" VersionFile="sources\shared\SharedAssemblyInfo.cs" GeneratedVersionFile="sources\shared\SharedAssemblyInfo.NuGet.cs" SpecialVersion="beta" SpecialVersionGitHeight="true" SpecialVersionGitCommit="true" />
</Target>
<Target Name="BuildForPackage" DependsOnTargets="PreparePackageBuild;BuildWindows;BuildEditorShaders;VSIXPlugin"/>
<Target Name="GeneratePackage" DependsOnTargets="PreparePackageBuild;PrerequisitesInstaller;Package;WritePackageVersionToFile"/>
@@ -0,0 +1,3 @@
bin/
obj/
.vs/
@@ -7,12 +7,10 @@
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Xenko.Core;
using Xenko.Core.IO;

namespace Xenko.Core.Tasks
namespace Xenko.GitVersioning
{
public class PackageUpdateVersionTask : Task
public class GenerateVersionFile : Task
{
/// <summary>
/// Gets or sets the version file.
@@ -47,7 +45,7 @@ public override bool Execute()
return false;
}

if (VersionFile == null || !File.Exists(VersionFile.ItemSpec))
if (VersionFile == null || !File.Exists(Path.Combine(RootDirectory.ItemSpec, VersionFile.ItemSpec)))
{
Log.LogError("VersionFile is not set or doesn't exist");
return false;
@@ -70,7 +68,6 @@ public override bool Execute()
{
var rootDirectory = RootDirectory.ItemSpec;

NativeLibrary.PreloadLibrary("git2-1196807.dll");
var repo = LibGit2Sharp.Repository.IsValid(rootDirectory) ? new LibGit2Sharp.Repository(rootDirectory) : null;
if (repo == null)
{
@@ -79,7 +76,7 @@ public override bool Execute()
}

// TODO: Right now we patch the VersionFile, but ideally we should make a copy and make the build system use it
var versionFileData = File.ReadAllText(VersionFile.ItemSpec);
var versionFileData = File.ReadAllText(Path.Combine(RootDirectory.ItemSpec, VersionFile.ItemSpec));

// Patch AssemblyInformationalVersion
var headCommitSha = repo.Head.Commits.FirstOrDefault()?.Sha;
@@ -89,8 +86,7 @@ public override bool Execute()
if (SpecialVersionGitHeight)
{
// Compute version based on Git info
var versionFileRelative = new UFile(VersionFile.ItemSpec).MakeRelative(rootDirectory).ToWindowsPath();
var height = Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(repo, versionFileRelative);
var height = Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(repo, VersionFile.ItemSpec);
versionSuffix += height.ToString("D5");
}
if (SpecialVersionGitCommit && headCommitSha != null)
@@ -119,7 +115,7 @@ public override bool Execute()
versionFileData = Regex.Replace(versionFileData, "AssemblyInformationalSuffix = (.*);", $"AssemblyInformationalSuffix = {assemblyInformationalSuffix};");

// Write back new file
File.WriteAllText(GeneratedVersionFile.ItemSpec, versionFileData);
File.WriteAllText(Path.Combine(RootDirectory.ItemSpec, GeneratedVersionFile.ItemSpec), versionFileData);

return true;
}
@@ -59,7 +59,7 @@ public static class GitExtensions
/// <returns>The height of the commit. Always a positive integer.</returns>
public static int GetVersionHeight(this Commit commit, string repoRelativeProjectDirectory = null)
{
var baseVersion = VersionFile.GetVersion(commit, repoRelativeProjectDirectory)?.Version?.Version ?? Version0;
var baseVersion = VersionFile.GetVersion(commit, repoRelativeProjectDirectory)?.Version ?? Version0;
int height = commit.GetHeight(c => CommitMatchesVersion(c, baseVersion, repoRelativeProjectDirectory));
return height;
}
@@ -83,8 +83,8 @@ public static int GetVersionHeight(this Repository repo, string repoRelativeProj
VersionOptions workingCopyVersionOptions, committedVersionOptions;
if (IsVersionFileChangedInWorkingCopy(repo, repoRelativeProjectDirectory, out committedVersionOptions, out workingCopyVersionOptions))
{
Version workingCopyVersion = workingCopyVersionOptions?.Version?.Version;
Version headCommitVersion = committedVersionOptions?.Version?.Version ?? Version0;
Version workingCopyVersion = workingCopyVersionOptions?.Version;
Version headCommitVersion = committedVersionOptions?.Version ?? Version0;
if (workingCopyVersion == null || !workingCopyVersion.Equals(headCommitVersion))
{
// The working copy has changed the major.minor version.
@@ -376,7 +376,7 @@ public static string FindLibGit2NativeBinaries(string basePath)
private static bool CommitMatchesVersion(Commit commit, Version expectedVersion, string repoRelativeProjectDirectory)
{
var commitVersionData = VersionFile.GetVersion(commit, repoRelativeProjectDirectory);
Version majorMinorFromFile = commitVersionData?.Version?.Version ?? Version0;
Version majorMinorFromFile = commitVersionData?.Version ?? Version0;
return majorMinorFromFile?.Major == expectedVersion.Major && majorMinorFromFile?.Minor == expectedVersion.Minor && majorMinorFromFile?.Build == expectedVersion.Build && majorMinorFromFile?.Revision == expectedVersion.Revision;
}

@@ -504,7 +504,7 @@ private static void AddReachableCommitsFrom(Commit startingCommit, HashSet<Commi
/// <returns></returns>
private static Version GetIdAsVersionHelper(Commit commit, VersionOptions versionOptions, string repoRelativeProjectDirectory, int? versionHeight)
{
var baseVersion = versionOptions?.Version?.Version ?? Version0;
var baseVersion = versionOptions?.Version ?? Version0;

// The compiler (due to WinPE header requirements) only allows 16-bit version components,
// and forbids 0xffff as a value.
@@ -1,10 +1,10 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Xenko.Core;

namespace Nerdbank.GitVersioning
{
@@ -61,11 +61,11 @@ private static VersionOptions GetVersionFromStream(Stream stream)
{
var text = reader.ReadToEnd();

var publicVersion = Regex.Match(text, "PublicVersion = (.*);");
if (!publicVersion.Success)
var publicVersion = Regex.Match(text, "PublicVersion = \"(.*)\";");
if (!publicVersion.Success || !Version.TryParse(publicVersion.Groups[0].Value, out var parsedVersion))
return null;

return new VersionOptions { Version = new PackageVersion((string)publicVersion.Groups[0].Value) };
return new VersionOptions { Version = parsedVersion };
}
}
}
@@ -1,6 +1,6 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using Xenko.Core;
using System;

namespace Nerdbank.GitVersioning
{
@@ -11,6 +11,6 @@ class VersionOptions
{
public int BuildNumberOffset => 0;

public PackageVersion Version { get; set; }
public Version Version { get; set; }
}
}
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.7.179" ExcludeAssets="runtime" />
<PackageReference Include="LibGit2Sharp" Version="0.25.3" />
</ItemGroup>
</Project>

0 comments on commit 75ea086

Please sign in to comment.
You can’t perform that action at this time.