MCPcopy Create free account
hub / github.com/FastLED/FastLED / _run_pio_size

Function _run_pio_size

ci/compiled_size.py:68–141  ·  view source on GitHub ↗
(build_dir: Path)

Source from the content-addressed store, hash-verified

66
67
68def _run_pio_size(build_dir: Path) -> int | None:
69 try:
70 # Try to compute size without building first
71 # Uses run_pio_command for proper process tracking and atexit cleanup
72 result = run_pio_command(
73 ["pio", "run", "-d", str(build_dir), "-t", "size"],
74 capture_output=True,
75 )
76 output = (result.stdout or "") + "\n" + (result.stderr or "")
77
78 # Try AVR format first: "Program: XXXXX bytes"
79 m = re.search(r"Program:\s*(\d+)\s*bytes", output)
80 if m:
81 return int(m.group(1))
82
83 # Try ARM toolchain format: "text data bss dec hex filename"
84 # Flash usage = text + data (initialized code and data in flash)
85 m = re.search(r"^\s*(\d+)\s+(\d+)\s+\d+\s+\d+\s+\w+\s+", output, re.MULTILINE)
86 if m:
87 text = int(m.group(1))
88 data = int(m.group(2))
89 return text + data
90
91 # Try teensy_size format (Teensy 4.x boards): "teensy_size: FLASH: code:XXX, data:YYY, headers:ZZZ"
92 # Flash usage = code + data + headers
93 m = re.search(
94 r"teensy_size:\s+FLASH:\s+code:(\d+),\s+data:(\d+),\s+headers:(\d+)", output
95 )
96 if m:
97 code = int(m.group(1))
98 data = int(m.group(2))
99 headers = int(m.group(3))
100 return code + data + headers
101
102 # If size target did not yield, try a full build then retry size
103 run_pio_command(
104 ["pio", "run", "-d", str(build_dir)],
105 capture_output=False,
106 )
107 result = run_pio_command(
108 ["pio", "run", "-d", str(build_dir), "-t", "size"],
109 capture_output=True,
110 )
111 output = (result.stdout or "") + "\n" + (result.stderr or "")
112
113 # Try AVR format first: "Program: XXXXX bytes"
114 m = re.search(r"Program:\s*(\d+)\s*bytes", output)
115 if m:
116 return int(m.group(1))
117
118 # Try ARM toolchain format: "text data bss dec hex filename"
119 # Flash usage = text + data (initialized code and data in flash)
120 m = re.search(r"^\s*(\d+)\s+(\d+)\s+\d+\s+\d+\s+\w+\s+", output, re.MULTILINE)
121 if m:
122 text = int(m.group(1))
123 data = int(m.group(2))
124 return text + data
125

Callers 1

check_firmware_sizeFunction · 0.85

Calls 2

run_pio_commandFunction · 0.90

Tested by

no test coverage detected