Skip to content

Commit 11ee6b3

Browse files
committed
Allow specifying embeddable files in a special platformio.ini section
1 parent 31f8624 commit 11ee6b3

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

builder/frameworks/_embed_files.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,44 @@
2222

2323
Import("env")
2424

25+
board = env.BoardConfig()
2526

2627
#
2728
# Embedded files helpers
2829
#
2930

3031
def extract_files(cppdefines, files_type):
31-
for define in cppdefines:
32-
if files_type not in define:
33-
continue
34-
35-
if not isinstance(define, tuple):
36-
print("Warning! %s macro cannot be empty!" % files_type)
37-
return []
32+
files = []
33+
if "build." + files_type in board:
34+
files.extend(
35+
[join("$PROJECT_DIR", f) for f in board.get(
36+
"build." + files_type, "").split() if f])
37+
else:
38+
files_define = "COMPONENT_" + files_type.upper()
39+
for define in cppdefines:
40+
if files_define not in define:
41+
continue
3842

39-
with cd(env.subst("$PROJECT_DIR")):
4043
value = define[1]
44+
if not isinstance(define, tuple):
45+
print("Warning! %s macro cannot be empty!" % files_define)
46+
return []
47+
4148
if not isinstance(value, str):
4249
print("Warning! %s macro must contain "
43-
"a list of files separated by ':'" % files_type)
50+
"a list of files separated by ':'" % files_define)
4451
return []
4552

46-
result = []
4753
for f in value.split(':'):
48-
if not isfile(f):
49-
print("Warning! Could not find file %s" % f)
54+
if not f:
5055
continue
51-
result.append(join("$PROJECT_DIR", f))
56+
files.append(join("$PROJECT_DIR", f))
5257

53-
return result
58+
for f in files:
59+
if not isfile(env.subst(f)):
60+
print("Warning! Could not find file \"%s\"" % basename(f))
61+
62+
return files
5463

5564

5665
def remove_config_define(cppdefines, files_type):
@@ -82,7 +91,7 @@ def embed_files(files, files_type):
8291
filename = basename(f) + ".txt.o"
8392
file_target = env.TxtToBin(join("$BUILD_DIR", filename), f)
8493
env.Depends("$PIOMAINPROG", file_target)
85-
if files_type == "COMPONENT_EMBED_TXTFILES":
94+
if files_type == "embed_txtfiles":
8695
env.AddPreAction(file_target, prepare_file)
8796
env.AddPostAction(file_target, revert_original_file)
8897
env.Append(PIOBUILDFILES=[env.File(join("$BUILD_DIR", filename))])
@@ -103,9 +112,11 @@ def embed_files(files, files_type):
103112
)
104113

105114
flags = env.get("CPPDEFINES")
106-
for files_type in ("COMPONENT_EMBED_TXTFILES", "COMPONENT_EMBED_FILES"):
107-
if files_type not in env.Flatten(flags):
115+
for files_type in ("embed_txtfiles", "embed_files"):
116+
if "COMPONENT_" + files_type.upper() not in env.Flatten(
117+
flags) and "build." + files_type not in board:
108118
continue
119+
109120
files = extract_files(flags, files_type)
110121
embed_files(files, files_type)
111122
remove_config_define(flags, files_type)

0 commit comments

Comments
 (0)