From 4aabf770cd9c2d65a8553488b8b1794f34f55ab6 Mon Sep 17 00:00:00 2001 From: GeminiServer Date: Thu, 19 Mar 2020 00:42:25 +0100 Subject: [PATCH 1/2] Removed BUILD_VERSION from python translation Add. new version.h, which included now the build version. Adapted build.sh - to extract the build version from versioh.h and sends it to translation script. --- Translation Editor/make_translation.py | 35 ++++++++++++-------------- workspace/TS100/build.sh | 16 +++++++++++- workspace/TS100/version.h | 7 ++++++ 3 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 workspace/TS100/version.h diff --git a/Translation Editor/make_translation.py b/Translation Editor/make_translation.py index 4edc0bdac9..06a65c3a48 100755 --- a/Translation Editor/make_translation.py +++ b/Translation Editor/make_translation.py @@ -8,12 +8,6 @@ import sys import fontTables -# To cause no confusion with the original firmware version of TS100, -# which actually has the latest firmware version 2.18 -# Lets go ahead start with version 2.20.0001 BETA -# Version String: xx.yy.zzzz TAG --> x:Major y:Minor z:Build TAG: REL | BETA | ALPHA -BUILD_VERSION = 'V2.20.0001 BETA' - TRANSLATION_CPP = "Translation.cpp" try: @@ -101,7 +95,7 @@ def getConstants(): consants.append(('SymbolVolts', 'V')) consants.append(('SymbolDC', 'DC')) consants.append(('SymbolCellCount', 'S')) - consants.append(('SymbolVersionNumber', BUILD_VERSION)) + consants.append(('SymbolVersionNumber', buildVersion)) return consants @@ -460,24 +454,26 @@ def writeLanguage(languageCode, defs, f): def read_opts(): """ Reading input parameters - First parameter = json directory - Second parameter = target directory + First parameter = build version + Second parameter = json directory + Third parameter = target directory """ if len(sys.argv) > 1: - jsonDir = sys.argv[1] + buildVersion = sys.argv[1] else: - jsonDir = "." - + raise Exception("Could not get build version") if len(sys.argv) > 2: - outFile = sys.argv[2] + jsonDir = sys.argv[2] + else: + jsonDir = "." + if len(sys.argv) > 3: + outFile = sys.argv[3] else: outDir = os.path.relpath(jsonDir + "/../workspace/TS100/Core/Src") outFile = os.path.join(outDir, TRANSLATION_CPP) - - if len(sys.argv) > 3: + if len(sys.argv) > 4: raise Exception("Too many parameters!") - - return jsonDir, outFile + return jsonDir, outFile, buildVersion def orderOutput(langDict): @@ -506,11 +502,12 @@ def writeTarget(outFile, defs, langCodes): if __name__ == "__main__": try: - jsonDir, outFile = read_opts() + jsonDir, outFile, buildVersion = read_opts() except: - print("usage: make_translation.py {json dir} {cpp dir}") + print("usage: make_translation.py {build version} {json dir} {cpp dir}") sys.exit(1) + print("Build version string: " + buildVersion) print("Making " + outFile + " from " + jsonDir) langDict = readTranslations(jsonDir) diff --git a/workspace/TS100/build.sh b/workspace/TS100/build.sh index 7bfff64dec..52ffddfa6e 100755 --- a/workspace/TS100/build.sh +++ b/workspace/TS100/build.sh @@ -8,6 +8,7 @@ AVAILABLE_LANGUAGES=() BUILD_LANGUAGES=() AVAILABLE_MODELS=("TS100" "TS80") BUILD_MODELS=() +BUILD_VERSION=() usage () { @@ -22,6 +23,14 @@ INFO : By default, without parameters, the build is for all platforms and all la exit 1 } +buildVersion () +{ + GIT_HASH="$(git describe --always)" + VERSION="$(grep '#define BUILD_VERSION' 'version.h' | awk '{print $3}' | sed 's/"//g')" + BUILD_VERSION=$VERSION'.'$GIT_HASH + echo "Building version: $BUILD_VERSION" +} + checkLastCommand () { if [ $? -eq 0 ] @@ -78,6 +87,11 @@ echo " Builder for the" echo " Alternate Open Source Firmware" echo " for Miniware TS100 or TS80" echo " by Ralim" +echo " " +echo "*********************************************" + +#Get and show build version +buildVersion echo "*********************************************" # Calculate available languages @@ -129,7 +143,7 @@ echo "*********************************************" if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ] then echo "Generating Translation.cpp" - python3 "$TRANSLATION_DIR/$TRANSLATION_SCRIPT" "$TRANSLATION_DIR" + python3 "$TRANSLATION_DIR/$TRANSLATION_SCRIPT" "$BUILD_VERSION" "$TRANSLATION_DIR" checkLastCommand echo "Cleaning previous builds" diff --git a/workspace/TS100/version.h b/workspace/TS100/version.h new file mode 100644 index 0000000000..66e80c4148 --- /dev/null +++ b/workspace/TS100/version.h @@ -0,0 +1,7 @@ +/** + * Firmware build version - format: xx.yy.zzzzzz + * x: Major - y: Minor - z: git short hash generated automaticaly from git + * i.e.: BUILD_VERSION = 'Rel. v2.08' --> Will generated to: 'v2.08.1a2b3c4' + */ + +#define BUILD_VERSION "v2.08" From a5ec2bcfa0f39e6074464db2c3f89c3a0f815096 Mon Sep 17 00:00:00 2001 From: GeminiServer Date: Thu, 19 Mar 2020 18:17:20 +0100 Subject: [PATCH 2/2] Let's try in in python translate script directly, to keep support ci process. Reverted build.sh --- Translation Editor/make_translation.py | 50 +++++++++++++++++--------- workspace/TS100/build.sh | 15 +------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Translation Editor/make_translation.py b/Translation Editor/make_translation.py index 06a65c3a48..364489967f 100755 --- a/Translation Editor/make_translation.py +++ b/Translation Editor/make_translation.py @@ -7,6 +7,8 @@ from datetime import datetime import sys import fontTables +import re +import subprocess TRANSLATION_CPP = "Translation.cpp" @@ -451,29 +453,43 @@ def writeLanguage(languageCode, defs, f): # ----- Block end f.write(to_unicode("#endif\n")) +def readVersion(): + with open(os.path.relpath(jsonDir + + "/../workspace/TS100/version.h"),"r") as version_file: + try: + for line in version_file: + if re.findall(r'^.*(?<=(#define)).*(?<=(BUILD_VERSION))', line): + line = re.findall(r'\"(.+?)\"',line) + if line: + version = line[0] + try: version += "."+ subprocess.check_output( + ["git","describe", "--always"]).strip().decode('ascii').upper() + except OSError: version += " git" + finally: + if version_file: + version_file.close(); + return version def read_opts(): """ Reading input parameters - First parameter = build version - Second parameter = json directory - Third parameter = target directory + First parameter = json directory + Second parameter = target directory """ if len(sys.argv) > 1: - buildVersion = sys.argv[1] - else: - raise Exception("Could not get build version") - if len(sys.argv) > 2: - jsonDir = sys.argv[2] + jsonDir = sys.argv[1] else: jsonDir = "." - if len(sys.argv) > 3: - outFile = sys.argv[3] + + if len(sys.argv) > 2: + outFile = sys.argv[2] else: outDir = os.path.relpath(jsonDir + "/../workspace/TS100/Core/Src") outFile = os.path.join(outDir, TRANSLATION_CPP) - if len(sys.argv) > 4: + + if len(sys.argv) > 3: raise Exception("Too many parameters!") - return jsonDir, outFile, buildVersion + + return jsonDir, outFile def orderOutput(langDict): @@ -499,15 +515,17 @@ def writeTarget(outFile, defs, langCodes): for langCode in langCodes: writeLanguage(langCode, defs, f) - if __name__ == "__main__": try: - jsonDir, outFile, buildVersion = read_opts() + jsonDir, outFile = read_opts() except: - print("usage: make_translation.py {build version} {json dir} {cpp dir}") + print("usage: make_translation.py {json dir} {cpp dir}") sys.exit(1) - print("Build version string: " + buildVersion) + try: buildVersion = readVersion() + except: print("error: could not get/extract build version"); sys.exit(1) + + print("Build version: " + buildVersion) print("Making " + outFile + " from " + jsonDir) langDict = readTranslations(jsonDir) diff --git a/workspace/TS100/build.sh b/workspace/TS100/build.sh index 52ffddfa6e..77181aedeb 100755 --- a/workspace/TS100/build.sh +++ b/workspace/TS100/build.sh @@ -8,7 +8,6 @@ AVAILABLE_LANGUAGES=() BUILD_LANGUAGES=() AVAILABLE_MODELS=("TS100" "TS80") BUILD_MODELS=() -BUILD_VERSION=() usage () { @@ -23,14 +22,6 @@ INFO : By default, without parameters, the build is for all platforms and all la exit 1 } -buildVersion () -{ - GIT_HASH="$(git describe --always)" - VERSION="$(grep '#define BUILD_VERSION' 'version.h' | awk '{print $3}' | sed 's/"//g')" - BUILD_VERSION=$VERSION'.'$GIT_HASH - echo "Building version: $BUILD_VERSION" -} - checkLastCommand () { if [ $? -eq 0 ] @@ -90,10 +81,6 @@ echo " by Ralim" echo " " echo "*********************************************" -#Get and show build version -buildVersion -echo "*********************************************" - # Calculate available languages for f in "$TRANSLATION_DIR"/translation_*.json do @@ -143,7 +130,7 @@ echo "*********************************************" if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ] then echo "Generating Translation.cpp" - python3 "$TRANSLATION_DIR/$TRANSLATION_SCRIPT" "$BUILD_VERSION" "$TRANSLATION_DIR" + python3 "$TRANSLATION_DIR/$TRANSLATION_SCRIPT" "$TRANSLATION_DIR" checkLastCommand echo "Cleaning previous builds"