summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2014-12-10 19:13:21 +1100
committerLeith Bade <leith@mapbox.com>2014-12-10 19:13:21 +1100
commit69cd7268d783a5e449de38ab40dfe5a28fa76f64 (patch)
treea4951f03d039c2775317678d66afb0e61eb2f1ea /scripts
parentc55cd7f473ca532193697882c48436d2f98885d2 (diff)
parent318ef5d44314814f4dd7da2ba8c532b0119bdb35 (diff)
downloadqtlocation-mapboxgl-69cd7268d783a5e449de38ab40dfe5a28fa76f64.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: platform/default/http_request_baton_curl.cpp
Diffstat (limited to 'scripts')
-rw-r--r--scripts/build-version.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/scripts/build-version.py b/scripts/build-version.py
new file mode 100644
index 0000000000..8261aea536
--- /dev/null
+++ b/scripts/build-version.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+import sys, os, errno
+
+
+output_dir = sys.argv[1]
+
+if len(sys.argv) <= 3:
+ tag = [0, 0, 0]
+ rev = sys.argv[2][0:8]
+else:
+ # When they're identical, the git describe can't find a tag and reports the rev instead.
+ if sys.argv[2] == sys.argv[3]:
+ tag = [0, 0, 0]
+ else:
+ tag = map(int, sys.argv[2].split('.'))
+ rev = sys.argv[3][0:8]
+
+
+def mkdir_p(path):
+ try:
+ os.makedirs(path)
+ except OSError as exc: # Python >2.5
+ if exc.errno == errno.EEXIST and os.path.isdir(path):
+ pass
+ else: raise
+
+
+header = """// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+#ifndef MBGL_UTIL_VERSION
+#define MBGL_UTIL_VERSION
+
+#define MBGL_VERSION 0x{major:02x}{minor:02x}{patch:02x}
+#define MBGL_VERSION_STRING "{major}.{minor}.{patch}"
+#define MBGL_VERSION_MAJOR {major}
+#define MBGL_VERSION_MINOR {minor}
+#define MBGL_VERSION_PATCH {patch}
+#define MBGL_VERSION_REV "{rev}"
+
+namespace mbgl {{
+namespace version {{
+
+extern const int major, minor, patch;
+extern const char *revision;
+extern const char *string;
+extern const unsigned int number;
+
+}}
+}}
+
+#endif
+""".format(
+ major = tag[0],
+ minor = tag[1],
+ patch = tag[2],
+ rev = rev
+)
+
+header_path = os.path.join(output_dir, 'include/mbgl/util/version.hpp')
+mkdir_p(os.path.dirname(header_path))
+with open(header_path, 'w') as f: f.write(header)
+
+source = """// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+#include <mbgl/util/version.hpp>
+
+namespace mbgl {{
+namespace version {{
+
+const int major = {major};
+const int minor = {minor};
+const int patch = {patch};
+const char *revision = "{rev}";
+const char *string = "{major}.{minor}.{patch}";
+const unsigned int number = 0x{major:02x}{minor:02x}{patch:02x};
+
+}}
+}}
+""".format(
+ major = tag[0],
+ minor = tag[1],
+ patch = tag[2],
+ rev = rev
+)
+
+# Note: We can't use version.cpp since libuv already has a file named version.c.
+# Having another one here would overwrite that file and cause missing symbols errors.
+source_path = os.path.join(output_dir, 'src/mbgl/util/mbgl_version.cpp')
+mkdir_p(os.path.dirname(source_path))
+with open(source_path, 'w') as f: f.write(source)