ยปCore Development>Code coverage>PC/VS8.0/make_buildinfo.c

Python code coverage for PC/VS8.0/make_buildinfo.c

#countcontent
1n/a#include <windows.h>
2n/a#include <sys/types.h>
3n/a#include <sys/stat.h>
4n/a#include <stdio.h>
5n/a
6n/a#define CMD_SIZE 500
7n/a
8n/a/* This file creates the getbuildinfo.o object, by first
9n/a invoking subwcrev.exe (if found), and then invoking cl.exe.
10n/a As a side effect, it might generate PCBuild\getbuildinfo2.c
11n/a also. If this isn't a subversion checkout, or subwcrev isn't
12n/a found, it compiles ..\\..\\Modules\\getbuildinfo.c instead.
13n/a
14n/a Currently, subwcrev.exe is found from the registry entries
15n/a of TortoiseSVN.
16n/a
17n/a No attempt is made to place getbuildinfo.o into the proper
18n/a binary directory. This isn't necessary, as this tool is
19n/a invoked as a pre-link step for pythoncore, so that overwrites
20n/a any previous getbuildinfo.o.
21n/a
22n/a However, if a second argument is provided, this will be used
23n/a as a temporary directory where any getbuildinfo2.c and
24n/a getbuildinfo.o files are put. This is useful if multiple
25n/a configurations are being built in parallel, to avoid them
26n/a trampling each other's files.
27n/a
28n/a*/
29n/a
30n/aint make_buildinfo2(const char *tmppath)
31n/a{
32n/a struct _stat st;
33n/a HKEY hTortoise;
34n/a char command[CMD_SIZE+1];
35n/a DWORD type, size;
36n/a if (_stat(".svn", &st) < 0)
37n/a return 0;
38n/a /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
39n/a if (_stat("no_subwcrev", &st) == 0)
40n/a return 0;
41n/a if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
42n/a RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
43n/a /* Tortoise not installed */
44n/a return 0;
45n/a command[0] = '"'; /* quote the path to the executable */
46n/a size = sizeof(command) - 1;
47n/a if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
48n/a type != REG_SZ)
49n/a /* Registry corrupted */
50n/a return 0;
51n/a strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
52n/a if (_stat(command+1, &st) < 0)
53n/a /* subwcrev.exe not part of the release */
54n/a return 0;
55n/a strcat_s(command, CMD_SIZE, "\" ..\\.. ..\\..\\Modules\\getbuildinfo.c ");
56n/a strcat_s(command, CMD_SIZE, tmppath);
57n/a strcat_s(command, CMD_SIZE, "getbuildinfo2.c");
58n/a puts(command); fflush(stdout);
59n/a if (system(command) < 0)
60n/a return 0;
61n/a return 1;
62n/a}
63n/a
64n/aint main(int argc, char*argv[])
65n/a{
66n/a char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
67n/a char tmppath[CMD_SIZE] = "";
68n/a int do_unlink, result;
69n/a char *tmpdir = NULL;
70n/a if (argc <= 2 || argc > 3) {
71n/a fprintf(stderr, "make_buildinfo $(ConfigurationName) [tmpdir]\n");
72n/a return EXIT_FAILURE;
73n/a }
74n/a if (strcmp(argv[1], "Release") == 0) {
75n/a strcat_s(command, CMD_SIZE, "-MD ");
76n/a }
77n/a else if (strcmp(argv[1], "Debug") == 0) {
78n/a strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
79n/a }
80n/a else if (strcmp(argv[1], "ReleaseItanium") == 0) {
81n/a strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
82n/a }
83n/a else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
84n/a strcat_s(command, CMD_SIZE, "-MD ");
85n/a strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
86n/a }
87n/a else {
88n/a fprintf(stderr, "unsupported configuration %s\n", argv[1]);
89n/a return EXIT_FAILURE;
90n/a }
91n/a if (argc > 2) {
92n/a tmpdir = argv[2];
93n/a strcat_s(tmppath, _countof(tmppath), tmpdir);
94n/a strcat_s(tmppath, _countof(tmppath), "\\");
95n/a }
96n/a
97n/a if ((do_unlink = make_buildinfo2(tmppath))) {
98n/a strcat_s(command, CMD_SIZE, tmppath);
99n/a strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV ");
100n/a } else
101n/a strcat_s(command, CMD_SIZE, "..\\..\\Modules\\getbuildinfo.c");
102n/a strcat_s(command, CMD_SIZE, " -Fo");
103n/a strcat_s(command, CMD_SIZE, tmppath);
104n/a strcat_s(command, CMD_SIZE, "getbuildinfo.o -I..\\..\\Include -I..\\..\\PC");
105n/a puts(command); fflush(stdout);
106n/a result = system(command);
107n/a if (do_unlink) {
108n/a command[0] = '\0';
109n/a strcat_s(command, CMD_SIZE, tmppath);
110n/a strcat_s(command, CMD_SIZE, "getbuildinfo2.c");
111n/a _unlink(command);
112n/a }
113n/a if (result < 0)
114n/a return EXIT_FAILURE;
115n/a return 0;
116n/a}