Compare commits

...

3 commits

Author SHA1 Message Date
Tyeth Gundry
cf23f456c2 Update boards.local.txt example specific file logic 2025-08-18 19:09:24 +01:00
Tyeth Gundry
13e4c5177c add(log): say if example specific boards.local.txt not found 2025-08-18 17:22:50 +01:00
Tyeth Gundry
0c51dc01c7 fix(args): better safety around sys.argv access 2025-08-18 17:19:15 +01:00

View file

@ -35,7 +35,7 @@ COPY_BOARDS_LOCAL_TXT = False
boards_local_txt = None
if "--boards-local-txt" in sys.argv:
COPY_BOARDS_LOCAL_TXT = True
if sys.argv.index("--boards-local-txt") + 1 >= len(sys.argv):
if sys.argv.index("--boards-local-txt") + 1 == len(sys.argv):
# check if in cwd
if os.path.exists("boards.local.txt"):
boards_local_txt = "boards.local.txt"
@ -43,7 +43,14 @@ if "--boards-local-txt" in sys.argv:
sys.stderr.write("Error: --boards-local-txt option requires a path to boards.local.txt file or to be present in current directory\n")
sys.exit(1)
else:
# get the boards.local.txt file from the command line
# check second arg is file or another flag:
if sys.argv[sys.argv.index("--boards-local-txt") + 1].startswith("--"):
if os.path.exists("boards.local.txt"):
boards_local_txt = "boards.local.txt"
else:
sys.stderr.write("Error: --boards-local-txt option requires a path to boards.local.txt file (or to be present in current directory)\n")
sys.exit(1)
# get the boards.local.txt file from the command line (index exists checked earlier)
if not os.path.exists(sys.argv[sys.argv.index("--boards-local-txt") + 1]):
sys.stderr.write("Error: boards.local.txt file does not exist\n")
sys.exit(1)
@ -402,15 +409,23 @@ def test_examples_in_folder(platform, folderpath):
if os.path.exists(gen_file_name):
ColorPrint.print_info("generating")
# check if boards.local.txt should be copied
# check if root or example-specific boards.local.txt should be copied
if COPY_BOARDS_LOCAL_TXT:
boards_local_txt = folderpath+"/."+platform+".boards.local.txt"
if os.path.exists(boards_local_txt):
ColorPrint.print_info("Copying boards.local.txt from "+boards_local_txt)
install_boards_local_txt(":".join(fqbn.split(':')[0:2]), boards_local_txt)
elif os.path.exists(folderpath+"/boards.local.txt"):
ColorPrint.print_info("Copying boards.local.txt from "+folderpath+"/boards.local.txt")
install_boards_local_txt(":".join(fqbn.split(':')[0:2]), folderpath+"/boards.local.txt")
root_boards_local_txt = boards_local_txt
example_boards_local_txt = folderpath+"/boards.local.txt"
board_specific_example_boards_local_txt = folderpath+"/."+platform+".boards.local.txt"
if os.path.exists(board_specific_example_boards_local_txt):
ColorPrint.print_info("Copying boards.local.txt from "+board_specific_example_boards_local_txt)
install_boards_local_txt(":".join(fqbn.split(':')[0:2]), board_specific_example_boards_local_txt)
elif os.path.exists(example_boards_local_txt):
ColorPrint.print_info("Copying boards.local.txt from "+example_boards_local_txt)
install_boards_local_txt(":".join(fqbn.split(':')[0:2]), example_boards_local_txt)
else: # effectively does the revert if subsequent example doesn't have a specific boards.local.txt
ColorPrint.print_info("No example-specific boards.local.txt found to copy, using root version")
install_boards_local_txt(":".join(fqbn.split(':')[0:2]), root_boards_local_txt)
if BUILD_WARN:
if os.path.exists(gen_file_name):
@ -466,9 +481,9 @@ def install_boards_local_txt(core_fqbn, boards_local_txt):
name, vendor:architecture (e.g., "adafruit:samd").
:param str boards_local_txt: The path to the boards.local.txt file.
"""
local_app_data_dir = os.environ.get('HOME', '')
data_dir = None
try:
local_app_data_dir = os.environ.get('HOME', '')
data_dir = None
if os.path.exists(os.path.join(local_app_data_dir, '.arduino15')):
data_dir = os.path.join(local_app_data_dir, '.arduino15')
elif os.path.exists(os.path.join(local_app_data_dir, '.arduino')):
@ -482,7 +497,7 @@ def install_boards_local_txt(core_fqbn, boards_local_txt):
config_output = subprocess.check_output(["arduino-cli", "config", "dump", "--format", "json"]).decode()
config = json.loads(config_output)
ColorPrint.print_info(f"Using arduino-cli config: {config_output.strip()}")
# Extract data directory, with fallback to default
data_dir = config.get("directories", {}).get("data", "")
if not data_dir:
@ -529,7 +544,7 @@ def install_boards_local_txt(core_fqbn, boards_local_txt):
# Sort versions and take the latest (could be improved with proper version sorting)
latest_version = sorted(versions)[-1]
platform_path = os.path.join(platform_base, latest_version)
dest_path = os.path.join(platform_path, "boards.local.txt")
shutil.copyfile(boards_local_txt, dest_path)
ColorPrint.print_info(f"Copied boards.local.txt to {dest_path}")
@ -573,7 +588,7 @@ def main():
if COPY_BOARDS_LOCAL_TXT and boards_local_txt:
install_boards_local_txt(core_fqbn, boards_local_txt)
print('#'*80)
# Test examples in the platform folder
if not IS_LEARNING_SYS:
test_examples_in_folder(platform, BUILD_DIR+"/examples")