From a5ec2bcfa0f39e6074464db2c3f89c3a0f815096 Mon Sep 17 00:00:00 2001 From: GeminiServer Date: Thu, 19 Mar 2020 18:17:20 +0100 Subject: [PATCH] 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 06a65c3a..36448996 100755 --- a/Translation Editor/make_translation.py +++ b/Translation Editor/make_translation.py @@ -7,6 +7,8 @@ import io 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 52ffddfa..77181aed 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"