Updated: Companion Russian UI (#7211)
[opentx.git] / tools / build-frsky.py
blob3db1e97fb50bfdabda181d6b55f8eba18dcd948b
1 #!/usr/bin/python3
3 import argparse
4 import datetime
5 import os
6 from builtins import NotADirectoryError
7 import shutil
8 import tempfile
11 boards = {
12 "XLITE_FCC": {
13 "PCB": "XLITE",
14 "LUA": "NO_MODEL_SCRIPTS",
15 "GVARS": "YES",
16 "MODULE_SIZE_STD": "NO",
17 "PPM": "NO",
18 "DSM2": "NO",
19 "MULTIMODULE": "NO",
20 "CROSSFIRE": "NO",
21 "SBUS": "NO",
23 "XLITE_LBT": {
24 "PCB": "XLITE",
25 "MODULE_PROTOCOL_D8": "NO",
26 "LUA": "NO_MODEL_SCRIPTS",
27 "GVARS": "YES",
28 "MODULE_SIZE_STD": "NO",
29 "PPM": "NO",
30 "DSM2": "NO",
31 "MULTIMODULE": "NO",
32 "CROSSFIRE": "NO",
33 "SBUS": "NO",
35 "XLITES": {
36 "PCB": "XLITES",
37 "LUA": "NO_MODEL_SCRIPTS",
38 "GVARS": "YES",
39 "AUTOUPDATE": "YES",
40 "PXX1": "YES",
41 "XJT": "NO",
42 "MODULE_SIZE_STD": "NO",
43 "PPM": "NO",
44 "DSM2": "NO",
45 "MULTIMODULE": "NO",
46 "CROSSFIRE": "NO",
47 "SBUS": "NO",
49 "X9LITE": {
50 "PCB": "X9LITE",
51 "LUA": "NO_MODEL_SCRIPTS",
52 "GVARS": "YES",
53 "AUTOUPDATE": "YES",
54 "PXX1": "YES",
55 "XJT": "NO",
56 "MODULE_SIZE_STD": "NO",
57 "PPM": "NO",
58 "DSM2": "NO",
59 "MULTIMODULE": "NO",
60 "CROSSFIRE": "NO",
61 "SBUS": "NO",
62 "DEFAULT_MODE": "2",
64 "X9LITES": {
65 "PCB": "X9LITES",
66 "LUA": "NO_MODEL_SCRIPTS",
67 "GVARS": "YES",
68 "AUTOUPDATE": "YES",
69 "PXX1": "YES",
70 "XJT": "NO",
71 "MODULE_SIZE_STD": "NO",
72 "PPM": "NO",
73 "DSM2": "NO",
74 "MULTIMODULE": "NO",
75 "CROSSFIRE": "NO",
76 "SBUS": "NO",
77 "DEFAULT_MODE": "2",
79 "X9D+": {
80 "PCB": "X9D+",
81 "PCBREV": "2019",
82 "LUA": "NO_MODEL_SCRIPTS",
83 "GVARS": "YES",
84 "AUTOUPDATE": "YES",
85 "PXX1": "YES",
86 "MULTIMODULE": "NO",
87 "CROSSFIRE": "NO",
88 "DEFAULT_MODE": "2",
90 "X7_FCC": {
91 "PCB": "X7",
92 "LUA": "NO_MODEL_SCRIPTS",
93 "GVARS": "YES",
94 "MULTIMODULE": "NO",
95 "CROSSFIRE": "NO",
96 "DEFAULT_MODE": "2",
98 "X7_LBT": {
99 "PCB": "X7",
100 "MODULE_PROTOCOL_D8": "NO",
101 "LUA": "NO_MODEL_SCRIPTS",
102 "GVARS": "YES",
103 "MULTIMODULE": "NO",
104 "CROSSFIRE": "NO",
105 "DEFAULT_MODE": "2",
107 "X7ACCESS": {
108 "PCB": "X7",
109 "PCBREV": "ACCESS",
110 "LUA": "NO_MODEL_SCRIPTS",
111 "GVARS": "YES",
112 "AUTOUPDATE": "YES",
113 "PXX1": "YES",
114 "MULTIMODULE": "NO",
115 "CROSSFIRE": "NO",
116 "DEFAULT_MODE": "2",
120 translations = [
121 "EN",
122 "CZ"
126 def timestamp():
127 return datetime.datetime.now().strftime("%y%m%d")
130 def build(board, translation, srcdir):
131 cmake_options = " ".join(["-D%s=%s" % (key, value) for key, value in boards[board].items()])
132 cwd = os.getcwd()
133 if not os.path.exists("output"):
134 os.mkdir("output")
135 path = tempfile.mkdtemp()
136 os.chdir(path)
137 command = "cmake %s -DTRANSLATIONS=%s -DFRSKY_RELEASE=YES %s" % (cmake_options, translation, srcdir)
138 print(command)
139 os.system(command)
140 os.system("make firmware -j6")
141 os.chdir(cwd)
142 index = 0
143 while 1:
144 suffix = "" if index == 0 else "_%d" % index
145 filename = "output/firmware_%s_%s_%s%s.bin" % (board.lower(), translation.lower(), timestamp(), suffix)
146 if not os.path.exists(filename):
147 shutil.copy("%s/firmware.bin" % path, filename)
148 break
149 index += 1
150 shutil.rmtree(path)
153 def dir_path(string):
154 if os.path.isdir(string):
155 return string
156 else:
157 raise NotADirectoryError(string)
160 def main():
161 parser = argparse.ArgumentParser(description="Build FrSky firmware")
162 parser.add_argument("-b", "--boards", action="append", help="Destination boards", required=True)
163 parser.add_argument("-t", "--translations", action="append", help="Translations", required=True)
164 parser.add_argument("srcdir", type=dir_path)
166 args = parser.parse_args()
168 for board in (boards.keys() if "ALL" in args.boards else args.boards):
169 for translation in (translations if "ALL" in args.translations else args.translations):
170 build(board, translation, args.srcdir)
173 if __name__ == "__main__":
174 main()