22
22
23
23
Import ("env" )
24
24
25
+ board = env .BoardConfig ()
25
26
26
27
#
27
28
# Embedded files helpers
28
29
#
29
30
30
31
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
38
42
39
- with cd (env .subst ("$PROJECT_DIR" )):
40
43
value = define [1 ]
44
+ if not isinstance (define , tuple ):
45
+ print ("Warning! %s macro cannot be empty!" % files_define )
46
+ return []
47
+
41
48
if not isinstance (value , str ):
42
49
print ("Warning! %s macro must contain "
43
- "a list of files separated by ':'" % files_type )
50
+ "a list of files separated by ':'" % files_define )
44
51
return []
45
52
46
- result = []
47
53
for f in value .split (':' ):
48
- if not isfile (f ):
49
- print ("Warning! Could not find file %s" % f )
54
+ if not f :
50
55
continue
51
- result .append (join ("$PROJECT_DIR" , f ))
56
+ files .append (join ("$PROJECT_DIR" , f ))
52
57
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
54
63
55
64
56
65
def remove_config_define (cppdefines , files_type ):
@@ -82,7 +91,7 @@ def embed_files(files, files_type):
82
91
filename = basename (f ) + ".txt.o"
83
92
file_target = env .TxtToBin (join ("$BUILD_DIR" , filename ), f )
84
93
env .Depends ("$PIOMAINPROG" , file_target )
85
- if files_type == "COMPONENT_EMBED_TXTFILES " :
94
+ if files_type == "embed_txtfiles " :
86
95
env .AddPreAction (file_target , prepare_file )
87
96
env .AddPostAction (file_target , revert_original_file )
88
97
env .Append (PIOBUILDFILES = [env .File (join ("$BUILD_DIR" , filename ))])
@@ -103,9 +112,11 @@ def embed_files(files, files_type):
103
112
)
104
113
105
114
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 :
108
118
continue
119
+
109
120
files = extract_files (flags , files_type )
110
121
embed_files (files , files_type )
111
122
remove_config_define (flags , files_type )
0 commit comments