From 7e2a181d2bdc08129d11a976b424f8d87180f851 Mon Sep 17 00:00:00 2001 From: Guglielmo Date: Wed, 20 May 2020 16:21:47 +0200 Subject: [PATCH] update build system: set version from platformio.ini + rename firmware with version and platform + ignore another platformio dir --- .gitignore | 1 + platformio.ini | 44 +++++++++++++++++++++++++----------------- platformio_prebuild.py | 14 ++++++++++++++ src/mavesp8266.h | 5 +---- 4 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 platformio_prebuild.py diff --git a/.gitignore b/.gitignore index 3556316..743aa44 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ platformio.sublime* platformio.pro* tests research +.pio .vscode diff --git a/platformio.ini b/platformio.ini index 9c0fc1c..a4a4e87 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,33 +5,41 @@ # http://docs.platformio.org/en/latest/projectconf.html # -# A sign `#` at the beginning of the line indicates a comment -# Comment lines are ignored. - -# Simple and base environment -# [env:mybaseenv] -# platform = %INSTALLED_PLATFORM_NAME_HERE% -# framework = -# board = -# -# Automatic targets - enable auto-uploading -# targets = upload - # The upload speed below (921600) has worked fine for all modules I tested. If you have upload issues, # try reducing to 115200. -[env:esp12e] +# Set mavesp version + +[version] +major = 1 +minor = 2 +build = 2 + +# Generate version string (e.g "1.2.2") and flags + +[version_env] +version_string = ${version.major}.${version.minor}.${version.build} +version_flags = "-DMAVESP8266_VERSION_MINOR="${version.minor} "-DMAVESP8266_VERSION_MAJOR="${version.major} "-DMAVESP8266_VERSION_BUILD="${version.build} "-DVERSION_STRING="${version_env.version_string} + +# General settings +# - Set platform and framework +# - Generate revision, date and time flags +# - Run prebuild script to set firmware name + +[env] platform = espressif8266@1.8.0 framework = arduino +build_flags = !echo "-DPIO_SRC_REV="$(git rev-parse HEAD) "-DPIO_BUILD_DATE="$(date +%%Y-%%m-%%d) "-DPIO_BUILD_TIME="$(date +%%H:%%M:%%S) ${version_env.version_flags} +extra_scripts = pre:platformio_prebuild.py + +# Platform specific settings + +[env:esp12e] board = esp12e -build_flags = -Wl,-Tesp8266.flash.4m.ld +build_flags = ${env.build_flags} -Wl,-Tesp8266.flash.4m.ld [env:esp01_1m] -platform = espressif8266@1.8.0 -framework = arduino board = esp01_1m [env:esp01] -platform = espressif8266@1.8.0 -framework = arduino board = esp01 diff --git a/platformio_prebuild.py b/platformio_prebuild.py new file mode 100644 index 0000000..87f9ab4 --- /dev/null +++ b/platformio_prebuild.py @@ -0,0 +1,14 @@ +Import("env") + +# retrieve build flags +my_flags = env.ParseFlags(env['BUILD_FLAGS']) +defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")} + +version_string = defines.get("VERSION_STRING") # e.g. "1.2.2" +board_name = env["BOARD"] # e.g. "esp01m" + +# replace dots in version if linker can't find the path +#version_string = version_string.replace(".","_") + +# set board and version in firmware name +env.Replace(PROGNAME="mavesp-{}-{}".format(board_name, version_string)) \ No newline at end of file diff --git a/src/mavesp8266.h b/src/mavesp8266.h index 82e78e3..b29fe8c 100644 --- a/src/mavesp8266.h +++ b/src/mavesp8266.h @@ -62,10 +62,7 @@ class MavESP8266GCS; #define HEARTBEAT_TIMEOUT 10 * 1000 -//-- TODO: This needs to come from the build system -#define MAVESP8266_VERSION_MAJOR 1 -#define MAVESP8266_VERSION_MINOR 2 -#define MAVESP8266_VERSION_BUILD 2 +//-- The version is set from the build system (major, minor and build) #define MAVESP8266_VERSION ((MAVESP8266_VERSION_MAJOR << 24) & 0xFF00000) | ((MAVESP8266_VERSION_MINOR << 16) & 0x00FF0000) | (MAVESP8266_VERSION_BUILD & 0xFFFF) //-- Debug sent out to Serial1 (GPIO02), which is TX only (no RX).