forked from emsesp/EMS-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename_fw.py
67 lines (49 loc) · 2.04 KB
/
rename_fw.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import shutil
import re
import os
Import("env")
OUTPUT_DIR = "build{}".format(os.path.sep)
def bin_copy(source, target, env):
# get the build info
bag = {}
exprs = [(re.compile(r'^#define EMSESP_APP_VERSION\s+"(\S+)"'), 'app_version')]
with open('./src/version.h', 'r') as f:
for l in f.readlines():
for expr, var in exprs:
m = expr.match(l)
if m and len(m.groups()) > 0:
bag[var] = m.group(1)
app_version = bag.get('app_version')
platform = "ESP32"
# flash_size = env["PIOENV"].split('_')[1]
# print(env.Dump())
# my_flags = env.ParseFlags(env['BUILD_FLAGS'])
# defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")}
# print(my_flags)
# print((my_flags.get("CPPDEFINES"))
# alternatively take platform from the pio target
# platform = str(target[0]).split(os.path.sep)[2]
chip_target = env.get('PIOENV').upper()
print("app version: "+app_version)
print("chip_target: "+chip_target)
print("platform: "+platform)
# print("flash size: "+flash_size)
# convert . to _ so Windows doesn't complain
variant = "EMS-ESP-" + app_version.replace(".", "_") + "-" + chip_target
# variant = "EMS-ESP-" + app_version.replace(".", "_") + "-" + platform + "_" + flash_size
# check if output directories exist and create if necessary
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
for d in ['firmware']:
if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
os.mkdir("{}{}".format(OUTPUT_DIR, d))
# create string with location and file names based on variant
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
# check if new target files exist and remove if necessary
for f in [bin_file]:
if os.path.isfile(f):
os.remove(f)
print("Renaming file to "+bin_file)
# copy firmware.bin to firmware/<variant>.bin
shutil.copy(str(target[0]), bin_file)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_copy])