|
2 | 2 | #include <sys/types.h> |
3 | 3 | #include <sys/stat.h> |
4 | 4 | #include <stdio.h> |
| 5 | +#include <io.h> |
5 | 6 |
|
6 | 7 | #define CMD_SIZE 500 |
7 | 8 |
|
@@ -61,6 +62,51 @@ int make_buildinfo2(const char *tmppath) |
61 | 62 | return 1; |
62 | 63 | } |
63 | 64 |
|
| 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 | + |
64 | 110 | int main(int argc, char*argv[]) |
65 | 111 | { |
66 | 112 | 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[]) |
109 | 155 | strcat_s(command, CMD_SIZE, "\""); |
110 | 156 | strcat_s(command, CMD_SIZE, tmppath); |
111 | 157 | 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 | + } |
113 | 177 | strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c"); |
| 178 | + } |
114 | 179 | strcat_s(command, CMD_SIZE, " -Fo\""); |
115 | 180 | strcat_s(command, CMD_SIZE, tmppath); |
116 | 181 | strcat_s(command, CMD_SIZE, "getbuildinfo.o\" -I..\\Include -I..\\PC"); |
|
0 commit comments