-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathrun_simulator.py
More file actions
63 lines (48 loc) · 2.33 KB
/
Copy pathrun_simulator.py
File metadata and controls
63 lines (48 loc) · 2.33 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
"""
PlatformIO library build script for the Crosspoint Simulator.
Handles two things automatically when this lib is included as a lib_dep:
1. Patches BookMetadataCache -- SpineEntry::cumulativeSize and its fast read
path can use size_t, which is 8 bytes on 64-bit hosts (macOS/Linux) but
4 bytes on ESP32-C3. This mismatch breaks binary cache serialization in the
simulator. Replaced with uint32_t, which is the correct explicit size on both
platforms. Applied idempotently -- safe to run on every build.
2. Patches GfxRenderer::setOrientation so simulator builds notify HalDisplay
when the logical orientation changes. Without this, the framebuffer content
can rotate while the SDL window keeps its startup portrait/landscape shape.
3. Registers a backward-compatible "run_simulator" custom target.
This file can be loaded more than once in the same PlatformIO process:
- once from this library's `library.json` build hook
- again indirectly when a consuming firmware repo adds the separate
`run_simulator_project.py` helper for IDE task exposure
Use a process-wide sentinel so the custom target is registered only once even
when multiple registration paths exist.
"""
Import("env")
import os
import builtins
import re
RUN_SIMULATOR_TARGET_KEY = "_crosspoint_run_simulator_target_registered"
RUN_SIMULATOR_TARGET_OWNER_OPTION = "custom_run_simulator_target_owner"
SIMULATOR_HTTP_PORT_OPTION = "custom_simulator_http_port"
# --- run_simulator custom target ---
def _run_simulator(source, target, env):
import subprocess
binary = env.subst("$BUILD_DIR/program")
runtime_env = os.environ.copy()
configured_http_port = env.GetProjectOption(
SIMULATOR_HTTP_PORT_OPTION, ""
).strip()
if configured_http_port:
runtime_env["CROSSPOINT_SIM_HTTP_PORT"] = configured_http_port
subprocess.run([binary], cwd=os.getcwd(), env=runtime_env)
target_owner = env.GetProjectOption(RUN_SIMULATOR_TARGET_OWNER_OPTION, "").strip().lower()
if target_owner != "project" and not getattr(builtins, RUN_SIMULATOR_TARGET_KEY, False):
setattr(builtins, RUN_SIMULATOR_TARGET_KEY, True)
env.AddCustomTarget(
name="run_simulator",
dependencies="$PROGPATH",
actions=_run_simulator,
title="Run Simulator",
description="Build and run the desktop simulator",
always_build=True,
)