Add --environment/-e flag to select PlatformIO build environment
This commit is contained in:
1 parent
e760fdc653
commit
781a291cd0
2 files changed
+49
-7
No files matched your search
@@ -53,6 +53,19 @@ From the root of this repository, run:
|
|||||||
python3 install.py
|
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:
|
The installer will:
|
||||||
|
|
||||||
1. Clone the CrossPoint Reader source repository
|
1. Clone the CrossPoint Reader source repository
|
||||||
|
|||||||
+36
-7
@@ -6,11 +6,18 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import glob
|
import glob
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import argparse
|
||||||
|
|
||||||
REPO_URL = "https://github.com/crosspoint-reader/crosspoint-reader.git"
|
REPO_URL = "https://github.com/crosspoint-reader/crosspoint-reader.git"
|
||||||
REPO_DIR = "crosspoint-reader"
|
REPO_DIR = "crosspoint-reader"
|
||||||
PLUGINS_DIR = "plugins"
|
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):
|
def run(cmd, cwd=None, check=True):
|
||||||
print(f" $ {cmd}")
|
print(f" $ {cmd}")
|
||||||
@@ -176,20 +183,38 @@ def prompt_for_upload_port():
|
|||||||
print(" Please enter a valid port name.")
|
print(" Please enter a valid port name.")
|
||||||
|
|
||||||
|
|
||||||
def build_and_flash():
|
def build_and_flash(environment: str):
|
||||||
print("\nBuilding firmware with PlatformIO...")
|
print(f"\nBuilding firmware with PlatformIO (environment: {environment})...")
|
||||||
run("pio run --environment default", cwd=REPO_DIR)
|
run(f"pio run --environment {environment}", cwd=REPO_DIR)
|
||||||
|
|
||||||
port = prompt_for_upload_port()
|
port = prompt_for_upload_port()
|
||||||
|
|
||||||
print(f"\n Flashing to {port}...")
|
print(f"\n Flashing to {port}...")
|
||||||
run(
|
run(
|
||||||
f"pio run --target upload --environment default --upload-port {port}",
|
f"pio run --target upload --environment {environment} --upload-port {port}",
|
||||||
cwd=REPO_DIR,
|
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():
|
def main():
|
||||||
|
args = parse_args()
|
||||||
|
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print(" xteink Plugin Installer")
|
print(" xteink Plugin Installer")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
@@ -199,6 +224,9 @@ def main():
|
|||||||
print(" no responsibility for any damage that may occur to your")
|
print(" no responsibility for any damage that may occur to your")
|
||||||
print(" device as a result of using this installer.")
|
print(" device as a result of using this installer.")
|
||||||
print()
|
print()
|
||||||
|
print(f" Environment : {args.environment}")
|
||||||
|
print(f" {ENVIRONMENTS[args.environment]}")
|
||||||
|
print()
|
||||||
answer = input(" Do you wish to proceed? [Y/n]: ").strip().lower()
|
answer = input(" Do you wish to proceed? [Y/n]: ").strip().lower()
|
||||||
if answer not in ("", "y", "yes"):
|
if answer not in ("", "y", "yes"):
|
||||||
print(" Aborted.")
|
print(" Aborted.")
|
||||||
@@ -206,8 +234,9 @@ def main():
|
|||||||
print()
|
print()
|
||||||
clone_repo()
|
clone_repo()
|
||||||
apply_plugins()
|
apply_plugins()
|
||||||
build_and_flash()
|
build_and_flash(args.environment)
|
||||||
print("\nDone.")
|
print("\nDone.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in new issue
Block a user