-
Notifications
You must be signed in to change notification settings - Fork 69
Ci wippersnapper boards local txt #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tyeth
wants to merge
14
commits into
ci-wippersnapper
Choose a base branch
from
ci-wippersnapper-boards-local-txt
base: ci-wippersnapper
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f95039b
Add --boards-local-txt argument
tyeth 7a10d6d
Add copy step for boards.local.txt
tyeth d0c3507
clean up comments
tyeth 6f2978d
Correct drill-down to platforms
tyeth 7d7d530
Use config dump for data directory + generate platform path
tyeth b48303f
Fallback to expected CI arduino folder /home/runner/Arduino
tyeth 909fc32
Super robust/hacky fallbacks to the correct CI folder of /home/runner…
tyeth 66622ba
Be more robust about version folders, but check for boards.txt first
tyeth a51bab0
Refactor to install_boards_local_txt method
tyeth ea8dfa1
Use config folder, but fallback to known path for esp
tyeth e74ec16
Support example boards.local.txt and board specific .platform.boards.…
tyeth 0c51dc0
fix(args): better safety around sys.argv access
tyeth 13e4c51
add(log): say if example specific boards.local.txt not found
tyeth cf23f45
Update boards.local.txt example specific file logic
tyeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,35 @@ | |
sys.argv.pop(sys.argv.index("--build_timeout") + 1) | ||
sys.argv.remove("--build_timeout") | ||
|
||
# optional --boards-local-txt argument to copy boards.local.txt | ||
# to the appropriate folder after installing the platform BSP. | ||
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): | ||
# check if in cwd | ||
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) | ||
else: | ||
# 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) | ||
boards_local_txt = sys.argv[sys.argv.index("--boards-local-txt") + 1] | ||
Comment on lines
+47
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. second if should be elif but negated with the line57 body, and first if should confirm there is a period (".") in the argument that follows --boards-local-txt, and finally the error as else body. |
||
sys.argv.pop(sys.argv.index("--boards-local-txt") + 1) | ||
sys.argv.remove("--boards-local-txt") | ||
|
||
# add user bin to path! | ||
BUILD_DIR = '' | ||
# add user bin to path! | ||
|
@@ -380,6 +409,24 @@ def test_examples_in_folder(platform, folderpath): | |
if os.path.exists(gen_file_name): | ||
ColorPrint.print_info("generating") | ||
|
||
|
||
# check if root or example-specific boards.local.txt should be copied | ||
if COPY_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) | ||
|
||
|
||
tyeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if BUILD_WARN: | ||
if os.path.exists(gen_file_name): | ||
cmd = ['arduino-cli', 'compile', '--warnings', 'all', '--fqbn', fqbn, '-e', folderpath] | ||
|
@@ -428,6 +475,89 @@ def test_examples_in_folder(platform, folderpath): | |
success = 1 | ||
|
||
|
||
def install_boards_local_txt(core_fqbn, boards_local_txt): | ||
"""Copies boards.local.txt to the appropriate folder for the given core_fqbn. | ||
:param str core_fqbn: The first two segments of fully qualified board | ||
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: | ||
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')): | ||
data_dir = os.path.join(local_app_data_dir, '.arduino') | ||
|
||
# Get arduino-cli data directory | ||
import json | ||
if data_dir: | ||
config_output = subprocess.check_output(["arduino-cli", "config", "dump", "--format", "json", "--config-dir", data_dir]).decode() | ||
else: | ||
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: | ||
if os.path.exists(os.path.join(local_app_data_dir, 'Arduino')): | ||
data_dir = os.path.join(local_app_data_dir, 'Arduino') | ||
else: | ||
ColorPrint.print_warn("No valid data directory found, cannot copy boards.local.txt") | ||
return | ||
|
||
ColorPrint.print_info(f"Using data directory: {data_dir}") | ||
|
||
# Parse platform vendor and architecture from core_fqbn (e.g., "adafruit:samd") | ||
parts = core_fqbn.split(':') | ||
if len(parts) >= 2: | ||
vendor = parts[0] | ||
architecture = parts[1] | ||
else: | ||
vendor = core_fqbn | ||
architecture = vendor | ||
|
||
ColorPrint.print_info(f"Using vendor: {vendor}, architecture: {architecture}") | ||
|
||
# Construct base platform path, fall back to architecture if vendor rebadged BSP. | ||
platform_base = os.path.join(data_dir, "packages", vendor, "hardware", architecture) if \ | ||
os.path.exists(os.path.join(data_dir, "packages", vendor, "hardware", architecture)) else \ | ||
os.path.join(data_dir, "packages", architecture, "hardware", architecture) if \ | ||
os.path.exists(os.path.join(data_dir, "packages", architecture, "hardware", architecture)) else \ | ||
os.path.join(data_dir, "hardware", vendor, architecture) if \ | ||
os.path.exists(os.path.join(data_dir, "hardware", vendor, architecture)) else \ | ||
os.path.join(data_dir, "hardware", architecture, architecture) | ||
|
||
# Find the latest version directory | ||
if os.path.exists(platform_base): | ||
if os.path.exists(os.path.join(platform_base, "boards.txt")): | ||
shutil.copyfile(boards_local_txt, os.path.join(platform_base, "boards.local.txt")) | ||
ColorPrint.print_info(f"Copied boards.local.txt to {os.path.join(platform_base, 'boards.local.txt')}") | ||
else: | ||
versions = [d for d in os.listdir(platform_base) if os.path.isdir(os.path.join(platform_base, d))] | ||
ColorPrint.print_info(f"Found subdirectories for {platform_base}:\n {versions}") | ||
# Filter out non-version directories (e.g., 'tools', 'libraries') while supporting 1.0-dev 1.0.0-offline-mode.102 etc | ||
versions = [v for v in versions if re.match(r'^(v)?\d+\.\d+(\.\d+(-\w+)?)?(\.\d+)?$', v)] | ||
ColorPrint.print_info(f"Filtered versions: {versions}") | ||
if versions: | ||
# 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}") | ||
|
||
else: | ||
ColorPrint.print_warn(f"No version directories found in {platform_base}") | ||
else: | ||
ColorPrint.print_warn(f"Platform path {platform_base} does not exist") | ||
|
||
except Exception as e: | ||
ColorPrint.print_fail(f"Error injecting boards.local.txt for {core_fqbn}: {e}") | ||
|
||
|
||
def main(): | ||
# Test platforms | ||
platforms = [] | ||
|
@@ -451,8 +581,15 @@ def main(): | |
fqbn = ALL_PLATFORMS[platform][0] | ||
print('#'*80) | ||
ColorPrint.print_info("SWITCHING TO "+fqbn) | ||
install_platform(":".join(fqbn.split(':', 2)[0:2]), ALL_PLATFORMS[platform]) # take only first two elements | ||
core_fqbn = ":".join(fqbn.split(':', 2)[0:2]) # take only first two elements | ||
install_platform(core_fqbn, ALL_PLATFORMS[platform]) | ||
|
||
# Inject boards.local.txt if requested | ||
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") | ||
else: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.