1 | n/a | #include <windows.h> |
---|
2 | n/a | #include <sys/types.h> |
---|
3 | n/a | #include <sys/stat.h> |
---|
4 | n/a | #include <stdio.h> |
---|
5 | n/a | #include <io.h> |
---|
6 | n/a | |
---|
7 | n/a | #define CMD_SIZE 500 |
---|
8 | n/a | |
---|
9 | n/a | /* This file creates the getbuildinfo.o object, by first |
---|
10 | n/a | invoking subwcrev.exe (if found), and then invoking cl.exe. |
---|
11 | n/a | As a side effect, it might generate PCBuild\getbuildinfo2.c |
---|
12 | n/a | also. If this isn't a subversion checkout, or subwcrev isn't |
---|
13 | n/a | found, it compiles ..\\Modules\\getbuildinfo.c instead. |
---|
14 | n/a | |
---|
15 | n/a | Currently, subwcrev.exe is found from the registry entries |
---|
16 | n/a | of TortoiseSVN. |
---|
17 | n/a | |
---|
18 | n/a | No attempt is made to place getbuildinfo.o into the proper |
---|
19 | n/a | binary directory. This isn't necessary, as this tool is |
---|
20 | n/a | invoked as a pre-link step for pythoncore, so that overwrites |
---|
21 | n/a | any previous getbuildinfo.o. |
---|
22 | n/a | |
---|
23 | n/a | However, if a second argument is provided, this will be used |
---|
24 | n/a | as a temporary directory where any getbuildinfo2.c and |
---|
25 | n/a | getbuildinfo.o files are put. This is useful if multiple |
---|
26 | n/a | configurations are being built in parallel, to avoid them |
---|
27 | n/a | trampling each other's files. |
---|
28 | n/a | |
---|
29 | n/a | */ |
---|
30 | n/a | |
---|
31 | n/a | int make_buildinfo2(const char *tmppath) |
---|
32 | n/a | { |
---|
33 | n/a | struct _stat st; |
---|
34 | n/a | HKEY hTortoise; |
---|
35 | n/a | char command[CMD_SIZE+1]; |
---|
36 | n/a | DWORD type, size; |
---|
37 | n/a | if (_stat(".svn", &st) < 0) |
---|
38 | n/a | return 0; |
---|
39 | n/a | /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */ |
---|
40 | n/a | if (_stat("no_subwcrev", &st) == 0) |
---|
41 | n/a | return 0; |
---|
42 | n/a | if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS && |
---|
43 | n/a | RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS) |
---|
44 | n/a | /* Tortoise not installed */ |
---|
45 | n/a | return 0; |
---|
46 | n/a | command[0] = '"'; /* quote the path to the executable */ |
---|
47 | n/a | size = sizeof(command) - 1; |
---|
48 | n/a | if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS || |
---|
49 | n/a | type != REG_SZ) |
---|
50 | n/a | /* Registry corrupted */ |
---|
51 | n/a | return 0; |
---|
52 | n/a | strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe"); |
---|
53 | n/a | if (_stat(command+1, &st) < 0) |
---|
54 | n/a | /* subwcrev.exe not part of the release */ |
---|
55 | n/a | return 0; |
---|
56 | n/a | strcat_s(command, CMD_SIZE, "\" .. ..\\Modules\\getbuildinfo.c \""); |
---|
57 | n/a | strcat_s(command, CMD_SIZE, tmppath); /* quoted tmppath */ |
---|
58 | n/a | strcat_s(command, CMD_SIZE, "getbuildinfo2.c\""); |
---|
59 | n/a | puts(command); fflush(stdout); |
---|
60 | n/a | if (system(command) < 0) |
---|
61 | n/a | return 0; |
---|
62 | n/a | return 1; |
---|
63 | n/a | } |
---|
64 | n/a | |
---|
65 | n/a | const char DELIMS[] = { " \n" }; |
---|
66 | n/a | |
---|
67 | n/a | int get_mercurial_info(char * hgbranch, char * hgtag, char * hgrev, int size) |
---|
68 | n/a | { |
---|
69 | n/a | int result = 0; |
---|
70 | n/a | char filename[CMD_SIZE]; |
---|
71 | n/a | char cmdline[CMD_SIZE]; |
---|
72 | n/a | |
---|
73 | n/a | strcpy_s(filename, CMD_SIZE, "tmpXXXXXX"); |
---|
74 | n/a | if (_mktemp_s(filename, CMD_SIZE) == 0) { |
---|
75 | n/a | int rc; |
---|
76 | n/a | |
---|
77 | n/a | strcpy_s(cmdline, CMD_SIZE, "hg id -bit > "); |
---|
78 | n/a | strcat_s(cmdline, CMD_SIZE, filename); |
---|
79 | n/a | rc = system(cmdline); |
---|
80 | n/a | if (rc == 0) { |
---|
81 | n/a | FILE * fp; |
---|
82 | n/a | |
---|
83 | n/a | if (fopen_s(&fp, filename, "r") == 0) { |
---|
84 | n/a | char * cp = fgets(cmdline, CMD_SIZE, fp); |
---|
85 | n/a | |
---|
86 | n/a | if (cp) { |
---|
87 | n/a | char * context = NULL; |
---|
88 | n/a | char * tp = strtok_s(cp, DELIMS, &context); |
---|
89 | n/a | if (tp) { |
---|
90 | n/a | strcpy_s(hgrev, size, tp); |
---|
91 | n/a | tp = strtok_s(NULL, DELIMS, &context); |
---|
92 | n/a | if (tp) { |
---|
93 | n/a | strcpy_s(hgbranch, size, tp); |
---|
94 | n/a | tp = strtok_s(NULL, DELIMS, &context); |
---|
95 | n/a | if (tp) { |
---|
96 | n/a | strcpy_s(hgtag, size, tp); |
---|
97 | n/a | result = 1; |
---|
98 | n/a | } |
---|
99 | n/a | } |
---|
100 | n/a | } |
---|
101 | n/a | } |
---|
102 | n/a | fclose(fp); |
---|
103 | n/a | } |
---|
104 | n/a | } |
---|
105 | n/a | _unlink(filename); |
---|
106 | n/a | } |
---|
107 | n/a | return result; |
---|
108 | n/a | } |
---|
109 | n/a | |
---|
110 | n/a | int main(int argc, char*argv[]) |
---|
111 | n/a | { |
---|
112 | n/a | char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL "; |
---|
113 | n/a | char tmppath[CMD_SIZE] = ""; |
---|
114 | n/a | int do_unlink, result; |
---|
115 | n/a | char *tmpdir = NULL; |
---|
116 | n/a | if (argc <= 2 || argc > 3) { |
---|
117 | n/a | fprintf(stderr, "make_buildinfo $(ConfigurationName) [tmpdir]\n"); |
---|
118 | n/a | return EXIT_FAILURE; |
---|
119 | n/a | } |
---|
120 | n/a | if (strcmp(argv[1], "Release") == 0) { |
---|
121 | n/a | strcat_s(command, CMD_SIZE, "-MD "); |
---|
122 | n/a | } |
---|
123 | n/a | else if (strcmp(argv[1], "Debug") == 0) { |
---|
124 | n/a | strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd "); |
---|
125 | n/a | } |
---|
126 | n/a | else if (strcmp(argv[1], "ReleaseItanium") == 0) { |
---|
127 | n/a | strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM "); |
---|
128 | n/a | } |
---|
129 | n/a | else if (strcmp(argv[1], "ReleaseAMD64") == 0) { |
---|
130 | n/a | strcat_s(command, CMD_SIZE, "-MD "); |
---|
131 | n/a | strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON "); |
---|
132 | n/a | } |
---|
133 | n/a | else { |
---|
134 | n/a | fprintf(stderr, "unsupported configuration %s\n", argv[1]); |
---|
135 | n/a | return EXIT_FAILURE; |
---|
136 | n/a | } |
---|
137 | n/a | if (argc > 2) { |
---|
138 | n/a | tmpdir = argv[2]; |
---|
139 | n/a | strcat_s(tmppath, _countof(tmppath), tmpdir); |
---|
140 | n/a | /* Hack fix for bad command line: If the command is issued like this: |
---|
141 | n/a | * $(SolutionDir)make_buildinfo.exe" Debug "$(IntDir)" |
---|
142 | n/a | * we will get a trailing quote because IntDir ends with a backslash that then |
---|
143 | n/a | * escapes the final ". To simplify the life for developers, catch that problem |
---|
144 | n/a | * here by cutting it off. |
---|
145 | n/a | * The proper command line, btw is: |
---|
146 | n/a | * $(SolutionDir)make_buildinfo.exe" Debug "$(IntDir)\" |
---|
147 | n/a | * Hooray for command line parsing on windows. |
---|
148 | n/a | */ |
---|
149 | n/a | if (strlen(tmppath) > 0 && tmppath[strlen(tmppath)-1] == '"') |
---|
150 | n/a | tmppath[strlen(tmppath)-1] = '\0'; |
---|
151 | n/a | strcat_s(tmppath, _countof(tmppath), "\\"); |
---|
152 | n/a | } |
---|
153 | n/a | |
---|
154 | n/a | if ((do_unlink = make_buildinfo2(tmppath))) { |
---|
155 | n/a | strcat_s(command, CMD_SIZE, "\""); |
---|
156 | n/a | strcat_s(command, CMD_SIZE, tmppath); |
---|
157 | n/a | strcat_s(command, CMD_SIZE, "getbuildinfo2.c\" -DSUBWCREV "); |
---|
158 | n/a | } |
---|
159 | n/a | else { |
---|
160 | n/a | char hgtag[CMD_SIZE]; |
---|
161 | n/a | char hgbranch[CMD_SIZE]; |
---|
162 | n/a | char hgrev[CMD_SIZE]; |
---|
163 | n/a | |
---|
164 | n/a | if (get_mercurial_info(hgbranch, hgtag, hgrev, CMD_SIZE)) { |
---|
165 | n/a | strcat_s(command, CMD_SIZE, "-DHGBRANCH=\\\""); |
---|
166 | n/a | strcat_s(command, CMD_SIZE, hgbranch); |
---|
167 | n/a | strcat_s(command, CMD_SIZE, "\\\""); |
---|
168 | n/a | |
---|
169 | n/a | strcat_s(command, CMD_SIZE, " -DHGTAG=\\\""); |
---|
170 | n/a | strcat_s(command, CMD_SIZE, hgtag); |
---|
171 | n/a | strcat_s(command, CMD_SIZE, "\\\""); |
---|
172 | n/a | |
---|
173 | n/a | strcat_s(command, CMD_SIZE, " -DHGVERSION=\\\""); |
---|
174 | n/a | strcat_s(command, CMD_SIZE, hgrev); |
---|
175 | n/a | strcat_s(command, CMD_SIZE, "\\\" "); |
---|
176 | n/a | } |
---|
177 | n/a | strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c"); |
---|
178 | n/a | } |
---|
179 | n/a | strcat_s(command, CMD_SIZE, " -Fo\""); |
---|
180 | n/a | strcat_s(command, CMD_SIZE, tmppath); |
---|
181 | n/a | strcat_s(command, CMD_SIZE, "getbuildinfo.o\" -I..\\Include -I..\\PC"); |
---|
182 | n/a | puts(command); fflush(stdout); |
---|
183 | n/a | result = system(command); |
---|
184 | n/a | if (do_unlink) { |
---|
185 | n/a | command[0] = '\0'; |
---|
186 | n/a | strcat_s(command, CMD_SIZE, "\""); |
---|
187 | n/a | strcat_s(command, CMD_SIZE, tmppath); |
---|
188 | n/a | strcat_s(command, CMD_SIZE, "getbuildinfo2.c\""); |
---|
189 | n/a | _unlink(command); |
---|
190 | n/a | } |
---|
191 | n/a | if (result < 0) |
---|
192 | n/a | return EXIT_FAILURE; |
---|
193 | n/a | return 0; |
---|
194 | n/a | } |
---|