summaryrefslogtreecommitdiff
path: root/src/common/scm_rev_gen.js
diff options
context:
space:
mode:
authorGravatar ShizZy2013-09-13 17:46:27 -0400
committerGravatar ShizZy2013-09-13 17:46:27 -0400
commit9709dd2def24260ec2ea4fdc16e3a78fa206bbb9 (patch)
tree0bd5ba71df0a211cf17a8e46d882094ff704c15e /src/common/scm_rev_gen.js
parentrenamed AkiruBinDir to EmuBinDir (diff)
downloadyuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.gz
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.tar.xz
yuzu-9709dd2def24260ec2ea4fdc16e3a78fa206bbb9.zip
added scm_rev_gen project to automatically create a header with the git revision on build
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 @@
1var wshShell = new ActiveXObject("WScript.Shell")
2var oFS = new ActiveXObject("Scripting.FileSystemObject");
3
4var outfile = "./src/scm_rev.h";
5var cmd_revision = " rev-parse HEAD";
6var cmd_describe = " describe --always --long --dirty";
7var cmd_branch = " rev-parse --abbrev-ref HEAD";
8
9function GetGitExe()
10{
11 for (var gitexe in {"git.cmd":1, "git":1})
12 {
13 try
14 {
15 wshShell.Exec(gitexe);
16 return gitexe;
17 }
18 catch (e)
19 {}
20 }
21
22 WScript.Echo("Cannot find git or git.cmd, check your PATH:\n" +
23 wshShell.ExpandEnvironmentStrings("%PATH%"));
24 WScript.Quit(1);
25}
26
27function GetFirstStdOutLine(cmd)
28{
29 try
30 {
31 return wshShell.Exec(cmd).StdOut.ReadLine();
32 }
33 catch (e)
34 {
35 // catch "the system cannot find the file specified" error
36 WScript.Echo("Failed to exec " + cmd + " this should never happen");
37 WScript.Quit(1);
38 }
39}
40
41function GetFileContents(f)
42{
43 try
44 {
45 return oFS.OpenTextFile(f).ReadAll();
46 }
47 catch (e)
48 {
49 // file doesn't exist
50 return "";
51 }
52}
53
54// get info from git
55var gitexe = GetGitExe();
56var revision = GetFirstStdOutLine(gitexe + cmd_revision);
57var describe = GetFirstStdOutLine(gitexe + cmd_describe);
58var branch = GetFirstStdOutLine(gitexe + cmd_branch);
59var isMaster = +("master" == branch);
60
61// remove hash (and trailing "-0" if needed) from description
62describe = describe.replace(/(-0)?-[^-]+(-dirty)?$/, '$2');
63
64var out_contents =
65 "#define SCM_REV_STR \"" + revision + "\"\n" +
66 "#define SCM_DESC_STR \"" + describe + "\"\n" +
67 "#define SCM_BRANCH_STR \"" + branch + "\"\n" +
68 "#define SCM_IS_MASTER " + isMaster + "\n";
69
70// check if file needs updating
71if (out_contents == GetFileContents(outfile))
72{
73 WScript.Echo(outfile + " current at " + describe);
74}
75else
76{
77 // needs updating - writeout current info
78 oFS.CreateTextFile(outfile, true).Write(out_contents);
79 WScript.Echo(outfile + " updated to " + describe);
80}