瀏覽代碼

Version Generator for PlatformIO Builds

Richard Wackerbarth 9 年之前
父節點
當前提交
8afd94ed3a
共有 2 個檔案被更改,包括 65 行新增2 行删除
  1. 57
    0
      PlatformIOAddons/generate_version_header_for_marlin
  2. 8
    2
      PlatformIOAddons/platformio.ini

+ 57
- 0
PlatformIOAddons/generate_version_header_for_marlin 查看文件

@@ -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)

+ 8
- 2
PlatformIOAddons/platformio.ini 查看文件

@@ -18,19 +18,24 @@ src_dir = ../Marlin
18 18
 platform = atmelavr
19 19
 framework = arduino
20 20
 board = megaatmega2560
21
+extra_script = ./generate_version_header_for_marlin
22
+build_flags = -D USE_AUTOMATIC_VERSIONING -I $BUILDSRC_DIR
21 23
 board_f_cpu = 16000000L
22 24
 
23 25
 [env:mega1280]
24 26
 platform = atmelavr
25 27
 framework = arduino
26 28
 board = megaatmega1280
29
+extra_script = ./generate_version_header_for_marlin
30
+build_flags = -D USE_AUTOMATIC_VERSIONING -I $BUILDSRC_DIR
27 31
 board_f_cpu = 16000000L
28 32
 
29 33
 [env:printrboard]
30 34
 platform = teensy
31 35
 framework = arduino
32 36
 board = teensy20pp
33
-build_flags = -D MOTHERBOARD=BOARD_PRINTRBOARD
37
+extra_script = ./generate_version_header_for_marlin
38
+build_flags = -D USE_AUTOMATIC_VERSIONING -I $BUILDSRC_DIR -D MOTHERBOARD=BOARD_PRINTRBOARD
34 39
 # Bug in arduino framework does not allow boards running at 20Mhz
35 40
 #board_f_cpu = 20000000L
36 41
 
@@ -38,4 +43,5 @@ build_flags = -D MOTHERBOARD=BOARD_PRINTRBOARD
38 43
 platform = teensy
39 44
 framework = arduino
40 45
 board = teensy20pp
41
-build_flags = -D MOTHERBOARD=BOARD_BRAINWAVE_PRO -D AT90USBxx_TEENSYPP_ASSIGNMENTS
46
+extra_script = ./generate_version_header_for_marlin
47
+build_flags = -D USE_AUTOMATIC_VERSIONING -I $BUILDSRC_DIR -D MOTHERBOARD=BOARD_BRAINWAVE_PRO -D AT90USBxx_TEENSYPP_ASSIGNMENTS

Loading…
取消
儲存