Minor fix for currentframe (SF #1652788).
[python.git] / PCbuild8 / make_buildinfo.c
blob85416ed39d15243741098059882476e45046b9da
1 #include <windows.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <stdio.h>
6 /* This file creates the getbuildinfo2.c file, by
7 invoking subwcrev.exe (if found).
8 If this isn't a subversion checkout, or subwcrev isn't
9 found, it copies ..\\Modules\\getbuildinfo.c instead.
11 A file, getbuildinfo2.h is then updated to define
12 SUBWCREV if it was a subversion checkout.
14 getbuildinfo2.c is part of the pythoncore project with
15 getbuildinfo2.h as a forced include. This helps
16 VisualStudio refrain from unnecessary compiles much of the
17 time.
19 Currently, subwcrev.exe is found from the registry entries
20 of TortoiseSVN.
22 make_buildinfo.exe is called as a pre-build step for pythoncore.
26 int make_buildinfo2()
28 struct _stat st;
29 HKEY hTortoise;
30 char command[500];
31 DWORD type, size;
32 if (_stat(".svn", &st) < 0)
33 return 0;
34 /* Allow suppression of subwcrev.exe invocation if a no_subwcrev file is present. */
35 if (_stat("no_subwcrev", &st) == 0)
36 return 0;
37 if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS &&
38 RegOpenKey(HKEY_CURRENT_USER, "Software\\TortoiseSVN", &hTortoise) != ERROR_SUCCESS)
39 /* Tortoise not installed */
40 return 0;
41 command[0] = '"'; /* quote the path to the executable */
42 size = sizeof(command) - 1;
43 if (RegQueryValueEx(hTortoise, "Directory", 0, &type, command+1, &size) != ERROR_SUCCESS ||
44 type != REG_SZ)
45 /* Registry corrupted */
46 return 0;
47 strcat_s(command, sizeof(command), "bin\\subwcrev.exe");
48 if (_stat(command+1, &st) < 0)
49 /* subwcrev.exe not part of the release */
50 return 0;
51 strcat_s(command, sizeof(command), "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c");
52 puts(command); fflush(stdout);
53 if (system(command) < 0)
54 return 0;
55 return 1;
58 int main(int argc, char*argv[])
60 char command[500] = "";
61 int svn;
62 FILE *f;
64 if (fopen_s(&f, "getbuildinfo2.h", "w"))
65 return EXIT_FAILURE;
66 /* Get getbuildinfo.c from svn as getbuildinfo2.c */
67 svn = make_buildinfo2();
68 if (svn) {
69 puts("got getbuildinfo2.c from svn. Updating getbuildinfo2.h");
70 /* yes. make sure SUBWCREV is defined */
71 fprintf(f, "#define SUBWCREV\n");
72 } else {
73 puts("didn't get getbuildinfo2.c from svn. Copying from Modules and clearing getbuildinfo2.h");
74 strcat_s(command, sizeof(command), "copy ..\\Modules\\getbuildinfo.c getbuildinfo2.c");
75 puts(command); fflush(stdout);
76 if (system(command) < 0)
77 return EXIT_FAILURE;
79 fclose(f);
80 return 0;