blob: 85416ed39d15243741098059882476e45046b9da [file] [log] [blame]
Thomas Wouters4d70c3d2006-06-08 14:42:34 +00001#include <windows.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <stdio.h>
5
Thomas Wouters89f507f2006-12-13 04:49:30 +00006/* 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.
10
11 A file, getbuildinfo2.h is then updated to define
12 SUBWCREV if it was a subversion checkout.
13
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.
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000018
19 Currently, subwcrev.exe is found from the registry entries
20 of TortoiseSVN.
21
Thomas Wouters89f507f2006-12-13 04:49:30 +000022 make_buildinfo.exe is called as a pre-build step for pythoncore.
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000023
24*/
25
26int make_buildinfo2()
27{
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;
Thomas Wouters89f507f2006-12-13 04:49:30 +000047 strcat_s(command, sizeof(command), "bin\\subwcrev.exe");
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000048 if (_stat(command+1, &st) < 0)
49 /* subwcrev.exe not part of the release */
50 return 0;
Thomas Wouters89f507f2006-12-13 04:49:30 +000051 strcat_s(command, sizeof(command), "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c");
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000052 puts(command); fflush(stdout);
53 if (system(command) < 0)
54 return 0;
55 return 1;
56}
57
58int main(int argc, char*argv[])
59{
Thomas Wouters89f507f2006-12-13 04:49:30 +000060 char command[500] = "";
61 int svn;
62 FILE *f;
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000063
Thomas Wouters89f507f2006-12-13 04:49:30 +000064 if (fopen_s(&f, "getbuildinfo2.h", "w"))
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000065 return EXIT_FAILURE;
Thomas Wouters89f507f2006-12-13 04:49:30 +000066 /* 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;
78 }
79 fclose(f);
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000080 return 0;
Thomas Wouters477c8d52006-05-27 19:21:47 +000081}