3 from __future__
import print_function
10 from fwoptions
import *
13 FIRMWARE_SIZE_TOO_BIG
= 1
20 def build_target(target
, path
, cmake_options
):
21 srcdir
= os
.path
.dirname(os
.path
.realpath(__file__
)) + "/../.."
22 outpath
= path
+ ".out"
23 errpath
= path
+ ".err"
27 for option
, value
in cmake_options
.items():
28 cmd
.append("-D%s=%s" % (option
, value
))
29 if "OPENTX_VERSION_SUFFIX" in os
.environ
:
30 suffix
= os
.environ
["OPENTX_VERSION_SUFFIX"]
31 cmd
.append('-DVERSION_SUFFIX="%s"' % suffix
)
32 if suffix
.startswith("N"):
33 cmd
.append('-DNIGHTLY_BUILD_WARNING=YES')
36 proc
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
37 output
, error
= proc
.communicate()
38 if proc
.returncode
== 0:
39 open(outpath
, "a").write("\n".join(cmd
) + output
.decode("utf-8") + error
.decode("utf-8"))
41 open(errpath
, "w").write(output
.decode("utf-8") + error
.decode("utf-8"))
42 return COMPILATION_ERROR
45 cmd
= ["make", "-j2", target
]
46 proc
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
47 output
, error
= proc
.communicate()
48 if proc
.returncode
== 0:
49 open(outpath
, "a").write(output
.decode("utf-8") + error
.decode("utf-8"))
51 open(errpath
, "w").write(output
.decode("utf-8") + error
.decode("utf-8"))
52 return COMPILATION_ERROR
58 if len(sys
.argv
) != 3:
59 exit(INVALID_FIRMWARE
)
62 directory
, filename
= os
.path
.split(sys
.argv
[2])
63 root
, ext
= os
.path
.splitext(filename
)
64 options
= root
.split("-")
66 if len(options
) < 2 or options
[0] != "opentx":
67 exit(INVALID_FIRMWARE
)
71 board_name
= options
[optcount
]
73 if board_name
== "sky9x":
74 cmake_options
["PCB"] = "SKY9X"
75 firmware_options
= options_sky9x
77 elif board_name
== "9xrpro":
78 cmake_options
["PCB"] = "9XRPRO"
79 cmake_options
["SDCARD"] = "YES"
80 firmware_options
= options_sky9x
82 elif board_name
== "ar9x":
83 cmake_options
["PCB"] = "AR9X"
84 cmake_options
["SDCARD"] = "YES"
85 firmware_options
= options_ar9x
87 elif board_name
== "x9lite":
88 cmake_options
["PCB"] = "X9LITE"
89 firmware_options
= options_taranis_x9lite
91 elif board_name
== "x9lites":
92 cmake_options
["PCB"] = "X9LITES"
93 firmware_options
= options_taranis_x9lite
95 elif options
[optcount
] == "x7":
96 cmake_options
["PCB"] = "X7"
97 firmware_options
= options_taranis_x9dp
99 elif board_name
== "xlite":
100 cmake_options
["PCB"] = "XLITE"
101 firmware_options
= options_taranis_xlite
103 elif board_name
== "xlites":
104 cmake_options
["PCB"] = "XLITES"
105 firmware_options
= options_taranis_xlites
107 elif board_name
== "x9d":
108 cmake_options
["PCB"] = "X9D"
109 firmware_options
= options_taranis_x9d
111 elif board_name
== "x9d+":
112 cmake_options
["PCB"] = "X9D+"
113 firmware_options
= options_taranis_x9dp
115 elif board_name
== "x9d+2019":
116 cmake_options
["PCB"] = "X9D+"
117 cmake_options
["PCBREV"] = "2019"
118 firmware_options
= options_taranis_x9dp
120 elif board_name
== "x9e":
121 cmake_options
["PCB"] = "X9E"
122 firmware_options
= options_taranis_x9e
124 elif board_name
== "x10":
125 cmake_options
["PCB"] = "X10"
126 firmware_options
= options_horus_x10
127 maxsize
= 2 * 1024 * 1024
128 elif board_name
== "x10express":
129 cmake_options
["PCB"] = "X10"
130 cmake_options
["PCBREV"] = "EXPRESS"
131 firmware_options
= options_horus_x10
132 maxsize
= 2 * 1024 * 1024
133 elif board_name
== "x12s":
134 cmake_options
["PCB"] = "X12S"
135 firmware_options
= options_horus_x12s
136 maxsize
= 2 * 1024 * 1024
137 elif board_name
== "t12":
138 cmake_options
["PCB"] = "X7"
139 cmake_options
["PCBREV"] = "T12"
140 firmware_options
= options_taranis_x9dp
142 elif board_name
== "t16":
143 cmake_options
["PCB"] = "X10"
144 cmake_options
["PCBREV"] = "T16"
145 firmware_options
= options_jumper_t16
146 maxsize
= 2 * 1024 * 1024
150 if target
== "firmware":
151 binary
= "firmware.bin"
154 elif target
== "libsimulator":
155 binary
= "libopentx-" + board_name
+ "-simulator.so"
157 filename
= "libopentx"
161 filename
+= "-" + board_name
164 # The firmware options
165 for opt
, values
in firmware_options
.items():
167 for i
in range(optcount
, len(options
)):
168 if options
[i
] == opt
:
172 if not isinstance(values
, list):
175 for name
, value1
, value2
in values
:
178 filename
+= "-" + opt
182 if value
is not None:
183 cmake_options
[name
] = value
185 # The firmware display language
187 for key
in languages
:
188 if key
== options
[-1]:
191 exit(INVALID_LANGUAGE
)
192 cmake_options
["TRANSLATIONS"] = language
.upper()
194 filename
+= "-" + language
+ ext
195 path
= os
.path
.join(directory
, filename
)
196 errpath
= path
+ ".err"
198 if os
.path
.isfile(errpath
):
200 exit(COMPILATION_ERROR
)
202 if os
.path
.isfile(path
):
206 lockpath
= path
+ ".lock"
207 lock
= filelock
.FileLock(lockpath
)
209 with lock
.acquire(timeout
=60 * 60):
210 if not os
.path
.isfile(path
):
211 result
= build_target(target
, path
, cmake_options
)
215 except filelock
.Timeout
:
217 exit(COMPILATION_ERROR
)
219 if target
== "firmware":
221 size
= os
.stat(binary
).st_size
223 return FIRMWARE_SIZE_TOO_BIG
225 # Copy binary to the binaries directory
226 shutil
.move(binary
, path
)
232 if __name__
== "__main__":