Skip to content

Commit

Permalink
Let's try in in python translate script directly, to keep support ci …
Browse files Browse the repository at this point in the history
…process.

Reverted build.sh
  • Loading branch information
GeminiServer committed Mar 19, 2020
1 parent 4aabf77 commit a5ec2bc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
50 changes: 34 additions & 16 deletions Translation Editor/make_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from datetime import datetime
import sys
import fontTables
import re
import subprocess

TRANSLATION_CPP = "Translation.cpp"

Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
15 changes: 1 addition & 14 deletions workspace/TS100/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ AVAILABLE_LANGUAGES=()
BUILD_LANGUAGES=()
AVAILABLE_MODELS=("TS100" "TS80")
BUILD_MODELS=()
BUILD_VERSION=()

usage ()
{
Expand All @@ -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 ]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a5ec2bc

Please sign in to comment.