Attempt to make the OSX package (no need to build a firmware)
[opentx.git] / tools / build-jumper.py
blobab3fb9e45164189cb84827d56d24d00920d4214b
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 "T12": {
13 "PCB": "X7",
14 "PCBREV": "T12",
15 "DEFAULT_MODE": "2",
17 "T12PRO": {
18 "PCB": "X7",
19 "PCBREV": "T12",
20 "INTERNAL_MODULE_MULTI": "YES",
21 "DEFAULT_MODE": "2",
23 "T16": {
24 "PCB": "X10",
25 "PCBREV": "T16",
26 "INTERNAL_MODULE_MULTI": "YES",
27 "DEFAULT_MODE": "2",
31 translations = [
32 "EN",
36 def timestamp():
37 return datetime.datetime.now().strftime("%y%m%d")
40 def build(board, translation, srcdir):
41 cmake_options = " ".join(["-D%s=%s" % (key, value) for key, value in boards[board].items()])
42 cwd = os.getcwd()
43 if not os.path.exists("output"):
44 os.mkdir("output")
45 path = tempfile.mkdtemp()
46 os.chdir(path)
47 command = "cmake %s -DTRANSLATIONS=%s -DJUMPER_RELEASE=YES %s" % (cmake_options, translation, srcdir)
48 print(command)
49 os.system(command)
50 os.system("make firmware -j6")
51 os.chdir(cwd)
52 index = 0
53 while 1:
54 suffix = "" if index == 0 else "_%d" % index
55 filename = "output/firmware_%s_%s_%s%s.bin" % (board.lower(), translation.lower(), timestamp(), suffix)
56 if not os.path.exists(filename):
57 shutil.copy("%s/firmware.bin" % path, filename)
58 break
59 index += 1
60 shutil.rmtree(path)
63 def dir_path(string):
64 if os.path.isdir(string):
65 return string
66 else:
67 raise NotADirectoryError(string)
70 def main():
71 parser = argparse.ArgumentParser(description="Build JumperRC firmware")
72 parser.add_argument("-b", "--boards", action="append", help="Destination boards", required=True)
73 parser.add_argument("-t", "--translations", action="append", help="Translations", required=True)
74 parser.add_argument("srcdir", type=dir_path)
76 args = parser.parse_args()
78 for board in (boards.keys() if "ALL" in args.boards else args.boards):
79 for translation in (translations if "ALL" in args.translations else args.translations):
80 build(board, translation, args.srcdir)
83 if __name__ == "__main__":
84 main()