From 781a291cd0678aa0e2f15bc0e756b84b2e74a091 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Wed, 1 Apr 2026 19:01:55 -0700 Subject: [PATCH] Add --environment/-e flag to select PlatformIO build environment --- README.md | 13 +++++++++++++ install.py | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2a8f9a6..58f1903 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,19 @@ From the root of this repository, run: python3 install.py ``` +By default this uses the `default` build environment. To use a different environment pass `-e`: + +```bash +python3 install.py -e slim +python3 install.py -e gh_release +``` + +| Environment | Description | +|-------------|-------------| +| `default` | Debug logging enabled, version from current git branch (recommended) | +| `gh_release` | Info logging only, version hardcoded to release tag | +| `slim` | No serial logging, smallest binary size | + The installer will: 1. Clone the CrossPoint Reader source repository diff --git a/install.py b/install.py index 5c6f258..c13c92b 100644 --- a/install.py +++ b/install.py @@ -6,11 +6,18 @@ import shutil import subprocess import glob import importlib.util +import argparse -REPO_URL = "https://github.com/crosspoint-reader/crosspoint-reader.git" -REPO_DIR = "crosspoint-reader" +REPO_URL = "https://github.com/crosspoint-reader/crosspoint-reader.git" +REPO_DIR = "crosspoint-reader" PLUGINS_DIR = "plugins" +ENVIRONMENTS = { + "default": "Debug logging enabled, version from current git branch (recommended)", + "gh_release": "Info logging only, version hardcoded to release tag", + "slim": "No serial logging, smallest binary size", +} + def run(cmd, cwd=None, check=True): print(f" $ {cmd}") @@ -176,20 +183,38 @@ def prompt_for_upload_port(): print(" Please enter a valid port name.") -def build_and_flash(): - print("\nBuilding firmware with PlatformIO...") - run("pio run --environment default", cwd=REPO_DIR) +def build_and_flash(environment: str): + print(f"\nBuilding firmware with PlatformIO (environment: {environment})...") + run(f"pio run --environment {environment}", cwd=REPO_DIR) port = prompt_for_upload_port() print(f"\n Flashing to {port}...") run( - f"pio run --target upload --environment default --upload-port {port}", + f"pio run --target upload --environment {environment} --upload-port {port}", cwd=REPO_DIR, ) +def parse_args(): + parser = argparse.ArgumentParser( + description="xteink Plugin Installer", + formatter_class=argparse.RawTextHelpFormatter, + ) + env_help = "\n".join(f" {name}: {desc}" for name, desc in ENVIRONMENTS.items()) + parser.add_argument( + "-e", "--environment", + default="default", + choices=ENVIRONMENTS.keys(), + metavar="ENV", + help=f"PlatformIO build environment (default: default)\n{env_help}", + ) + return parser.parse_args() + + def main(): + args = parse_args() + print("=" * 60) print(" xteink Plugin Installer") print("=" * 60) @@ -199,6 +224,9 @@ def main(): print(" no responsibility for any damage that may occur to your") print(" device as a result of using this installer.") print() + print(f" Environment : {args.environment}") + print(f" {ENVIRONMENTS[args.environment]}") + print() answer = input(" Do you wish to proceed? [Y/n]: ").strip().lower() if answer not in ("", "y", "yes"): print(" Aborted.") @@ -206,8 +234,9 @@ def main(): print() clone_repo() apply_plugins() - build_and_flash() + build_and_flash(args.environment) print("\nDone.") + if __name__ == "__main__": main()