Repository navigation
Expand file tree
/
Copy pathmake_buildinfo.c.patch
More file actions
executable file
·137 lines (131 loc) · 4.9 KB
/
Copy pathmake_buildinfo.c.patch
File metadata and controls
executable file
·137 lines (131 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
diff --git a/PCbuild/make_buildinfo.c b/PCbuild/make_buildinfo.c
index f9aadee..043c673 100644
--- a/PCbuild/make_buildinfo.c
+++ b/PCbuild/make_buildinfo.c
@@ -62,13 +62,12 @@ int make_buildinfo2(const char *tmppath)
return 1;
}
-const char DELIMS[] = { " \n" };
-
int get_mercurial_info(char * hgbranch, char * hgtag, char * hgrev, int size)
{
int result = 0;
char filename[CMD_SIZE];
char cmdline[CMD_SIZE];
+ static const char DELIMS[] = { " \n" };
strcpy_s(filename, CMD_SIZE, "tmpXXXXXX");
if (_mktemp_s(filename, CMD_SIZE) == 0) {
@@ -107,6 +106,80 @@ int get_mercurial_info(char * hgbranch, char * hgtag, char * hgrev, int size)
return result;
}
+int get_git_info(char * tag, char * rev, int size)
+{
+ int result = 0;
+ char filename[CMD_SIZE];
+ char cmdline[CMD_SIZE];
+ static const char DELIMS[] = { "-" };
+
+ strcpy_s(filename, CMD_SIZE, "tmpXXXXXX");
+ if (_mktemp_s(filename, CMD_SIZE) == 0) {
+ int rc;
+ int attempts = 1;
+
+ strcpy_s(cmdline, CMD_SIZE, "git describe --always --tags --dirty --long > ");
+ strcat_s(cmdline, CMD_SIZE, filename);
+
+ do {
+ rc = system(cmdline);
+ if (rc != 0 && attempts) {
+ char new_path[1024];
+ char prepend_path[] = (
+ "PATH="
+ "C:\\msysgit\\bin;"
+ "C:\\msysgit\\mingw\\bin;"
+ "C:\\msysgit\\cmd;"
+ );
+ char *path = getenv("PATH");
+ size_t path_len = strlen(path);
+ size_t copy_size = min(
+ path_len,
+ sizeof(new_path) - sizeof(prepend_path)
+ );
+ printf("git not on path, attempting to use c:\\msysgit\n");
+ memset(new_path, 0, sizeof(new_path));
+ memcpy(new_path, prepend_path, sizeof(prepend_path)-1);
+ memcpy(new_path+sizeof(prepend_path)-1, path, copy_size);
+ putenv(new_path);
+ }
+ } while (attempts--);
+
+ if (rc == 0) {
+ FILE * fp;
+
+ if (fopen_s(&fp, filename, "r") == 0) {
+ char * cp = fgets(cmdline, CMD_SIZE, fp);
+
+ if (cp) {
+ char * context = NULL;
+ char * tp = strtok_s(cp, DELIMS, &context);
+ if (tp) {
+ strcpy_s(tag, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp) {
+ strcat_s(tag, size, "-");
+ strcat_s(tag, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp) {
+ strcpy_s(rev, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp && strstr(tp, "dirty"))
+ strcat_s(rev, size, "+");
+ result = 1;
+ }
+ }
+ }
+ }
+ fclose(fp);
+ }
+ }
+ _unlink(filename);
+ }
+ return result;
+}
+
+
int main(int argc, char*argv[])
{
char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
@@ -157,21 +230,29 @@ int main(int argc, char*argv[])
strcat_s(command, CMD_SIZE, "getbuildinfo2.c\" -DSUBWCREV ");
}
else {
- char hgtag[CMD_SIZE];
- char hgbranch[CMD_SIZE];
- char hgrev[CMD_SIZE];
+ char tag[CMD_SIZE];
+ char branch[CMD_SIZE];
+ char rev[CMD_SIZE];
+ if (get_git_info(tag, rev, CMD_SIZE)) {
+ strcat_s(command, CMD_SIZE, "-DGITTAG=\\\"");
+ strcat_s(command, CMD_SIZE, tag);
+ strcat_s(command, CMD_SIZE, "\\\"");
+
+ strcat_s(command, CMD_SIZE, " -DGITVERSION=\\\"");
+ strcat_s(command, CMD_SIZE, rev);
+ strcat_s(command, CMD_SIZE, "\\\" ");
- if (get_mercurial_info(hgbranch, hgtag, hgrev, CMD_SIZE)) {
+ } else if (get_mercurial_info(branch, tag, rev, CMD_SIZE)) {
strcat_s(command, CMD_SIZE, "-DHGBRANCH=\\\"");
- strcat_s(command, CMD_SIZE, hgbranch);
+ strcat_s(command, CMD_SIZE, branch);
strcat_s(command, CMD_SIZE, "\\\"");
strcat_s(command, CMD_SIZE, " -DHGTAG=\\\"");
- strcat_s(command, CMD_SIZE, hgtag);
+ strcat_s(command, CMD_SIZE, tag);
strcat_s(command, CMD_SIZE, "\\\"");
strcat_s(command, CMD_SIZE, " -DHGVERSION=\\\"");
- strcat_s(command, CMD_SIZE, hgrev);
+ strcat_s(command, CMD_SIZE, rev);
strcat_s(command, CMD_SIZE, "\\\" ");
}
strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");