forked from BeyondRobotix/mavesp8266
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplatformio_prebuild.py
44 lines (35 loc) · 1.67 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
33
34
35
36
37
38
39
40
41
42
43
44
import datetime
import subprocess
Import("env")
# get revivion from Git
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 +%%..." )
board_name = env["BOARD"]# e.g. "esp01m"
build_flags = env['BUILD_FLAGS']
rev_str = str(revision)
build_flags[0] = "!echo" +' "-DBOARD_NAME="' + board_name +' "-DPIO_SRC_REV="' + rev_str + ' "-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"
debug = defines.get("ENABLE_DEBUG")
pwlink_target = defines.get("PW_LINK")
# replace dots in version if linker can't find the path
version_string = version_string.replace(".","_")
#firmware_name = "mavesp-{}-{}".format(board_name, version_string)
# set board and version in firmware name
firmware_name = "mavespx2-{}-{}-DEBUG-{}".format(board_name, version_string, rev_str)
if debug == None :
firmware_name = "mavespx2-{}-{}".format(board_name, version_string)
if pwlink_target != None :
firmware_name = "mavespx2-{}-{}".format(pwlink_target, version_string)
build_flags[0] = build_flags[0] + " -DFW_NAME='\"{}.bin\"'".format(firmware_name)
env.Replace(PROGNAME=firmware_name)