dolphin/Source/Core/Common/make_scmrev.h.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

var wshShell = new ActiveXObject("WScript.Shell")
var oFS = new ActiveXObject("Scripting.FileSystemObject");
var outfile = "./Src/scmrev.h";
var cmd_revision = " rev-parse HEAD";
var cmd_describe = " describe --always --dirty";
var cmd_branch = " rev-parse --abbrev-ref HEAD";
function GetGitExe()
{
2011-08-21 21:25:52 -06:00
for (var gitexe in {"git.cmd":1, "git":1})
{
try
{
wshShell.Exec(gitexe);
2011-08-21 21:25:52 -06:00
return gitexe;
}
catch (e)
2011-08-21 21:25:52 -06:00
{}
}
2011-08-21 21:25:52 -06:00
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)
{
2011-08-21 21:25:52 -06:00
// 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 isMaster = 0
if (branch == "master")
isMaster = 1
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 " + isMaster + "\n";
// check if file needs updating
if (out_contents == GetFileContents(outfile))
{
2011-08-21 21:25:52 -06:00
WScript.Echo(outfile + " current at " + revision);
}
else
{
// needs updating - writeout current info
oFS.CreateTextFile(outfile, true).Write(out_contents);
2011-08-21 21:25:52 -06:00
WScript.Echo(outfile + " updated to " + revision);
}