Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 1 | #include <windows.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/stat.h> |
| 4 | #include <stdio.h> |
| 5 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 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. |
| 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 Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 18 | |
| 19 | Currently, subwcrev.exe is found from the registry entries |
| 20 | of TortoiseSVN. |
| 21 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 22 | make_buildinfo.exe is called as a pre-build step for pythoncore. |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 23 | |
| 24 | */ |
| 25 | |
| 26 | int 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 Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 47 | strcat_s(command, sizeof(command), "bin\\subwcrev.exe"); |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 48 | if (_stat(command+1, &st) < 0) |
| 49 | /* subwcrev.exe not part of the release */ |
| 50 | return 0; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 51 | strcat_s(command, sizeof(command), "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c"); |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 52 | puts(command); fflush(stdout); |
| 53 | if (system(command) < 0) |
| 54 | return 0; |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | int main(int argc, char*argv[]) |
| 59 | { |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 60 | char command[500] = ""; |
| 61 | int svn; |
| 62 | FILE *f; |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 63 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 64 | if (fopen_s(&f, "getbuildinfo2.h", "w")) |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 65 | return EXIT_FAILURE; |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 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; |
| 78 | } |
| 79 | fclose(f); |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 80 | return 0; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 81 | } |