diff --git a/Build/BizHawk.Build.Tool.exe b/Build/BizHawk.Build.Tool.exe index 895e92bb20..8102768f11 100644 Binary files a/Build/BizHawk.Build.Tool.exe and b/Build/BizHawk.Build.Tool.exe differ diff --git a/Build/BizHawk.Build.Tool/FileLocator.cs b/Build/BizHawk.Build.Tool/FileLocator.cs index 32f97e35fe..5313b62463 100644 --- a/Build/BizHawk.Build.Tool/FileLocator.cs +++ b/Build/BizHawk.Build.Tool/FileLocator.cs @@ -5,7 +5,7 @@ using Microsoft.Win32; static class FileLocator { - public static string LocateSVNTool(string _toolName) + public static string LocateTool(string _toolName) { string t = ToolPathUtil.MakeToolName(_toolName); string dir = null; @@ -34,7 +34,10 @@ static class FileLocator @"CollabNet Subversion Client", @"VisualSVN\bin", @"VisualSVN Server\bin", - @"SlikSvn\bin"); + @"TortoiseSVN\bin", + @"SlikSvn\bin", + @"Git\bin" + ); if (toolPath == null) { diff --git a/Build/BizHawk.Build.Tool/Tool.cs b/Build/BizHawk.Build.Tool/Tool.cs index ca2cbdaee7..2409d360fa 100644 --- a/Build/BizHawk.Build.Tool/Tool.cs +++ b/Build/BizHawk.Build.Tool/Tool.cs @@ -14,7 +14,8 @@ namespace BizHawk.Build.Tool string[] cmdArgs = Crop(args, 1); switch (cmd.ToUpperInvariant()) { - case "SVN_REV": SVN_REV(cmdArgs); break; + case "SVN_REV": SVN_REV(true,cmdArgs); break; + case "GIT_REV": SVN_REV(false,cmdArgs); break; } } @@ -68,7 +69,7 @@ namespace BizHawk.Build.Tool //gets the working copy version. use this command: //BizHawk.Build.Tool.exe SCM_REV --wc c:\path\to\wcdir --template c:\path\to\templatefile --out c:\path\to\outputfile.cs //if the required tools aren't found - static void SVN_REV(string[] args) + static void SVN_REV(bool svn, string[] args) { string wcdir = null, templatefile = null, outfile = null; int idx=0; @@ -90,25 +91,54 @@ namespace BizHawk.Build.Tool //pick revision 0 in case the WC investigation fails int rev = 0; - //try to find an SVN and run it - string svn = FileLocator.LocateSVNTool("svnversion"); - if (svn != "") + //pick branch unnamed in case investigation fails (or isnt git) + string branch = ""; + + //try to find an SVN or GIT and run it + if (svn) { - try { - string output = RunTool(svn, wcdir); - var parts = output.Split(':'); - var rstr = parts[parts.Length - 1]; - rstr = Regex.Replace(rstr, "[^0-9]", ""); - rev = int.Parse(rstr); - } - catch(Exception ex) + string svntool = FileLocator.LocateTool("svnversion"); + if (svntool != "") { - Console.WriteLine(ex); + try + { + string output = RunTool(svntool, wcdir); + var parts = output.Split(':'); + var rstr = parts[parts.Length - 1]; + rstr = Regex.Replace(rstr, "[^0-9]", ""); + rev = int.Parse(rstr); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + } + } + else + { + string gittool = FileLocator.LocateTool("git"); + if (gittool != "") + { + try + { + string output = RunTool(gittool, "-C", wcdir, "rev-list", "HEAD", "--count"); + if(int.TryParse(output, out rev)) + { + output = RunTool(gittool, "-C", wcdir, "rev-parse", "--abbrev-ref", "HEAD"); + if(output.StartsWith("fatal")) {} + else branch = output; + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } } } //replace the template and dump the results if needed templateContents = templateContents.Replace("$WCREV$", rev.ToString()); + templateContents = templateContents.Replace("$WCBRANCH$", branch); WriteTextIfChanged(outfile, templateContents); } } diff --git a/Build/BizHawk.Build.Tool/ToolPathUtil.cs b/Build/BizHawk.Build.Tool/ToolPathUtil.cs index f2addaf21c..5ec7d75da1 100644 --- a/Build/BizHawk.Build.Tool/ToolPathUtil.cs +++ b/Build/BizHawk.Build.Tool/ToolPathUtil.cs @@ -59,12 +59,17 @@ static class ToolPathUtil public static string FindInProgramFiles(string toolName, params string[] commonLocations) { - foreach (string location in commonLocations) + var trials = new[] { Environment.GetEnvironmentVariable("ProgramFiles(x86)"), Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) }; + foreach (var t in trials) { - string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), location); - if (SafeFileExists(path, toolName)) + if (t == null) continue; + foreach (string location in commonLocations) { - return path; + string path = Path.Combine(t, location); + if (SafeFileExists(path, toolName)) + { + return path; + } } }