forked from likeablob/ulptool-pio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_extra_script_ulptool.py
63 lines (49 loc) · 1.66 KB
/
post_extra_script_ulptool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) likeablob
# SPDX-License-Identifier: MIT
from pathlib import Path
from SCons.Script import COMMAND_LINE_TARGETS, Import
Import("env", "projenv")
env = globals()["env"]
projenv = globals()["projenv"]
# Do not run extra script when IDE fetches C/C++ project metadata
if "idedata" in COMMAND_LINE_TARGETS:
env.Exit(0)
project_dir = Path(env["PROJECT_DIR"])
ulptool_dir = Path(env["PROJECT_LIBDEPS_DIR"]) / env["PIOENV"] / "ulptool-pio"
def run_ulptool():
platform = env.PioPlatform()
framework_dir = platform.get_package_dir("framework-arduinoespressif32")
toolchain_ulp_dir = platform.get_package_dir("toolchain-esp32ulp")
toolchain_xtensa_dir = platform.get_package_dir("toolchain-xtensa32-esp32")
cpp_defines = ""
for raw in env["CPPDEFINES"]:
k = None
if type(raw) is tuple:
k, v = raw
v = v if type(v) is not str else v.replace(" ", r"\ ")
flag = f"--D{k}={v} "
else:
k = raw
flag = f"--D{k} "
if k.startswith("ARDUINO"):
cpp_defines += flag
# TODO: Rewrite with process.run()
res = env.Execute(
f"""$PYTHONEXE \
{ulptool_dir}/src/esp32ulp_build_recipe.py \
$_CPPINCFLAGS \
-b {project_dir} \
-p {framework_dir} \
-u {toolchain_ulp_dir}/bin \
-x {toolchain_xtensa_dir}/bin \
-t {ulptool_dir}/src/ \
{cpp_defines}
"""
)
if res:
raise Exception("An error returned by ulptool.")
def cb(*args, **kwargs):
print("Running ulptool")
run_ulptool()
# Run ulptool just before linking .elf
env.AddPreAction("$BUILD_DIR/${PROGNAME}.elf", cb)