From af8cf263658c1edd955130e7b02f5842906d18a9 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Sun, 8 Mar 2020 15:46:26 -1000 Subject: [PATCH] Added python build-all and build-machine scripts --- build-all.py | 39 ++++++++++++++++++++++++++++++++++++ build-machine.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 build-all.py create mode 100644 build-machine.py diff --git a/build-all.py b/build-all.py new file mode 100644 index 00000000..af19788d --- /dev/null +++ b/build-all.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python2 + +# Compile Grbl_ESP32 for each of the machines defined in Machines/ . +# Add-on files are built on top of a single base. +# This is useful for automated testing, to make sure you haven't broken something + +# The output is filtered so that the only lines you see are a single +# success or failure line for each build, plus any preceding lines that +# contain the word "error". If you need to see everything, for example to +# see the details of an errored build, include -v on the command line. + +from __future__ import print_function +import os, subprocess, sys + +env = dict(os.environ) +verbose = '-v' in sys.argv + +def buildMachine(baseName, addName=None): + displayName = baseName + flags = '-DMACHINE_FILENAME=' + baseName + if addName: + displayName += ' + ' + addName + flags += ' -DMACHINE_FILENAME2=' + addName + print('Building machine ' + displayName) + env['PLATFORMIO_BUILD_FLAGS'] = flags + app = subprocess.Popen(['platformio','run'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, env=env) + for line in app.stdout: + if verbose or "Took" in line or "error" in line.lower(): + print(line, end='') + print() + +adderBase = '3axis_v4.h' +for name in os.listdir('Grbl_Esp32/Machines'): + if name.startswith('add_'): + buildMachine(adderBase, name) + else: + buildMachine(name) + + diff --git a/build-machine.py b/build-machine.py new file mode 100644 index 00000000..7e7d6e62 --- /dev/null +++ b/build-machine.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python2 + +# Compile Grbl_ESP32 for the machine listed on the command line, as in +# ./build-machine.py 3xis_v4.h + +# Add-ons can be built by listing both the base name and the adder, as in +# ./build-machine.py 3axis_v4.h add_esc_spindle.h + +# -q suppresses most messages +# -u uploads the firmware to the target machine + +from __future__ import print_function +import os, subprocess, sys + +cmd=['platformio','run'] +verbose = '-v' in sys.argv or '-q' not in sys.argv +if '-v' in sys.argv: + sys.argv.remove('-v') +if '-q' in sys.argv: + sys.argv.remove('-q') +if '-u' in sys.argv: + sys.argv.remove('-u') + cmd.append('--target=upload') + +env = dict(os.environ) + +def buildMachine(baseName, addName=None): + displayName = baseName + flags = '-DMACHINE_FILENAME=' + baseName + if addName: + displayName += ' + ' + addName + flags += ' -DMACHINE_FILENAME2=' + addName + print('Building machine ' + displayName) + env['PLATFORMIO_BUILD_FLAGS'] = flags + if verbose: + subprocess.Popen(cmd, env=env).wait() + else: + app = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, env=env) + for line in app.stdout: + if "Took" in line or 'Uploading' in line or "error" in line.lower(): + print(line, end='') + +if len(sys.argv) == 2: + buildMachine(sys.argv[1], None) +elif len(sys.argv) == 3: + buildMachine(sys.argv[1], sys.argv[2]) +else: + print("Usage: ./build-machine.py [-q] [-u] machine_name.h [add_name.h]") + print(' Build for the given machine and optional add-on regardless of machine.h') + print(' -q suppresses most messages') + print(' -u uploads to the target after compilation') \ No newline at end of file