Skip to content

Commit b48303f

Browse files
committed
Fallback to expected CI arduino folder /home/runner/Arduino
1 parent 7d7d530 commit b48303f

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

build_platform.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,21 +479,30 @@ def main():
479479
# Inject boards.local.txt if requested
480480
if COPY_BOARDS_LOCAL_TXT and boards_local_txt:
481481
try:
482+
local_app_data_dir = os.environ.get('HOME', '')
483+
data_dir = None
484+
if os.path.exists(os.path.join(local_app_data_dir, 'Arduino')):
485+
data_dir = os.path.join(local_app_data_dir, 'Arduino')
486+
elif os.path.exists(os.path.join(local_app_data_dir, '.arduino15')):
487+
data_dir = os.path.join(local_app_data_dir, '.arduino15')
488+
elif os.path.exists(os.path.join(local_app_data_dir, '.arduino')):
489+
data_dir = os.path.join(local_app_data_dir, '.arduino')
490+
482491
# Get arduino-cli data directory
483492
import json
484-
config_output = subprocess.check_output(["arduino-cli", "config", "dump", "--format", "json"]).decode()
493+
if data_dir:
494+
config_output = subprocess.check_output(["arduino-cli", "config", "dump", "--format", "json", "--config-dir", data_dir]).decode()
495+
else:
496+
config_output = subprocess.check_output(["arduino-cli", "config", "dump", "--format", "json"]).decode()
485497
config = json.loads(config_output)
486498
ColorPrint.print_info(f"Using arduino-cli config: {config_output.strip()}")
487499

488500
# Extract data directory, with fallback to default
489-
data_dir = config.get("directories", {}).get("data", "")
501+
data_dir = config.get("directories", {}).get("data", data_dir)
490502
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')
503+
ColorPrint.print_warn("No valid data directory found, cannot copy boards.local.txt")
504+
continue
505+
497506
ColorPrint.print_info(f"Using data directory: {data_dir}")
498507

499508
# Parse platform vendor and architecture from core_fqbn (e.g., "adafruit:samd")
@@ -507,8 +516,10 @@ def main():
507516

508517
ColorPrint.print_info(f"Using vendor: {vendor}, architecture: {architecture}")
509518

510-
# Construct base platform path
511-
platform_base = os.path.join(data_dir, "packages", vendor, "hardware", architecture)
519+
# Construct base platform path, fall back to architecture if vendor rebadged BSP.
520+
platform_base = os.path.join(data_dir, "packages", vendor, "hardware", architecture) if \
521+
os.path.exists(os.path.join(data_dir, "packages", vendor, "hardware", architecture)) else \
522+
os.path.join(data_dir, "packages", architecture, "hardware", architecture)
512523

513524
# Find the latest version directory
514525
if os.path.exists(platform_base):

0 commit comments

Comments
 (0)