Debian Codegraph @

Source/Core/Common/make_scmrev.h.js

raw symbols SCIP
1 var wshShell = new ActiveXObject("WScript.Shell")
2 var oFS = new ActiveXObject("Scripting.FileSystemObject");
3
4 var outfile = "./scmrev.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 var cmd_commits_ahead = " rev-list --count HEAD ^master";
9 var cmd_get_tag = " describe --exact-match HEAD";
10
11 function GetGitExe()
12 {
13 try
14 {
15 gitexe = wshShell.RegRead("HKCU\\Software\\GitExtensions\\gitcommand");
16 wshShell.Exec(gitexe);
17 return gitexe;
18 }
19 catch (e)
20 {}
21
22 for (var gitexe in {"git.cmd":1, "git":1, "git.bat":1})
23 {
24 try
25 {
26 wshShell.Exec(gitexe);
27 return gitexe;
28 }
29 catch (e)
30 {}
31 }
32
33 // last try - msysgit not in path (vs2015 default)
34 msyspath = "\\Git\\cmd\\git.exe";
35 gitexe = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") + msyspath;
36 if (oFS.FileExists(gitexe)) {
37 return gitexe;
38 }
39 gitexe = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%") + msyspath;
40 if (oFS.FileExists(gitexe)) {
41 return gitexe;
42 }
43
44 WScript.Echo("Cannot find git or git.cmd, check your PATH:\n" +
45 wshShell.ExpandEnvironmentStrings("%PATH%"));
46 WScript.Quit(1);
47 }
48
49 function GetFirstStdOutLine(cmd)
50 {
51 try
52 {
53 return wshShell.Exec(cmd).StdOut.ReadLine();
54 }
55 catch (e)
56 {
57 // catch "the system cannot find the file specified" error
58 WScript.Echo("Failed to exec " + cmd + " this should never happen");
59 WScript.Quit(1);
60 }
61 }
62
63 function AttemptToExecuteCommand(cmd)
64 {
65 try
66 {
67 var exec = wshShell.Exec(cmd)
68
69 // wait until the command has finished
70 while (exec.Status == 0) {}
71
72 return exec.ExitCode;
73 }
74 catch (e)
75 {
76 // catch "the system cannot find the file specified" error
77 WScript.Echo("Failed to exec " + cmd + " this should never happen");
78 WScript.Quit(1);
79 }
80 }
81
82 function GetFileContents(f)
83 {
84 try
85 {
86 return oFS.OpenTextFile(f).ReadAll();
87 }
88 catch (e)
89 {
90 // file doesn't exist
91 return "";
92 }
93 }
94
95 // get info from git
96 var gitexe = GetGitExe();
97 var revision = GetFirstStdOutLine(gitexe + cmd_revision);
98 var describe = GetFirstStdOutLine(gitexe + cmd_describe);
99 var branch = GetFirstStdOutLine(gitexe + cmd_branch);
100 var commits_ahead = GetFirstStdOutLine(gitexe + cmd_commits_ahead);
101
102 // Get environment information.
103 var distributor = wshShell.ExpandEnvironmentStrings("%DOLPHIN_DISTRIBUTOR%");
104 if (distributor == "%DOLPHIN_DISTRIBUTOR%") distributor = "None";
105 var default_update_track = wshShell.ExpandEnvironmentStrings("%DOLPHIN_DEFAULT_UPDATE_TRACK%");
106 if (default_update_track == "%DOLPHIN_DEFAULT_UPDATE_TRACK%") default_update_track = "";
107
108 // remove hash (and trailing "-0" if needed) from description
109 describe = describe.replace(/(-0)?-[^-]+(-dirty)?$/, '$2');
110
111 // set commits ahead to zero if on a tag
112 if (AttemptToExecuteCommand(gitexe + cmd_get_tag) == 0)
113 {
114 commits_ahead = "0";
115 }
116
117 var out_contents =
118 "#define SCM_REV_STR \"" + revision + "\"\n" +
119 "#define SCM_DESC_STR \"" + describe + "\"\n" +
120 "#define SCM_BRANCH_STR \"" + branch + "\"\n" +
121 "#define SCM_COMMITS_AHEAD_MASTER " + commits_ahead + "\n" +
122 "#define SCM_DISTRIBUTOR_STR \"" + distributor + "\"\n" +
123 "#define SCM_UPDATE_TRACK_STR \"" + default_update_track + "\"\n";
124
125 // check if file needs updating
126 if (out_contents == GetFileContents(outfile))
127 {
128 WScript.Echo(outfile + " current at " + describe);
129 }
130 else
131 {
132 // needs updating - writeout current info
133 oFS.CreateTextFile(outfile, true).Write(out_contents);
134 WScript.Echo(outfile + " updated to " + describe);
135 }