forked from BeyondRobotix/mavesp8266
-
Notifications
You must be signed in to change notification settings - Fork 2
/
platformio_prebuild.py
32 lines (24 loc) · 1.14 KB
/
platformio_prebuild.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import datetime
import subprocess
Import("env")
revision = (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.strip()
.decode("utf-8")
)
#get current date and time
curr_date = datetime.datetime.now()
date_str = f"{curr_date.year}-{curr_date.month:02}-{curr_date.day:02}"
time_str = f"{curr_date.hour:02}:{curr_date.minute:02}:{curr_date.second:02}"
# add revision and date/time as build informations to the existing build flags (workaround to fix compilation issue with "date +%%..." )
build_flags = env['BUILD_FLAGS']
build_flags[0] = "!echo" + ' "-DPIO_SRC_REV="' + str(revision) + ' "-DPIO_BUILD_DATE="' + date_str + ' "-DPIO_BUILD_TIME="' + time_str + " " + build_flags[0]
# 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))