|
@@ -0,0 +1,57 @@
|
|
1
|
+#/usr/bin/env python -
|
|
2
|
+from SCons.Script import DefaultEnvironment
|
|
3
|
+
|
|
4
|
+env = DefaultEnvironment()
|
|
5
|
+
|
|
6
|
+import os
|
|
7
|
+import errno
|
|
8
|
+
|
|
9
|
+def make_sure_path_exists(path):
|
|
10
|
+ try:
|
|
11
|
+ os.makedirs(path)
|
|
12
|
+ except OSError as exception:
|
|
13
|
+ if exception.errno != errno.EEXIST:
|
|
14
|
+ raise
|
|
15
|
+
|
|
16
|
+import subprocess
|
|
17
|
+
|
|
18
|
+make_sure_path_exists(env.subst('$BUILDSRC_DIR'))
|
|
19
|
+
|
|
20
|
+from datetime import datetime
|
|
21
|
+import time
|
|
22
|
+import string
|
|
23
|
+import re
|
|
24
|
+
|
|
25
|
+p = subprocess.Popen(['git', 'symbolic-ref', '-q', '--short', 'HEAD'], stdout=subprocess.PIPE)
|
|
26
|
+BRANCH = p.stdout.readline().rstrip()
|
|
27
|
+p = subprocess.Popen(['git', 'describe', '--tags', '--first-parent'], stdout=subprocess.PIPE)
|
|
28
|
+RAW_VERSION = p.stdout.readline().rstrip()
|
|
29
|
+s = re.search('(.*)(-.*)(-.*)',RAW_VERSION)
|
|
30
|
+SHORT_VERSION = s.group(1)+' '+BRANCH
|
|
31
|
+DETAILED_VERSION = string.replace(RAW_VERSION,'-',' '+BRANCH+'-',1)
|
|
32
|
+p = subprocess.Popen(['git', 'config', '--local', '--get', 'remote.origin.url'], stdout=subprocess.PIPE)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+try:
|
|
36
|
+ s = re.search('(.*github.com:)(.*)', p.stdout.readline().rstrip())
|
|
37
|
+ URL = string.replace("https://github.com/"+s.group(2), ".git", "/")
|
|
38
|
+
|
|
39
|
+ url_text = """#define SOURCE_CODE_URL "%s"
|
|
40
|
+// Deprecated URL definition
|
|
41
|
+#define FIRMWARE_URL "%s"
|
|
42
|
+""" % (URL, URL)
|
|
43
|
+except Exception, e:
|
|
44
|
+ url_text = ""
|
|
45
|
+
|
|
46
|
+version_header_text = """/* This file is automatically generated by a compile time hook
|
|
47
|
+ * Do not manually edit it
|
|
48
|
+ * It does not get committed to the repository
|
|
49
|
+ */
|
|
50
|
+
|
|
51
|
+#define BUILD_UNIX_DATETIME %s
|
|
52
|
+#define STRING_DISTRIBUTION_DATE "%s"
|
|
53
|
+#define SHORT_BUILD_VERSION "%s"
|
|
54
|
+#define DETAILED_BUILD_VERSION "%s"
|
|
55
|
+%s""" % (int(time.time()), datetime.now().strftime('%Y-%m-%d %H:%M'),SHORT_VERSION, DETAILED_VERSION, url_text)
|
|
56
|
+
|
|
57
|
+open(env.subst('$BUILDSRC_DIR/_Version.h'), 'w').write(version_header_text)
|