Fixes #7171
[opentx.git] / tools / build-frsky.py
blob9e538bc4adbcb2815ffd1f8df6b4ae8196b39943
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",
109 translations = [
110 "EN",
111 "CZ"
115 def timestamp():
116 return datetime.datetime.now().strftime("%y%m%d")
119 def build(board, translation, srcdir):
120 cmake_options = " ".join(["-D%s=%s" % (key, value) for key, value in boards[board].items()])
121 cwd = os.getcwd()
122 if not os.path.exists("output"):
123 os.mkdir("output")
124 path = tempfile.mkdtemp()
125 os.chdir(path)
126 command = "cmake %s -DTRANSLATIONS=%s -DFRSKY_RELEASE=YES %s" % (cmake_options, translation, srcdir)
127 print(command)
128 os.system(command)
129 os.system("make firmware -j6")
130 os.chdir(cwd)
131 index = 0
132 while 1:
133 suffix = "" if index == 0 else "_%d" % index
134 filename = "output/firmware_%s_%s_%s%s.bin" % (board.lower(), translation.lower(), timestamp(), suffix)
135 if not os.path.exists(filename):
136 shutil.copy("%s/firmware.bin" % path, filename)
137 break
138 index += 1
139 shutil.rmtree(path)
142 def dir_path(string):
143 if os.path.isdir(string):
144 return string
145 else:
146 raise NotADirectoryError(string)
149 def main():
150 parser = argparse.ArgumentParser(description="Build FrSky firmware")
151 parser.add_argument("-b", "--boards", action="append", help="Destination boards", required=True)
152 parser.add_argument("-t", "--translations", action="append", help="Translations", required=True)
153 parser.add_argument("srcdir", type=dir_path)
155 args = parser.parse_args()
157 for board in (boards.keys() if "ALL" in args.boards else args.boards):
158 for translation in (translations if "ALL" in args.translations else args.translations):
159 build(board, translation, args.srcdir)
162 if __name__ == "__main__":
163 main()