瀏覽代碼

Clean up / improve generate_version script (#21674)

Ryan Finnie 3 年之前
父節點
當前提交
a73dce4a56
No account linked to committer's email address
共有 1 個文件被更改,包括 24 次插入36 次删除
  1. 24
    36
      buildroot/bin/generate_version

+ 24
- 36
buildroot/bin/generate_version 查看文件

@@ -4,47 +4,35 @@
4 4
 #
5 5
 # Make a Version.h file to accompany CUSTOM_VERSION_FILE
6 6
 #
7
+# Authors: jbrazio, thinkyhead, InsanityAutomation, rfinnie
8
+#
7 9
 
8
-DIR=${1:-"Marlin"}
9
-
10
-# MRCC3=$( git merge-base HEAD upstream/bugfix-2.0.x 2>/dev/null )
11
-# MRCC2=$( git merge-base HEAD upstream/bugfix-1.1.x 2>/dev/null )
12
-# MRCC1=$( git merge-base HEAD upstream/1.1.x 2>/dev/null )
13
-
14
-# BASE='?'
15
-# if [[ -n $MRCC3 && $MRCC3 != $MRCC2 ]]; then
16
-#   BASE=bugfix-2.0.x
17
-# elif [[ -n $MRCC2 ]]; then
18
-#   BASE=bugfix-1.1.x
19
-# elif [[ -n $MRCC1 ]]; then
20
-#   BASE=1.1.x
21
-# fi
22
-
23
-BUILDATE=$(date '+%s')
24
-DISTDATE=$(date '+%Y-%m-%d %H:%M')
10
+set -e
25 11
 
26
-BRANCH=$(git -C "${DIR}" symbolic-ref -q --short HEAD)
27
-VERSION=$(git -C "${DIR}" describe --tags --first-parent 2>/dev/null)
12
+DIR="${1:-Marlin}"
13
+READ_FILE="${READ_FILE:-${DIR}/Version.h}"
14
+WRITE_FILE="${WRITE_FILE:-${READ_FILE}}"
28 15
 
29
-[ -z "${BRANCH}" ] && BRANCH=$(echo "${TRAVIS_BRANCH}")
30
-[ -z "${VERSION}" ] && VERSION=$(git -C "${DIR}" describe --tags --first-parent --always 2>/dev/null)
16
+BRANCH="$(git -C "${DIR}" symbolic-ref -q --short HEAD 2>/dev/null || true)"
17
+VERSION="$(git -C "${DIR}" describe --tags --first-parent 2>/dev/null || true)"
31 18
 
32
-SHORT_BUILD_VERSION=$(echo "${BRANCH}")
33
-DETAILED_BUILD_VERSION=$(echo "${BRANCH}-${VERSION}")
19
+STRING_DISTRIBUTION_DATE="${STRING_DISTRIBUTION_DATE:-$(date '+%Y-%m-%d %H:%M')}"
20
+SHORT_BUILD_VERSION="${SHORT_BUILD_VERSION:-${BRANCH}}"
21
+DETAILED_BUILD_VERSION="${DETAILED_BUILD_VERSION:-${BRANCH}-${VERSION}}"
34 22
 
35 23
 # Gets some misc options from their defaults
36
-DEFAULT_MACHINE_UUID=$(awk -F'"' \
37
-  '/#define DEFAULT_MACHINE_UUID/{ print $2 }' < "${DIR}/Version.h")
38
-MACHINE_NAME=$(awk -F'"' \
39
-  '/#define MACHINE_NAME/{ print $2 }' < "${DIR}/Version.h")
40
-PROTOCOL_VERSION=$(awk -F'"' \
41
-  '/#define PROTOCOL_VERSION/{ print $2 }' < "${DIR}/Version.h")
42
-SOURCE_CODE_URL=$(awk -F'"' \
43
-  '/#define SOURCE_CODE_URL/{ print $2 }' < "${DIR}/Version.h")
44
-WEBSITE_URL=$(awk -F'"' \
45
-  '/#define WEBSITE_URL/{ print $2 }' < "${DIR}/Version.h")
46
-
47
-cat > "${DIR}/Version.h" <<EOF
24
+DEFAULT_MACHINE_UUID="${DEFAULT_MACHINE_UUID:-$(awk -F'"' \
25
+  '/#define DEFAULT_MACHINE_UUID/{ print $2 }' < "${READ_FILE}")}"
26
+MACHINE_NAME="${MACHINE_NAME:-$(awk -F'"' \
27
+  '/#define MACHINE_NAME/{ print $2 }' < "${READ_FILE}")}"
28
+PROTOCOL_VERSION="${PROTOCOL_VERSION:-$(awk -F'"' \
29
+  '/#define PROTOCOL_VERSION/{ print $2 }' < "${READ_FILE}")}"
30
+SOURCE_CODE_URL="${SOURCE_CODE_URL:-$(awk -F'"' \
31
+  '/#define SOURCE_CODE_URL/{ print $2 }' < "${READ_FILE}")}"
32
+WEBSITE_URL="${WEBSITE_URL:-$(awk -F'"' \
33
+  '/#define WEBSITE_URL/{ print $2 }' < "${READ_FILE}")}"
34
+
35
+cat > "${WRITE_FILE}" <<EOF
48 36
 /**
49 37
  * Marlin 3D Printer Firmware
50 38
  * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
@@ -97,7 +85,7 @@ cat > "${DIR}/Version.h" <<EOF
97 85
   * version was tagged.
98 86
   */
99 87
 #ifndef STRING_DISTRIBUTION_DATE
100
-  #define STRING_DISTRIBUTION_DATE "${DISTDATE}"
88
+  #define STRING_DISTRIBUTION_DATE "${STRING_DISTRIBUTION_DATE}"
101 89
 #endif
102 90
 
103 91
 /**

Loading…
取消
儲存