diff options
| author | 2013-09-13 17:46:27 -0400 | |
|---|---|---|
| committer | 2013-09-13 17:46:27 -0400 | |
| commit | 9709dd2def24260ec2ea4fdc16e3a78fa206bbb9 (patch) | |
| tree | 0bd5ba71df0a211cf17a8e46d882094ff704c15e /src/common/scm_rev_gen.js | |
| parent | renamed AkiruBinDir to EmuBinDir (diff) | |
| download | yuzu-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.js | 80 |
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 @@ | |||
| 1 | var wshShell = new ActiveXObject("WScript.Shell") | ||
| 2 | var oFS = new ActiveXObject("Scripting.FileSystemObject"); | ||
| 3 | |||
| 4 | var outfile = "./src/scm_rev.h"; | ||
| 5 | var cmd_revision = " rev-parse HEAD"; | ||
| 6 | var cmd_describe = " describe --always --long --dirty"; | ||
| 7 | var cmd_branch = " rev-parse --abbrev-ref HEAD"; | ||
| 8 | |||
| 9 | function 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 | |||
| 27 | function 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 | |||
| 41 | function 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 | ||
| 55 | var gitexe = GetGitExe(); | ||
| 56 | var revision = GetFirstStdOutLine(gitexe + cmd_revision); | ||
| 57 | var describe = GetFirstStdOutLine(gitexe + cmd_describe); | ||
| 58 | var branch = GetFirstStdOutLine(gitexe + cmd_branch); | ||
| 59 | var isMaster = +("master" == branch); | ||
| 60 | |||
| 61 | // remove hash (and trailing "-0" if needed) from description | ||
| 62 | describe = describe.replace(/(-0)?-[^-]+(-dirty)?$/, '$2'); | ||
| 63 | |||
| 64 | var 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 | ||
| 71 | if (out_contents == GetFileContents(outfile)) | ||
| 72 | { | ||
| 73 | WScript.Echo(outfile + " current at " + describe); | ||
| 74 | } | ||
| 75 | else | ||
| 76 | { | ||
| 77 | // needs updating - writeout current info | ||
| 78 | oFS.CreateTextFile(outfile, true).Write(out_contents); | ||
| 79 | WScript.Echo(outfile + " updated to " + describe); | ||
| 80 | } | ||