diff --git a/src/version.h b/src/version.h index 3b9e8333..3e40acc5 100644 --- a/src/version.h +++ b/src/version.h @@ -26,7 +26,7 @@ //todo - everyone will want to support this eventually, i suppose #ifdef _MSC_VER -#include "svnrev.h" +#include "scmrev.h" #else #ifdef SVN_REV #define SVN_REV_STR SVN_REV diff --git a/vc/defaultconfig/SubWCRev.exe b/vc/defaultconfig/SubWCRev.exe deleted file mode 100644 index 05d576e1..00000000 Binary files a/vc/defaultconfig/SubWCRev.exe and /dev/null differ diff --git a/vc/defaultconfig/make_scmrev.h.js b/vc/defaultconfig/make_scmrev.h.js new file mode 100644 index 00000000..f088387b --- /dev/null +++ b/vc/defaultconfig/make_scmrev.h.js @@ -0,0 +1,100 @@ +var wshShell = new ActiveXObject("WScript.Shell") +var oFS = new ActiveXObject("Scripting.FileSystemObject"); + +var outfile = "./defaultconfig/scmrev.h"; +var cmd_revision = " rev-parse HEAD"; +var cmd_describe = " describe --always --long --dirty"; +var cmd_branch = " rev-parse --abbrev-ref HEAD"; + +function GetGitExe() +{ + try + { + gitexe = wshShell.RegRead("HKCU\\Software\\GitExtensions\\gitcommand"); + wshShell.Exec(gitexe); + return gitexe; + } + catch (e) + {} + + for (var gitexe in {"git.cmd":1, "git":1, "git.bat":1}) + { + try + { + wshShell.Exec(gitexe); + return gitexe; + } + catch (e) + {} + } + + // last try - msysgit not in path (vs2015 default) + msyspath = "\\Git\\cmd\\git.exe"; + gitexe = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") + msyspath; + if (oFS.FileExists(gitexe)) { + return gitexe; + } + gitexe = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%") + msyspath; + if (oFS.FileExists(gitexe)) { + return gitexe; + } + + WScript.Echo("Cannot find git or git.cmd, check your PATH:\n" + + wshShell.ExpandEnvironmentStrings("%PATH%")); + WScript.Quit(1); +} + +function GetFirstStdOutLine(cmd) +{ + try + { + return wshShell.Exec(cmd).StdOut.ReadLine(); + } + catch (e) + { + // catch "the system cannot find the file specified" error + WScript.Echo("Failed to exec " + cmd + " this should never happen"); + WScript.Quit(1); + } +} + +function GetFileContents(f) +{ + try + { + return oFS.OpenTextFile(f).ReadAll(); + } + catch (e) + { + // file doesn't exist + return ""; + } +} + +// get info from git +var gitexe = GetGitExe(); +var revision = GetFirstStdOutLine(gitexe + cmd_revision); +var describe = GetFirstStdOutLine(gitexe + cmd_describe); +var branch = GetFirstStdOutLine(gitexe + cmd_branch); +var isStable = +("master" == branch || "stable" == branch); + +// remove hash (and trailing "-0" if needed) from description +describe = describe.replace(/(-0)?-[^-]+(-dirty)?$/, '$2'); + +var out_contents = + "#define SCM_REV_STR \"" + revision + "\"\n" + + "#define SCM_DESC_STR \"" + describe + "\"\n" + + "#define SCM_BRANCH_STR \"" + branch + "\"\n" + + "#define SCM_IS_MASTER " + isStable + "\n"; + +// check if file needs updating +if (out_contents == GetFileContents(outfile)) +{ + WScript.Echo(outfile + " current at " + describe); +} +else +{ + // needs updating - writeout current info + oFS.CreateTextFile(outfile, true).Write(out_contents); + WScript.Echo(outfile + " updated to " + describe); +} diff --git a/vc/defaultconfig/svnrev.h b/vc/defaultconfig/svnrev.h deleted file mode 100644 index e2669fba..00000000 --- a/vc/defaultconfig/svnrev.h +++ /dev/null @@ -1,5 +0,0 @@ -//this should be overridden with one generated in userconfig -//but it is here just in case to prevent compiler errors - -#define SVN_REV 0 -#define SVN_REV_STR "0" \ No newline at end of file diff --git a/vc/defaultconfig/svnrev_template.h b/vc/defaultconfig/svnrev_template.h deleted file mode 100644 index d7a944d4..00000000 --- a/vc/defaultconfig/svnrev_template.h +++ /dev/null @@ -1,2 +0,0 @@ -#define SVN_REV $WCREV$ -#define SVN_REV_STR "$WCREV$" \ No newline at end of file