Skip to content

Commit 66622ba

Browse files
committed
Be more robust about version folders, but check for boards.txt first
1 parent 909fc32 commit 66622ba

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

build_platform.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,25 @@ def main():
528528

529529
# Find the latest version directory
530530
if os.path.exists(platform_base):
531-
versions = [d for d in os.listdir(platform_base) if os.path.isdir(os.path.join(platform_base, d))]
532-
ColorPrint.print_info(f"Found versions: {versions}")
533-
if versions:
534-
# Sort versions and take the latest (could be improved with proper version sorting)
535-
latest_version = sorted(versions)[-1]
536-
platform_path = os.path.join(platform_base, latest_version)
537-
538-
dest_path = os.path.join(platform_path, "boards.local.txt")
539-
shutil.copyfile(boards_local_txt, dest_path)
540-
ColorPrint.print_info(f"Copied boards.local.txt to {dest_path}")
541-
elif os.path.exists(os.path.join(platform_base, "boards.txt")):
531+
if os.path.exists(os.path.join(platform_base, "boards.txt")):
542532
shutil.copyfile(boards_local_txt, os.path.join(platform_base, "boards.local.txt"))
543533
ColorPrint.print_info(f"Copied boards.local.txt to {os.path.join(platform_base, 'boards.local.txt')}")
544534
else:
545-
ColorPrint.print_warn(f"No version directories found in {platform_base}")
535+
versions = [d for d in os.listdir(platform_base) if os.path.isdir(os.path.join(platform_base, d))]
536+
ColorPrint.print_info(f"Found versions: {versions}")
537+
# Filter out non-version directories (e.g., 'tools', 'libraries') while supporting 1.0-dev 1.0.0-offline-mode.102 etc
538+
versions = [v for v in versions if re.match(r'^(v)?\d+\.\d+(\.\d+(-\w+)?)?(\.\d+)?$', v)]
539+
if versions:
540+
# Sort versions and take the latest (could be improved with proper version sorting)
541+
latest_version = sorted(versions)[-1]
542+
platform_path = os.path.join(platform_base, latest_version)
543+
544+
dest_path = os.path.join(platform_path, "boards.local.txt")
545+
shutil.copyfile(boards_local_txt, dest_path)
546+
ColorPrint.print_info(f"Copied boards.local.txt to {dest_path}")
547+
548+
else:
549+
ColorPrint.print_warn(f"No version directories found in {platform_base}")
546550
else:
547551
ColorPrint.print_warn(f"Platform path {platform_base} does not exist")
548552

0 commit comments

Comments
 (0)