Skip to content

Commit

Permalink
Add helper script for building/installing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoles committed Dec 31, 2022
1 parent 36dbc4d commit 60cf3ee
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
# Helper script for building/installing all examples.

import argparse
import logging
import os
from pathlib import Path, PurePosixPath
from subprocess import run

FLIPPERZERO_FIRMWARE = Path(os.environ.get('FLIPPERZERO_FIRMWARE', '../../flipperzero-firmware'))
PYTHON = 'python'
STORAGE_SCRIPT = FLIPPERZERO_FIRMWARE / 'scripts' / 'storage.py'
INSTALL_PATH = PurePosixPath('/ext/apps/Examples')


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--install', action='store_true', help='Copy built projects to device')

return parser.parse_args()


def main():
args = parse_args()

logging.basicConfig(level=logging.INFO)

for path in Path.cwd().iterdir():
if not path.is_dir() or not path.joinpath('Cargo.toml').exists():
continue

logging.info('Building %s', path.name)
run(['cargo', 'build', '--release'], cwd=path, check=True)

if args.install:
# Assume that the binary has the name as the
binary = path / 'target' / 'thumbv7em-none-eabihf' / 'release' / path.name
target = INSTALL_PATH / f'{path.name}.fap'

logging.info('Copying %s to %s', binary, target)
run([PYTHON, STORAGE_SCRIPT, 'send', os.fspath(binary), os.fspath(target)], check=True)


if __name__ == '__main__':
main()

0 comments on commit 60cf3ee

Please sign in to comment.