Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d3ce9d

Browse files
committed
merge
2 parents 6b9b727 + 5182c18 commit 2d3ce9d

1 file changed

Lines changed: 66 additions & 1 deletion

File tree

PCbuild/make_buildinfo.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <sys/types.h>
33
#include <sys/stat.h>
44
#include <stdio.h>
5+
#include <io.h>
56

67
#define CMD_SIZE 500
78

@@ -61,6 +62,51 @@ int make_buildinfo2(const char *tmppath)
6162
return 1;
6263
}
6364

65+
const char DELIMS[] = { " \n" };
66+
67+
int get_mercurial_info(char * hgbranch, char * hgtag, char * hgrev, int size)
68+
{
69+
int result = 0;
70+
char filename[CMD_SIZE];
71+
char cmdline[CMD_SIZE];
72+
73+
strcpy_s(filename, CMD_SIZE, "tmpXXXXXX");
74+
if (_mktemp_s(filename, CMD_SIZE) == 0) {
75+
int rc;
76+
77+
strcpy_s(cmdline, CMD_SIZE, "hg id -bit > ");
78+
strcat_s(cmdline, CMD_SIZE, filename);
79+
rc = system(cmdline);
80+
if (rc == 0) {
81+
FILE * fp;
82+
83+
if (fopen_s(&fp, filename, "r") == 0) {
84+
char * cp = fgets(cmdline, CMD_SIZE, fp);
85+
86+
if (cp) {
87+
char * context = NULL;
88+
char * tp = strtok_s(cp, DELIMS, &context);
89+
if (tp) {
90+
strcpy_s(hgrev, size, tp);
91+
tp = strtok_s(NULL, DELIMS, &context);
92+
if (tp) {
93+
strcpy_s(hgbranch, size, tp);
94+
tp = strtok_s(NULL, DELIMS, &context);
95+
if (tp) {
96+
strcpy_s(hgtag, size, tp);
97+
result = 1;
98+
}
99+
}
100+
}
101+
}
102+
fclose(fp);
103+
}
104+
}
105+
_unlink(filename);
106+
}
107+
return result;
108+
}
109+
64110
int main(int argc, char*argv[])
65111
{
66112
char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
@@ -109,8 +155,27 @@ int main(int argc, char*argv[])
109155
strcat_s(command, CMD_SIZE, "\"");
110156
strcat_s(command, CMD_SIZE, tmppath);
111157
strcat_s(command, CMD_SIZE, "getbuildinfo2.c\" -DSUBWCREV ");
112-
} else
158+
}
159+
else {
160+
char hgtag[CMD_SIZE];
161+
char hgbranch[CMD_SIZE];
162+
char hgrev[CMD_SIZE];
163+
164+
if (get_mercurial_info(hgbranch, hgtag, hgrev, CMD_SIZE)) {
165+
strcat_s(command, CMD_SIZE, "-DHGBRANCH=\\\"");
166+
strcat_s(command, CMD_SIZE, hgbranch);
167+
strcat_s(command, CMD_SIZE, "\\\"");
168+
169+
strcat_s(command, CMD_SIZE, " -DHGTAG=\\\"");
170+
strcat_s(command, CMD_SIZE, hgtag);
171+
strcat_s(command, CMD_SIZE, "\\\"");
172+
173+
strcat_s(command, CMD_SIZE, " -DHGVERSION=\\\"");
174+
strcat_s(command, CMD_SIZE, hgrev);
175+
strcat_s(command, CMD_SIZE, "\\\" ");
176+
}
113177
strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");
178+
}
114179
strcat_s(command, CMD_SIZE, " -Fo\"");
115180
strcat_s(command, CMD_SIZE, tmppath);
116181
strcat_s(command, CMD_SIZE, "getbuildinfo.o\" -I..\\Include -I..\\PC");

0 commit comments

Comments
 (0)