33
33
from tools .toolchains import TOOLCHAIN_CLASSES
34
34
from jinja2 import FileSystemLoader
35
35
from jinja2 .environment import Environment
36
-
36
+ from tools . config import Config
37
37
38
38
def prep_report (report , target_name , toolchain_name , id_name ):
39
39
# Setup report keys
@@ -76,21 +76,46 @@ def add_result_to_report(report, result):
76
76
result_wrap = { 0 : result }
77
77
report [target ][toolchain ][id_name ].append (result_wrap )
78
78
79
+ def get_config (src_path , target , toolchain_name ):
80
+ # Convert src_path to a list if needed
81
+ src_paths = [src_path ] if type (src_path ) != ListType else src_path
82
+ # We need to remove all paths which are repeated to avoid
83
+ # multiple compilations and linking with the same objects
84
+ src_paths = [src_paths [0 ]] + list (set (src_paths [1 :]))
85
+
86
+ # Create configuration object
87
+ config = Config (target , src_paths )
88
+
89
+ # If the 'target' argument is a string, convert it to a target instance
90
+ if isinstance (target , str ):
91
+ try :
92
+ target = TARGET_MAP [target ]
93
+ except KeyError :
94
+ raise KeyError ("Target '%s' not found" % target )
95
+
96
+ # Toolchain instance
97
+ try :
98
+ toolchain = TOOLCHAIN_CLASSES [toolchain_name ](target , options = None , notify = None , macros = None , silent = True , extra_verbose = False )
99
+ except KeyError as e :
100
+ raise KeyError ("Toolchain %s not supported" % toolchain_name )
101
+
102
+ # Scan src_path for config files
103
+ resources = toolchain .scan_resources (src_paths [0 ])
104
+ for path in src_paths [1 :]:
105
+ resources .add (toolchain .scan_resources (path ))
106
+
107
+ config .add_config_files (resources .json_files )
108
+ return config .get_config_data ()
109
+
79
110
def build_project (src_path , build_path , target , toolchain_name ,
80
111
libraries_paths = None , options = None , linker_script = None ,
81
112
clean = False , notify = None , verbose = False , name = None , macros = None , inc_dirs = None ,
82
- jobs = 1 , silent = False , report = None , properties = None , project_id = None , project_description = None , extra_verbose = False ):
113
+ jobs = 1 , silent = False , report = None , properties = None , project_id = None , project_description = None ,
114
+ extra_verbose = False , config = None ):
83
115
""" This function builds project. Project can be for example one test / UT
84
116
"""
85
- # Toolchain instance
86
- try :
87
- toolchain = TOOLCHAIN_CLASSES [toolchain_name ](target , options , notify , macros , silent , extra_verbose = extra_verbose )
88
- except KeyError as e :
89
- raise KeyError ("Toolchain %s not supported" % toolchain_name )
90
117
91
- toolchain .VERBOSE = verbose
92
- toolchain .jobs = jobs
93
- toolchain .build_all = clean
118
+ # Convert src_path to a list if needed
94
119
src_paths = [src_path ] if type (src_path ) != ListType else src_path
95
120
96
121
# We need to remove all paths which are repeated to avoid
@@ -100,6 +125,26 @@ def build_project(src_path, build_path, target, toolchain_name,
100
125
abs_path = abspath (first_src_path )
101
126
project_name = basename (normpath (abs_path ))
102
127
128
+ # If the configuration object was not yet created, create it now
129
+ config = config or Config (target , src_paths )
130
+
131
+ # If the 'target' argument is a string, convert it to a target instance
132
+ if isinstance (target , str ):
133
+ try :
134
+ target = TARGET_MAP [target ]
135
+ except KeyError :
136
+ raise KeyError ("Target '%s' not found" % target )
137
+
138
+ # Toolchain instance
139
+ try :
140
+ toolchain = TOOLCHAIN_CLASSES [toolchain_name ](target , options , notify , macros , silent , extra_verbose = extra_verbose )
141
+ except KeyError as e :
142
+ raise KeyError ("Toolchain %s not supported" % toolchain_name )
143
+
144
+ toolchain .VERBOSE = verbose
145
+ toolchain .jobs = jobs
146
+ toolchain .build_all = clean
147
+
103
148
if name is None :
104
149
# We will use default project name based on project folder name
105
150
name = project_name
@@ -148,13 +193,18 @@ def build_project(src_path, build_path, target, toolchain_name,
148
193
resources .inc_dirs .extend (inc_dirs )
149
194
else :
150
195
resources .inc_dirs .append (inc_dirs )
196
+
197
+ # Update the configuration with any .json files found while scanning
198
+ config .add_config_files (resources .json_files )
199
+ # And add the configuration macros to the toolchain
200
+ toolchain .add_macros (config .get_config_data_macros ())
201
+
151
202
# Compile Sources
152
203
for path in src_paths :
153
204
src = toolchain .scan_resources (path )
154
205
objects = toolchain .compile_sources (src , build_path , resources .inc_dirs )
155
206
resources .objects .extend (objects )
156
207
157
-
158
208
# Link Program
159
209
res , needed_update = toolchain .link_program (resources , build_path , name )
160
210
@@ -190,7 +240,6 @@ def build_project(src_path, build_path, target, toolchain_name,
190
240
# Let Exception propagate
191
241
raise e
192
242
193
-
194
243
def build_library (src_paths , build_path , target , toolchain_name ,
195
244
dependencies_paths = None , options = None , name = None , clean = False , archive = True ,
196
245
notify = None , verbose = False , macros = None , inc_dirs = None , inc_dirs_ext = None ,
@@ -279,13 +328,19 @@ def build_library(src_paths, build_path, target, toolchain_name,
279
328
else :
280
329
tmp_path = build_path
281
330
331
+ # Handle configuration
332
+ config = Config (target )
333
+
282
334
# Copy headers, objects and static libraries
283
335
for resource in resources :
284
336
toolchain .copy_files (resource .headers , build_path , rel_path = resource .base_path )
285
337
toolchain .copy_files (resource .objects , build_path , rel_path = resource .base_path )
286
338
toolchain .copy_files (resource .libraries , build_path , rel_path = resource .base_path )
287
339
if resource .linker_script :
288
340
toolchain .copy_files (resource .linker_script , build_path , rel_path = resource .base_path )
341
+ config .add_config_files (resource .json_files )
342
+
343
+ toolchain .add_macros (config .get_config_data_macros ())
289
344
290
345
# Compile Sources
291
346
objects = []
0 commit comments