go my file uploader
This commit is contained in:
22
tools/UpdateGitRevision/UpdateGitRevision.sln
Normal file
22
tools/UpdateGitRevision/UpdateGitRevision.sln
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateGitRevision", "UpdateGitRevision\UpdateGitRevision.csproj", "{DBD4656C-5F40-4067-A70B-C4460DE20F77}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DBD4656C-5F40-4067-A70B-C4460DE20F77}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
6
tools/UpdateGitRevision/UpdateGitRevision/App.config
Normal file
6
tools/UpdateGitRevision/UpdateGitRevision/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace UpdateRevision
|
||||
{
|
||||
public class CommandLineRunner
|
||||
{
|
||||
public string Result { get; set; }
|
||||
|
||||
public bool RunCommandAndGetOutput(string command, string arguments, string workingFolder)
|
||||
{
|
||||
var p = new Process();
|
||||
p.StartInfo.FileName = command;
|
||||
p.StartInfo.Arguments = arguments;
|
||||
p.StartInfo.WorkingDirectory = workingFolder;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardInput = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.OutputDataReceived += OutputDataReceived;
|
||||
|
||||
try
|
||||
{
|
||||
p.Start();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
p.BeginOutputReadLine(); // Async reading of output to prevent deadlock
|
||||
if (p.WaitForExit(5000))
|
||||
{
|
||||
return p.ExitCode == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e != null && e.Data != null)
|
||||
Result = e.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
259
tools/UpdateGitRevision/UpdateGitRevision/Program.cs
Normal file
259
tools/UpdateGitRevision/UpdateGitRevision/Program.cs
Normal file
@@ -0,0 +1,259 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace UpdateRevision
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static readonly Regex LongGitTagRegex; // e.g.: v3.4-226-g7037fef
|
||||
private static readonly Regex LongVersionRegex; // e.g.: v3.4.226
|
||||
private static readonly Regex ShortVersionRegex; // e.g.: v3.4 (w/o commits)
|
||||
static Program()
|
||||
{
|
||||
var options = RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant;
|
||||
LongGitTagRegex = new Regex(@"\Av(?<major>[0-9]+)\.(?<minor>[0-9]+)-(?<commits>[0-9]+)-g[0-9a-z]+\z", options);
|
||||
LongVersionRegex = new Regex(@"\Av(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<commits>[0-9]+)\z", options);
|
||||
ShortVersionRegex = new Regex(@"\A(?<major>[0-9]+)\.(?<minor>[0-9]+)\z", options);
|
||||
options |= RegexOptions.Multiline;
|
||||
}
|
||||
|
||||
private const int UnknownBuild = 9999;
|
||||
|
||||
private class VersionInfo : IComparable<VersionInfo>, IEquatable<VersionInfo>
|
||||
{
|
||||
public int Major { get; private set; }
|
||||
public int Minor { get; private set; }
|
||||
public int Commits { get; private set; }
|
||||
public string RevisionGuid { get; private set; }
|
||||
|
||||
public VersionInfo()
|
||||
{
|
||||
RevisionGuid = string.Empty;
|
||||
}
|
||||
|
||||
public VersionInfo(string version, string guid = null)
|
||||
{
|
||||
var match = LongGitTagRegex.Match(version);
|
||||
if (!match.Success)
|
||||
match = LongVersionRegex.Match(version);
|
||||
if (!match.Success || string.IsNullOrWhiteSpace(guid))
|
||||
{
|
||||
Commits = UnknownBuild;
|
||||
RevisionGuid = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
Commits = int.Parse(match.Groups["commits"].Value, NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
RevisionGuid = guid.Trim().ToLowerInvariant();
|
||||
}
|
||||
if (!match.Success)
|
||||
match = ShortVersionRegex.Match(version);
|
||||
if (!match.Success)
|
||||
throw new ArgumentException("Invalid version identifier: '" + version + "'");
|
||||
Major = int.Parse(match.Groups["major"].Value, NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
Minor = int.Parse(match.Groups["minor"].Value, NumberStyles.None, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public int CompareTo(VersionInfo vi)
|
||||
{
|
||||
int cmp = 1;
|
||||
if (!object.ReferenceEquals(vi, null))
|
||||
{
|
||||
cmp = Major.CompareTo(vi.Major);
|
||||
if (cmp == 0)
|
||||
cmp = Minor.CompareTo(vi.Minor);
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
||||
public bool Equals(VersionInfo vi)
|
||||
{
|
||||
return object.ReferenceEquals(vi, null) ? false : Major.Equals(vi.Major) && Minor.Equals(vi.Minor) && Commits.Equals(vi.Commits) && RevisionGuid.Equals(vi.RevisionGuid, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as VersionInfo);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0:D}.{1:D}+{2:D}: {3}", Major, Minor, Commits, RevisionGuid);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.ToString().GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(VersionInfo vi1, VersionInfo vi2)
|
||||
{
|
||||
return object.ReferenceEquals(vi2, null) ? object.ReferenceEquals(vi1, null) : vi2.Equals(vi1);
|
||||
}
|
||||
|
||||
public static bool operator !=(VersionInfo vi1, VersionInfo vi2)
|
||||
{
|
||||
return object.ReferenceEquals(vi2, null) ? !object.ReferenceEquals(vi1, null) : !vi2.Equals(vi1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetRepositoryVersions(out VersionInfo currentRepositoryVersion, out VersionInfo latestRepositoryVersion)
|
||||
{
|
||||
var workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
|
||||
var clrHash = new CommandLineRunner();
|
||||
var clrTags = new CommandLineRunner();
|
||||
var gitPath = GetGitPath();
|
||||
if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingDirectory) && clrTags.RunCommandAndGetOutput(gitPath, "describe --long --tags", workingDirectory))
|
||||
{
|
||||
if (!LongGitTagRegex.IsMatch(clrTags.Result))
|
||||
{
|
||||
throw new Exception("Invalid Git version tag: '" + clrTags.Result + "' (vmajor.minor-build expected)");
|
||||
}
|
||||
currentRepositoryVersion = new VersionInfo(clrTags.Result, clrHash.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentRepositoryVersion = new VersionInfo(); // no git repository
|
||||
}
|
||||
if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify refs/heads/master", workingDirectory) && clrTags.RunCommandAndGetOutput(gitPath, "describe --long --tags refs/heads/master", workingDirectory))
|
||||
{
|
||||
if (!LongGitTagRegex.IsMatch(clrTags.Result))
|
||||
{
|
||||
throw new Exception("Invalid Git version tag: '" + clrTags.Result + "' (vmajor.minor-build expected)");
|
||||
}
|
||||
latestRepositoryVersion = new VersionInfo(clrTags.Result, clrHash.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
latestRepositoryVersion = new VersionInfo(); // no git repository
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteWarning(string message)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("WARNING: " + message);
|
||||
}
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
var myName = Environment.GetCommandLineArgs()[0];
|
||||
myName = Path.GetFileNameWithoutExtension(string.IsNullOrWhiteSpace(myName) ? System.Reflection.Assembly.GetEntryAssembly().Location : myName);
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Console.WriteLine("Usage: " + myName + " input-file output-file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var inputFileName = Environment.GetCommandLineArgs()[1];
|
||||
var outputFileName = Environment.GetCommandLineArgs()[2];
|
||||
VersionInfo currentRepositoryVersion;
|
||||
VersionInfo latestRepositoryVersion;
|
||||
|
||||
GetRepositoryVersions(out currentRepositoryVersion, out latestRepositoryVersion);
|
||||
|
||||
Console.WriteLine("Current version: " + currentRepositoryVersion.ToString());
|
||||
Console.WriteLine("Latest version: " + latestRepositoryVersion.ToString());
|
||||
|
||||
var template = File.ReadAllText(inputFileName);
|
||||
var output = template.Replace("$COMMITS$", currentRepositoryVersion.Commits.ToString());
|
||||
|
||||
if (!File.Exists(outputFileName) || File.ReadAllText(outputFileName) != output)
|
||||
File.WriteAllText(outputFileName, output);
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("ERROR: " + myName + ": " + exception.Message + Environment.NewLine + exception.StackTrace);
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetGitPath()
|
||||
{
|
||||
var envPath = Environment.GetEnvironmentVariable("PATH");
|
||||
if (!string.IsNullOrWhiteSpace(envPath))
|
||||
{
|
||||
foreach (var p in envPath.Split(Path.PathSeparator))
|
||||
{
|
||||
var path = Path.Combine(p, "git.exe");
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
var gitPath = Path.Combine("Git", "bin", "git.exe");
|
||||
|
||||
var envProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles");
|
||||
if (!string.IsNullOrWhiteSpace(envProgramFiles))
|
||||
{
|
||||
var path = Path.Combine(envProgramFiles, gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
}
|
||||
|
||||
envProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
|
||||
if (!string.IsNullOrWhiteSpace(envProgramFiles))
|
||||
{
|
||||
var path = Path.Combine(envProgramFiles, gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
}
|
||||
|
||||
var envSystemDrive = Environment.GetEnvironmentVariable("SystemDrive");
|
||||
if (string.IsNullOrEmpty(envSystemDrive))
|
||||
{
|
||||
WriteWarning(@"Environment.GetEnvironmentVariable(""SystemDrive"") returned null!");
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(envSystemDrive))
|
||||
{
|
||||
var path = Path.Combine(envSystemDrive, "Program Files", gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
|
||||
path = Path.Combine(envSystemDrive, "Program Files (x86)", gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
|
||||
path = Path.Combine(envSystemDrive, gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var cRoot = new DriveInfo("C").RootDirectory.FullName;
|
||||
if (string.IsNullOrWhiteSpace(envSystemDrive) || !cRoot.StartsWith(envSystemDrive, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var path = Path.Combine(cRoot, "Program Files", gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
|
||||
path = Path.Combine(cRoot, "Program Files (x86)", gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
|
||||
path = Path.Combine(cRoot, gitPath);
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
WriteWarning(@"System.IO.DriveInfo(""C"") exception: " + exception.Message);
|
||||
}
|
||||
|
||||
WriteWarning("Might not be able to run Git command line tool!");
|
||||
return "git";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("UpdateAssemblyInfo")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("UpdateAssemblyInfo")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("07219928-b0da-484d-a7de-b3d9470e2e57")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
1
tools/UpdateGitRevision/UpdateGitRevision/README.md
Normal file
1
tools/UpdateGitRevision/UpdateGitRevision/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Based on https://github.com/SubtitleEdit/subtitleedit/tree/master/src/UpdateAssemblyInfo
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<AssemblyName>UpdateGitRevision</AssemblyName>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{DBD4656C-5F40-4067-A70B-C4460DE20F77}</ProjectGuid>
|
||||
<RootNamespace>UpdateGitRevision</RootNamespace>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CommandLineRunner.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Binary file not shown.
Reference in New Issue
Block a user