3535
3636SCRIPT_DIR = Path (__file__ ).resolve ().parent
3737
38+ env_config_keys = [
39+ "DOCS_EMBED_PUBLIC_ROOT" ,
40+ "DOCS_EMBED_GITHUB_BASE_URL" ,
41+ "DOCS_EMBED_BINARIES_DIR" ,
42+ ]
43+
44+ # load environment variables
45+ env_config = {}
46+ for key in env_config_keys :
47+ value = os .environ .get (key )
48+ if value is None :
49+ raise EnvironmentError (f"{ key } environment variable is not set" )
50+ env_config [key ] = value
51+
52+
53+ if env_config .get ("DOCS_EMBED_BINARIES_DIR" ):
54+ DOCS_EMBED_BINARIES_PATH = Path (f"docs/{ env_config ['DOCS_EMBED_BINARIES_DIR' ]} " )
55+
3856ARDUINO_ESP32_PATH = os .environ .get ("ARDUINO_ESP32_PATH" )
3957GITHUB_WORKSPACE = os .environ .get ("GITHUB_WORKSPACE" )
40- STORAGE_URL_PREFIX = os .environ .get ("STORAGE_URL_PREFIX" )
41- REPO_URL_PREFIX = os .environ .get ("REPO_URL_PREFIX" )
4258
4359if ARDUINO_ESP32_PATH and (Path (ARDUINO_ESP32_PATH ) / "tools" / "esp32-arduino-libs" ).is_dir ():
4460 SDKCONFIG_DIR = Path (ARDUINO_ESP32_PATH ) / "tools" / "esp32-arduino-libs"
4561elif GITHUB_WORKSPACE and (Path (GITHUB_WORKSPACE ) / "tools" / "esp32-arduino-libs" ).is_dir ():
4662 SDKCONFIG_DIR = Path (GITHUB_WORKSPACE ) / "tools" / "esp32-arduino-libs"
4763else :
48- SDKCONFIG_DIR = Path ("tools/esp32-arduino-libs" )
64+ raise EnvironmentError ("Could not locate esp32-arduino-libs directory. "
65+ "Set ARDUINO_ESP32_PATH or GITHUB_WORKSPACE environment variable." )
4966
5067KEEP_FILES = [
5168 "*.merged.bin" ,
5673]
5774
5875SKETCH_UTILS = SCRIPT_DIR / "sketch_utils.sh"
59- DOCS_BINARIES_DIR = Path ("docs/_static/binaries" )
60-
6176
6277def detect_arduino_paths ():
6378 """Get Arduino CLI and user paths from environment variables set by install-arduino-cli.sh
@@ -269,11 +284,11 @@ def cleanup_binaries():
269284 Removes all files except those matching patterns in KEEP_FILES.
270285 Also removes empty directories after cleanup.
271286 """
272- print (f"Cleaning up binaries directory: { DOCS_BINARIES_DIR } " )
273- if not DOCS_BINARIES_DIR .exists ():
287+ print (f"Cleaning up binaries directory: { DOCS_EMBED_BINARIES_PATH } " )
288+ if not DOCS_EMBED_BINARIES_PATH .exists ():
274289 print ("Binaries directory does not exist, nothing to clean" )
275290 return
276- for root , dirs , files in os .walk (DOCS_BINARIES_DIR ):
291+ for root , dirs , files in os .walk (DOCS_EMBED_BINARIES_PATH ):
277292 for fname in files :
278293 fpath = Path (root ) / fname
279294 parent = Path (root ).name
@@ -292,7 +307,7 @@ def cleanup_binaries():
292307 else :
293308 print (f"Keeping: { fpath } " )
294309 # remove empty dirs
295- for root , dirs , files in os .walk (DOCS_BINARIES_DIR , topdown = False ):
310+ for root , dirs , files in os .walk (DOCS_EMBED_BINARIES_PATH , topdown = False ):
296311 if not os .listdir (root ):
297312 try :
298313 os .rmdir (root )
@@ -356,7 +371,7 @@ def build_example_for_target(sketch_dir, target, relative_path, args):
356371 bool: True if build succeeded, False otherwise
357372 """
358373 print (f"\n > Building example: { relative_path } for target: { target } " )
359- output_dir = DOCS_BINARIES_DIR / relative_path / target
374+ output_dir = DOCS_EMBED_BINARIES_PATH / relative_path / target
360375 output_dir .mkdir (parents = True , exist_ok = True )
361376
362377 sdkconfig = SDKCONFIG_DIR / target / 'sdkconfig'
@@ -405,13 +420,13 @@ def build_all_examples(args):
405420 total_built = 0
406421 total_failed = 0
407422
408- if DOCS_BINARIES_DIR .exists ():
409- shutil .rmtree (DOCS_BINARIES_DIR )
410- print (f"Removed existing build directory: { DOCS_BINARIES_DIR } " )
423+ if DOCS_EMBED_BINARIES_PATH .exists ():
424+ shutil .rmtree (DOCS_EMBED_BINARIES_PATH )
425+ print (f"Removed existing build directory: { DOCS_EMBED_BINARIES_PATH } " )
411426
412427 # add gitignore to binaries dir with * for new files
413- DOCS_BINARIES_DIR .mkdir (parents = True , exist_ok = True )
414- gitignore_path = DOCS_BINARIES_DIR / '.gitignore'
428+ DOCS_EMBED_BINARIES_PATH .mkdir (parents = True , exist_ok = True )
429+ gitignore_path = DOCS_EMBED_BINARIES_PATH / '.gitignore'
415430 gitignore_path .write_text ("*\n " )
416431
417432 examples = find_examples_with_upload_binary ()
@@ -444,7 +459,7 @@ def build_all_examples(args):
444459 else :
445460 total_failed += 1
446461
447- output_sketch_dir = DOCS_BINARIES_DIR / relative_path
462+ output_sketch_dir = DOCS_EMBED_BINARIES_PATH / relative_path
448463 output_sketch_dir .mkdir (parents = True , exist_ok = True )
449464
450465 # copy sketch ci.yml to output dir - parent of target dirs
@@ -455,15 +470,20 @@ def build_all_examples(args):
455470 if args .generate_launchpad_config :
456471 print (f"Generating LaunchPad config for { relative_path } /{ target } ..." )
457472 try :
458- sync = DiagramSync (output_sketch_dir / target )
459- sync .generate_launchpad_config (STORAGE_URL_PREFIX , REPO_URL_PREFIX , True , output_sketch_dir )
473+ sync = DiagramSync (output_sketch_dir )
474+ sync .generate_launchpad_config (
475+ env_config ['DOCS_EMBED_PUBLIC_ROOT' ],
476+ env_config ['DOCS_EMBED_GITHUB_BASE_URL' ],
477+ True ,
478+ output_sketch_dir
479+ )
460480 except Exception as e :
461481 print (f"WARNING: Failed to generate LaunchPad config for { relative_path } /{ target } : { e } " )
462482
463483 print ('\n Build summary:' )
464484 print (f" Successfully built: { total_built } " )
465485 print (f" Failed builds: { total_failed } " )
466- print (f" Output directory: { DOCS_BINARIES_DIR } " )
486+ print (f" Output directory: { DOCS_EMBED_BINARIES_PATH } " )
467487 return total_failed
468488
469489
0 commit comments