-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·156 lines (130 loc) · 5.22 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·156 lines (130 loc) · 5.22 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
# Add scripts to sys.path to import boards
sys.path.append(os.path.join(os.path.dirname(__file__), "scripts"))
from boards import SUPPORTED_BOARDS
BOARDS = list(SUPPORTED_BOARDS.keys())
STEPS = ["webapp", "splash", "firmware"]
def build_webapp():
"""Build the webapp (npm install + npm run build)."""
print("\n=== Building webapp ===")
try:
subprocess.run("npm install", shell=True, check=True, cwd="webapp")
subprocess.run("npm run build", shell=True, check=True, cwd="webapp")
except subprocess.CalledProcessError as e:
print(f" ✗ Webapp build failed with exit code {e.returncode}")
sys.exit(e.returncode)
except FileNotFoundError:
print(
" ✗ 'npm' not found. Please ensure Node.js is installed and in your PATH."
)
sys.exit(1)
def generate_splash(board):
"""Generate splash screen EPDGZ for the target board."""
print(f"\n=== Generating splash screen for {board} ===", flush=True)
output_dir = os.path.join(os.path.dirname(__file__), "main", "splash_data")
script = os.path.join(os.path.dirname(__file__), "scripts", "generate_splash.py")
process_cli_dir = os.path.join(os.path.dirname(__file__), "process-cli")
# Ensure process-cli dependencies are installed
node_modules = os.path.join(process_cli_dir, "node_modules")
if not os.path.isdir(node_modules):
print(" Installing process-cli dependencies...")
try:
subprocess.run("npm ci", shell=True, check=True, cwd=process_cli_dir)
except subprocess.CalledProcessError as e:
print(f" ✗ npm ci failed in process-cli with exit code {e.returncode}")
sys.exit(e.returncode)
try:
subprocess.run(
[sys.executable, script, "--board", board, "--output-dir", output_dir],
check=True,
)
except subprocess.CalledProcessError as e:
print(f" ✗ Splash generation failed with exit code {e.returncode}")
sys.exit(e.returncode)
def build_firmware(board, extra_args, debug=False):
"""Build firmware with idf.py."""
print(f"\n=== Building firmware for {board}{' [debug]' if debug else ''} ===")
sdkconfig_defaults = f"sdkconfig.defaults;boards/sdkconfig.defaults.{board}"
if debug:
# Debug-only overlay: core-dump-to-flash capture (+ the coredump partition
# from generate_partitions.py). Changes the partition table — never used
# for release or demo builds.
sdkconfig_defaults += ";sdkconfig.defaults.debug"
idf_base = [
"idf.py",
f"-DSDKCONFIG_DEFAULTS={sdkconfig_defaults}",
]
cmake_defines = [a for a in extra_args if a.startswith("-D")]
post_build_args = [a for a in extra_args if not a.startswith("-D")]
build_cmd = idf_base + cmake_defines + ["build"]
print(f"Running: {' '.join(build_cmd)}")
try:
subprocess.run(build_cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Build failed with exit code {e.returncode}")
sys.exit(e.returncode)
except FileNotFoundError:
print(
"Error: 'idf.py' not found. Please ensure ESP-IDF is correctly installed and activated."
)
sys.exit(1)
# Run post-build commands (flash, monitor, etc.)
if post_build_args:
post_cmd = idf_base + post_build_args
print(f"Running: {' '.join(post_cmd)}")
try:
subprocess.run(post_cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Post-build command failed with exit code {e.returncode}")
sys.exit(e.returncode)
def main():
parser = argparse.ArgumentParser(description="Build firmware for different boards")
parser.add_argument(
"--board",
choices=BOARDS,
default="waveshare_photopainter_73",
help="Board type to build",
)
parser.add_argument(
"--fullclean",
action="store_true",
help="Remove sdkconfig and run idf.py fullclean before building",
)
parser.add_argument(
"--debug",
action="store_true",
help="Debug build: enable core-dump-to-flash capture. Changes the "
"partition table (adds a coredump partition) — do not ship to users.",
)
parser.add_argument(
"--step",
choices=STEPS,
action="append",
help="Run only specific step(s). Can be specified multiple times. "
"If omitted, all steps run.",
)
# Allow passing extra arguments to idf.py
args, extra_args = parser.parse_known_args()
steps = args.step if args.step else STEPS
if args.fullclean:
print("Performing full clean...")
import shutil
for f in ["sdkconfig", "partitions.csv"]:
if os.path.exists(f):
os.remove(f)
print(f" ✓ Removed {f}")
if os.path.isdir("build"):
shutil.rmtree("build")
print(" ✓ Removed build/")
if "webapp" in steps:
build_webapp()
if "splash" in steps:
generate_splash(args.board)
if "firmware" in steps:
build_firmware(args.board, extra_args, debug=args.debug)
if __name__ == "__main__":
main()