@@ -479,19 +479,54 @@ def main():
479
479
# Inject boards.local.txt if requested
480
480
if COPY_BOARDS_LOCAL_TXT and boards_local_txt :
481
481
try :
482
- # Find platform path via ` arduino-cli core list --format json`
482
+ # Get arduino-cli data directory
483
483
import json
484
- output = subprocess .check_output (["arduino-cli" , "core" , "list" , "--format" , "json" ]).decode ()
485
- core_list = json .loads (output )["platforms" ]
486
- for core in core_list :
487
- if core ["id" ] == core_fqbn :
488
- platform_path = core ["install_dir" ]
484
+ config_output = subprocess .check_output (["arduino-cli" , "config" , "dump" , "--format" , "json" ]).decode ()
485
+ config = json .loads (config_output )
486
+ ColorPrint .print_info (f"Using arduino-cli config: { config_output .strip ()} " )
487
+
488
+ # Extract data directory, with fallback to default
489
+ data_dir = config .get ("directories" , {}).get ("data" , "" )
490
+ if not data_dir :
491
+ ColorPrint .print_warn ("No data directory found in arduino-cli config, using fallback locations." )
492
+ # Fallback to common default locations
493
+ if os .name == 'nt' : # Windows
494
+ data_dir = os .path .join (os .environ .get ('LOCALAPPDATA' , '' ), 'Arduino15' )
495
+ else : # Linux/macOS
496
+ data_dir = os .path .join (os .environ .get ('HOME' , '' ), '.arduino15' )
497
+ ColorPrint .print_info (f"Using data directory: { data_dir } " )
498
+
499
+ # Parse platform vendor and architecture from core_fqbn (e.g., "adafruit:samd")
500
+ parts = core_fqbn .split (':' )
501
+ if len (parts ) >= 2 :
502
+ vendor = parts [0 ]
503
+ architecture = parts [1 ]
504
+ else :
505
+ vendor = core_fqbn
506
+ architecture = vendor
507
+
508
+ ColorPrint .print_info (f"Using vendor: { vendor } , architecture: { architecture } " )
509
+
510
+ # Construct base platform path
511
+ platform_base = os .path .join (data_dir , "packages" , vendor , "hardware" , architecture )
512
+
513
+ # Find the latest version directory
514
+ if os .path .exists (platform_base ):
515
+ versions = [d for d in os .listdir (platform_base ) if os .path .isdir (os .path .join (platform_base , d ))]
516
+ ColorPrint .print_info (f"Found versions: { versions } " )
517
+ if versions :
518
+ # Sort versions and take the latest (could be improved with proper version sorting)
519
+ latest_version = sorted (versions )[- 1 ]
520
+ platform_path = os .path .join (platform_base , latest_version )
521
+
489
522
dest_path = os .path .join (platform_path , "boards.local.txt" )
490
523
shutil .copyfile (boards_local_txt , dest_path )
491
524
ColorPrint .print_info (f"Copied boards.local.txt to { dest_path } " )
492
- break
525
+ else :
526
+ ColorPrint .print_warn (f"No version directories found in { platform_base } " )
493
527
else :
494
- ColorPrint .print_warn (f"Could not find platform path for { core_fqbn } - not copying boards.local.txt" )
528
+ ColorPrint .print_warn (f"Platform path { platform_base } does not exist" )
529
+
495
530
except Exception as e :
496
531
ColorPrint .print_fail (f"Error injecting boards.local.txt for { core_fqbn } : { e } " )
497
532
print ('#' * 80 )
0 commit comments