summaryrefslogtreecommitdiffstats
path: root/src/common/scm_rev_gen.js
diff options
context:
space:
mode:
authorShizZy <shizzy@6bit.net>2013-09-13 23:46:27 +0200
committerShizZy <shizzy@6bit.net>2013-09-13 23:46:27 +0200
commit9709dd2def24260ec2ea4fdc16e3a78fa206bbb9 (patch)
tree0bd5ba71df0a211cf17a8e46d882094ff704c15e /src/common/scm_rev_gen.js
parentrenamed AkiruBinDir to EmuBinDir (diff)
downloadyuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.gz
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.bz2
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.lz
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.xz
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.zst
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.zip
Diffstat (limited to 'src/common/scm_rev_gen.js')
-rw-r--r--src/common/scm_rev_gen.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/common/scm_rev_gen.js b/src/common/scm_rev_gen.js
new file mode 100644
index 000000000..e3ca5e67b
--- /dev/null
+++ b/src/common/scm_rev_gen.js
@@ -0,0 +1,80 @@
+var wshShell = new ActiveXObject("WScript.Shell")
+var oFS = new ActiveXObject("Scripting.FileSystemObject");
+
+var outfile = "./src/scm_rev.h";
+var cmd_revision = " rev-parse HEAD";
+var cmd_describe = " describe --always --long --dirty";
+var cmd_branch = " rev-parse --abbrev-ref HEAD";
+
+function GetGitExe()
+{
+ for (var gitexe in {"git.cmd":1, "git":1})
+ {
+ try
+ {
+ wshShell.Exec(gitexe);
+ return gitexe;
+ }
+ catch (e)
+ {}
+ }
+
+ 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 isMaster = +("master" == 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 " + isMaster + "\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);
+}