MCPcopy Create free account
hub / github.com/BruceDevices/firmware / generate_headers

Function generate_headers

gen_mqjs_headers.py:147–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145 return defines.get(flag_name)
146
147def generate_headers():
148 if not os.path.exists(MQJS_PATH):
149 return
150
151 if get_build_flag_value("LITE_VERSION") is not None or get_build_flag_value("DISABLE_INTERPRETER") is not None:
152 return
153
154 if not _gen_enabled():
155 print("Skipped MQJS headers build.")
156 return
157
158 os.makedirs(BUILD_DIR, exist_ok=True)
159
160 if not needs_rebuild():
161 return
162
163 try:
164 host_cc = _resolve_host_cc()
165 if not shutil.which(host_cc):
166 if os.path.exists(os.path.join(BJS_INTERPRETER_PATH, "mqjs_stdlib.h")):
167 print("Host compiler not found; skipping mqjs_stdlib header generation.")
168 print("Set MQJS_HOST_CC or mqjs_host_cc to a GCC-compatible compiler, or use Docker.")
169 print("\nOn Windows:\n- install MSYS2 https://www.msys2.org/ at default path")
170 print("- open C:\\msys64\\ucrt64.exe")
171 print("- run on UCRT64 terminal: pacman -S --needed mingw-w64-i686-toolchain")
172 print("- add C:\\msys64\\mingw32\\bin to PATH, cmd: setx PATH \"%PATH%;C:\\msys64\\mingw32\\bin\\\"")
173 print("- close and open VSCode again")
174 print("\nOn Mac:\n- run on terminal: xcode-select --install")
175 print("\nOn Linux:\n- run on terminal: sudo apt-get install -y --no-install-recommends gcc-multilib libc6-dev-i386\n\n")
176 return
177 raise RuntimeError("Host compiler not found and mqjs_stdlib.h is missing.")
178
179 # Build the generator as a native host executable. The output headers are
180 # still forced to 32-bit target format via the generator's `-m32` flag.
181 # Ensure the compiler's bin directory is in PATH so sub-processes
182 # (cc1, as, ld) can be found -- required on Windows/MSYS2.
183 cc_dir = os.path.dirname(shutil.which(host_cc) or host_cc)
184 sub_env = os.environ.copy()
185 if cc_dir:
186 sub_env["PATH"] = cc_dir + os.pathsep + sub_env.get("PATH", "")
187
188 gcc_result = subprocess.run(
189 [host_cc, *CFLAGS, "-o", GEN, *SRC],
190 capture_output=True,
191 text=True,
192 env=sub_env,
193 )
194 if gcc_result.returncode != 0:
195 if gcc_result.stdout:
196 print("gcc stdout:\n" + gcc_result.stdout)
197 if gcc_result.stderr:
198 print("gcc stderr:\n" + gcc_result.stderr)
199 raise subprocess.CalledProcessError(
200 gcc_result.returncode,
201 gcc_result.args,
202 output=gcc_result.stdout,
203 stderr=gcc_result.stderr,
204 )

Callers 1

Calls 6

get_build_flag_valueFunction · 0.85
_gen_enabledFunction · 0.85
needs_rebuildFunction · 0.85
_resolve_host_ccFunction · 0.85
write_build_stampFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected