|
8 | 8 |
|
9 | 9 | import argparse |
10 | 10 | from argparse import RawDescriptionHelpFormatter |
| 11 | +from esp_docs.generic_extensions.docs_embed.tool.wokwi_tool import DiagramSync |
11 | 12 | import json |
12 | 13 | import os |
13 | 14 | import shutil |
|
20 | 21 | # Determine SDKCONFIG_DIR like the shell script |
21 | 22 | ARDUINO_ESP32_PATH = os.environ.get("ARDUINO_ESP32_PATH") |
22 | 23 | GITHUB_WORKSPACE = os.environ.get("GITHUB_WORKSPACE") |
| 24 | +DOCS_DEPLOY_URL_BASE = os.environ.get("DOCS_PROD_URL_BASE") |
| 25 | +REPO_URL_PREFIX = os.environ.get("REPO_URL_PREFIX") |
| 26 | + |
23 | 27 |
|
24 | 28 | if ARDUINO_ESP32_PATH and (Path(ARDUINO_ESP32_PATH) / "tools" / "esp32-arduino-libs").is_dir(): |
25 | 29 | SDKCONFIG_DIR = Path(ARDUINO_ESP32_PATH) / "tools" / "esp32-arduino-libs" |
|
31 | 35 | # Wrapper functions to call sketch_utils.sh |
32 | 36 | SKETCH_UTILS = SCRIPT_DIR / "sketch_utils.sh" |
33 | 37 |
|
34 | | -KEEP_FILES = ["*.merged.bin", "ci.json"] |
| 38 | +KEEP_FILES = [ |
| 39 | + "*.merged.bin", |
| 40 | + "ci.json", |
| 41 | + "launchpad.toml", |
| 42 | + "diagram*.json", |
| 43 | +] |
35 | 44 | DOCS_BINARIES_DIR = Path("docs/_static/binaries") |
36 | 45 | GENERATE_DIAGRAMS = False |
37 | | -LAUNCHPAD_STORAGE_URL = "" |
| 46 | +GENERATE_LAUNCHPAD_CONFIG = False |
38 | 47 |
|
39 | 48 |
|
40 | 49 | def run_cmd(cmd, check=True, capture_output=False, text=True): |
@@ -117,8 +126,9 @@ def parse_args(argv): |
117 | 126 | ) |
118 | 127 | p.add_argument( |
119 | 128 | "-l", |
120 | | - dest="launchpad_storage_url", |
121 | | - help="LaunchPad storage URL to include in generated config", |
| 129 | + dest="generate_launchpad_config", |
| 130 | + action="store_true", |
| 131 | + help="Generate LaunchPad config with configured storage URL", |
122 | 132 | ) |
123 | 133 | return p.parse_args(argv) |
124 | 134 |
|
@@ -233,42 +243,18 @@ def build_example_for_target(sketch_dir, target, relative_path, args): |
233 | 243 | shutil.copy(ci_json, output_dir / 'ci.json') |
234 | 244 | if GENERATE_DIAGRAMS: |
235 | 245 | print(f"Generating diagram for {relative_path} ({target})...") |
236 | | - rc = run_cmd( |
237 | | - [ |
238 | | - "docs-embed", |
239 | | - "--path", |
240 | | - str(output_dir), |
241 | | - "diagram-from-ci", |
242 | | - "--platform", |
243 | | - target, |
244 | | - "--override", |
245 | | - ], |
246 | | - check=False, |
247 | | - ) |
248 | | - if rc.returncode == 0: |
249 | | - print("Diagram generated successfully for {relative_path} ({target})") |
250 | | - else: |
251 | | - print("WARNING: Failed to generate diagram for {relative_path} ({target})") |
252 | | - if LAUNCHPAD_STORAGE_URL: |
| 246 | + try: |
| 247 | + sync = DiagramSync(output_dir) |
| 248 | + sync.generate_diagram_from_ci(target) |
| 249 | + except Exception as e: |
| 250 | + print(f"WARNING: Failed to generate diagram for {relative_path} ({target}): {e}") |
| 251 | + if GENERATE_LAUNCHPAD_CONFIG: |
253 | 252 | print(f"Generating LaunchPad config for {relative_path} ({target})...") |
254 | | - rc = run_cmd( |
255 | | - [ |
256 | | - "docs-embed", |
257 | | - "--path", |
258 | | - str(output_dir), |
259 | | - "launchpad-config", |
260 | | - LAUNCHPAD_STORAGE_URL, |
261 | | - "--repo-url-prefix", |
262 | | - "https://github.com/espressif/arduino-esp32/tree/master", |
263 | | - "--override", |
264 | | - ], |
265 | | - check=False, |
266 | | - ) |
267 | | - if rc.returncode == 0: |
268 | | - print("LaunchPad config generated successfully for {relative_path} ({target})") |
269 | | - else: |
270 | | - print("WARNING: Failed to generate LaunchPad config for {relative_path} ({target})") |
271 | | - return True |
| 253 | + try: |
| 254 | + sync = DiagramSync(output_dir) |
| 255 | + sync.generate_launchpad_config(DOCS_DEPLOY_URL_BASE, REPO_URL_PREFIX) |
| 256 | + except Exception as e: |
| 257 | + print(f"WARNING: Failed to generate LaunchPad config for {relative_path} ({target}): {e}") |
272 | 258 | else: |
273 | 259 | print(f"ERROR: Failed to build {relative_path} for {target}") |
274 | 260 | return False |
@@ -320,14 +306,14 @@ def build_all_examples(args): |
320 | 306 |
|
321 | 307 |
|
322 | 308 | def main(argv): |
323 | | - global GENERATE_DIAGRAMS, LAUNCHPAD_STORAGE_URL |
| 309 | + global GENERATE_DIAGRAMS, GENERATE_LAUNCHPAD_CONFIG |
324 | 310 | args = parse_args(argv) |
325 | 311 | if args.cleanup: |
326 | 312 | cleanup_binaries() |
327 | 313 | return |
328 | 314 | validate_prerequisites(args) |
329 | 315 | GENERATE_DIAGRAMS = args.generate_diagrams |
330 | | - LAUNCHPAD_STORAGE_URL = args.launchpad_storage_url or "" |
| 316 | + GENERATE_LAUNCHPAD_CONFIG = args.generate_launchpad_config |
331 | 317 | DOCS_BINARIES_DIR.mkdir(parents=True, exist_ok=True) |
332 | 318 | result = build_all_examples(args) |
333 | 319 | if result == 0: |
|
0 commit comments