Skip to content

Commit 7778e78

Browse files
jeplerdpgeorge
authored andcommitted
tools/metrics.py: Allow pre_cmd to set up environment.
This is a necessary step to allow cleanly building the xtensa port during CI, as it's undesirable to apply the esp-idf environment settings while building other ports. PRE_CMD_<letter> can be used to override the command, or add a command if not otherwise specified. Note that <letter> is case sensitive. Signed-off-by: Jeff Epler <jepler@unpythonic.net>
1 parent f982158 commit 7778e78

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

tools/metrics.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,19 @@
4343
4444
"""
4545

46-
import collections, sys, re, subprocess, multiprocessing
46+
import collections, os, sys, re, shlex, subprocess, multiprocessing
4747

4848
MAKE_FLAGS = ["-j{}".format(multiprocessing.cpu_count()), "CFLAGS_EXTRA=-DNDEBUG"]
4949

5050

5151
class PortData:
52-
def __init__(self, name, dir, output, make_flags=None):
52+
def __init__(self, name, dir, output, make_flags=None, pre_cmd=None):
5353
self.name = name
5454
self.dir = dir
5555
self.output = output
5656
self.make_flags = make_flags
5757
self.needs_mpy_cross = dir not in ("bare-arm", "minimal")
58+
self.pre_cmd = pre_cmd
5859

5960

6061
mpy_cross_output = "mpy-cross/build/mpy-cross"
@@ -67,7 +68,12 @@ def __init__(self, name, dir, output, make_flags=None):
6768
"s": PortData("stm32", "stm32", "build-PYBV10/firmware.elf", "BOARD=PYBV10"),
6869
"c": PortData("cc3200", "cc3200", "build/WIPY/release/application.axf", "BTARGET=application"),
6970
"8": PortData("esp8266", "esp8266", "build-ESP8266_GENERIC/firmware.elf"),
70-
"3": PortData("esp32", "esp32", "build-ESP32_GENERIC/micropython.elf"),
71+
"3": PortData(
72+
"esp32",
73+
"esp32",
74+
"build-ESP32_GENERIC/micropython.elf",
75+
pre_cmd=". esp-idf/export.sh",
76+
),
7177
"x": PortData("mimxrt", "mimxrt", "build-TEENSY40/firmware.elf"),
7278
"e": PortData("renesas-ra", "renesas-ra", "build-EK_RA6M2/firmware.elf"),
7379
"r": PortData("nrf", "nrf", "build-PCA10040/firmware.elf"),
@@ -76,15 +82,26 @@ def __init__(self, name, dir, output, make_flags=None):
7682
"v": PortData("qemu rv32", "qemu", "build-VIRT_RV32/firmware.elf", "BOARD=VIRT_RV32"),
7783
}
7884

85+
for port_letter, port in port_data.items():
86+
port.pre_cmd = os.environ.get(f"PRE_CMD_{port_letter}", port.pre_cmd)
7987

80-
def syscmd(*args):
88+
89+
def quoted(args):
90+
return " ".join(shlex.quote(word) for word in args)
91+
92+
93+
def syscmd(*args, pre_cmd=None):
8194
sys.stdout.flush()
8295
a2 = []
8396
for a in args:
8497
if isinstance(a, str):
8598
a2.append(a)
8699
elif a:
87100
a2.extend(a)
101+
if pre_cmd is not None:
102+
a2_quoted = quoted(a2)
103+
a2 = ["bash", "-c", "{} && {}".format(pre_cmd, a2_quoted)]
104+
print(a2)
88105
subprocess.check_call(a2)
89106

90107

@@ -190,7 +207,14 @@ def do_clean(args):
190207
syscmd("make", "-C", "mpy-cross", "clean")
191208

192209
for port in ports:
193-
syscmd("make", "-C", "ports/{}".format(port.dir), port.make_flags, "clean")
210+
syscmd(
211+
"make",
212+
"-C",
213+
"ports/{}".format(port.dir),
214+
port.make_flags,
215+
"clean",
216+
pre_cmd=port.pre_cmd,
217+
)
194218

195219

196220
def do_build(args):
@@ -204,7 +228,14 @@ def do_build(args):
204228

205229
print("BUILDING PORTS")
206230
for port in ports:
207-
syscmd("make", "-C", "ports/{}".format(port.dir), MAKE_FLAGS, port.make_flags)
231+
syscmd(
232+
"make",
233+
"-C",
234+
"ports/{}".format(port.dir),
235+
MAKE_FLAGS,
236+
port.make_flags,
237+
pre_cmd=port.pre_cmd,
238+
)
208239

209240
do_sizes(args)
210241

0 commit comments

Comments
 (0)