summaryrefslogtreecommitdiffstats
path: root/PCbuild
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-05-04 19:51:59 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-05-04 19:51:59 (GMT)
commit5182c18b1a4ac11c9825117ecdc51c1ef013c66b (patch)
treeeed8fc6ea9bf0314a2a8b198f1e8407e9428691c /PCbuild
parentf19c19106704f01b75b8e3e678f27a9b543aad74 (diff)
downloadcpython-5182c18b1a4ac11c9825117ecdc51c1ef013c66b.zip
cpython-5182c18b1a4ac11c9825117ecdc51c1ef013c66b.tar.gz
cpython-5182c18b1a4ac11c9825117ecdc51c1ef013c66b.tar.bz2
Closes #14093: Added Mercurial version information to Windows builds.
Diffstat (limited to 'PCbuild')
-rw-r--r--PCbuild/make_buildinfo.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/PCbuild/make_buildinfo.c b/PCbuild/make_buildinfo.c
index fd3a2e2..f9aadee 100644
--- a/PCbuild/make_buildinfo.c
+++ b/PCbuild/make_buildinfo.c
@@ -2,6 +2,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
+#include <io.h>
#define CMD_SIZE 500
@@ -61,6 +62,51 @@ int make_buildinfo2(const char *tmppath)
return 1;
}
+const char DELIMS[] = { " \n" };
+
+int get_mercurial_info(char * hgbranch, char * hgtag, char * hgrev, int size)
+{
+ int result = 0;
+ char filename[CMD_SIZE];
+ char cmdline[CMD_SIZE];
+
+ strcpy_s(filename, CMD_SIZE, "tmpXXXXXX");
+ if (_mktemp_s(filename, CMD_SIZE) == 0) {
+ int rc;
+
+ strcpy_s(cmdline, CMD_SIZE, "hg id -bit > ");
+ strcat_s(cmdline, CMD_SIZE, filename);
+ rc = system(cmdline);
+ if (rc == 0) {
+ FILE * fp;
+
+ if (fopen_s(&fp, filename, "r") == 0) {
+ char * cp = fgets(cmdline, CMD_SIZE, fp);
+
+ if (cp) {
+ char * context = NULL;
+ char * tp = strtok_s(cp, DELIMS, &context);
+ if (tp) {
+ strcpy_s(hgrev, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp) {
+ strcpy_s(hgbranch, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp) {
+ strcpy_s(hgtag, size, tp);
+ result = 1;
+ }
+ }
+ }
+ }
+ fclose(fp);
+ }
+ }
+ _unlink(filename);
+ }
+ return result;
+}
+
int main(int argc, char*argv[])
{
char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
@@ -109,8 +155,27 @@ int main(int argc, char*argv[])
strcat_s(command, CMD_SIZE, "\"");
strcat_s(command, CMD_SIZE, tmppath);
strcat_s(command, CMD_SIZE, "getbuildinfo2.c\" -DSUBWCREV ");
- } else
+ }
+ else {
+ char hgtag[CMD_SIZE];
+ char hgbranch[CMD_SIZE];
+ char hgrev[CMD_SIZE];
+
+ if (get_mercurial_info(hgbranch, hgtag, hgrev, CMD_SIZE)) {
+ strcat_s(command, CMD_SIZE, "-DHGBRANCH=\\\"");
+ strcat_s(command, CMD_SIZE, hgbranch);
+ strcat_s(command, CMD_SIZE, "\\\"");
+
+ strcat_s(command, CMD_SIZE, " -DHGTAG=\\\"");
+ strcat_s(command, CMD_SIZE, hgtag);
+ strcat_s(command, CMD_SIZE, "\\\"");
+
+ strcat_s(command, CMD_SIZE, " -DHGVERSION=\\\"");
+ strcat_s(command, CMD_SIZE, hgrev);
+ strcat_s(command, CMD_SIZE, "\\\" ");
+ }
strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");
+ }
strcat_s(command, CMD_SIZE, " -Fo\"");
strcat_s(command, CMD_SIZE, tmppath);
strcat_s(command, CMD_SIZE, "getbuildinfo.o\" -I..\\Include -I..\\PC");