2014-04-23 19:04:33 -07:00
|
|
|
var wshShell = new ActiveXObject("WScript.Shell")
|
|
|
|
var oFS = new ActiveXObject("Scripting.FileSystemObject");
|
2013-09-13 14:46:27 -07:00
|
|
|
|
2014-04-23 19:04:33 -07:00
|
|
|
var outfile = "scm_rev.cpp";
|
|
|
|
var cmd_revision = " rev-parse HEAD";
|
|
|
|
var cmd_describe = " describe --always --long --dirty";
|
|
|
|
var cmd_branch = " rev-parse --abbrev-ref HEAD";
|
2013-09-13 14:46:27 -07:00
|
|
|
|
2014-04-23 19:04:33 -07:00
|
|
|
function GetGitExe() {
|
|
|
|
for (var gitexe in { "git.cmd": 1, "git": 1 }) {
|
|
|
|
try {
|
|
|
|
wshShell.Exec(gitexe);
|
|
|
|
return gitexe;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
2013-09-13 14:46:27 -07:00
|
|
|
|
2014-04-23 19:04:33 -07:00
|
|
|
WScript.Echo("Cannot find git or git.cmd, check your PATH:\n" +
|
|
|
|
wshShell.ExpandEnvironmentStrings("%PATH%"));
|
|
|
|
WScript.Quit(1);
|
2013-09-13 14:46:27 -07:00
|
|
|
}
|
|
|
|
|
2014-04-23 19:04:33 -07:00
|
|
|
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);
|
|
|
|
}
|
2013-09-13 14:46:27 -07:00
|
|
|
}
|
|
|
|
|
2014-04-23 19:04:33 -07:00
|
|
|
function GetFileContents(f) {
|
|
|
|
try {
|
|
|
|
return oFS.OpenTextFile(f).ReadAll();
|
|
|
|
} catch (e) {
|
|
|
|
// file doesn't exist
|
|
|
|
return "";
|
|
|
|
}
|
2013-09-13 14:46:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// get info from git
|
2014-04-23 19:04:33 -07:00
|
|
|
var gitexe = GetGitExe();
|
|
|
|
var revision = GetFirstStdOutLine(gitexe + cmd_revision);
|
|
|
|
var describe = GetFirstStdOutLine(gitexe + cmd_describe);
|
|
|
|
var branch = GetFirstStdOutLine(gitexe + cmd_branch);
|
2013-09-13 14:46:27 -07:00
|
|
|
var isMaster = +("master" == branch);
|
|
|
|
|
|
|
|
// remove hash (and trailing "-0" if needed) from description
|
|
|
|
describe = describe.replace(/(-0)?-[^-]+(-dirty)?$/, '$2');
|
|
|
|
|
|
|
|
var out_contents =
|
2014-04-23 19:04:33 -07:00
|
|
|
"#include \"common/scm_rev.h\"\n" +
|
|
|
|
"namespace Common {\n" +
|
|
|
|
" const char g_scm_rev[] = \"" + revision + "\";\n" +
|
|
|
|
" const char g_scm_branch[] = \"" + branch + "\";\n" +
|
|
|
|
" const char g_scm_desc[] = \"" + describe + "\";\n" +
|
|
|
|
"}\n";
|
2013-09-13 14:46:27 -07:00
|
|
|
|
|
|
|
// check if file needs updating
|
2014-04-23 19:04:33 -07:00
|
|
|
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);
|
2013-09-13 14:46:27 -07:00
|
|
|
}
|