Skip to content

Commit d88852d

Browse files
committed
Replace -o with profiles
1 parent df32eff commit d88852d

File tree

15 files changed

+176
-249
lines changed

15 files changed

+176
-249
lines changed

tools/build.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from tools.toolchains import mbedToolchain
3232
from tools.targets import TARGET_NAMES, TARGET_MAP
3333
from tools.options import get_default_options_parser
34+
from tools.options import extract_profile
3435
from tools.build_api import build_library, build_mbed_libs, build_lib
3536
from tools.build_api import mcu_toolchain_matrix
3637
from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
@@ -222,13 +223,20 @@
222223
try:
223224
mcu = TARGET_MAP[target]
224225
# CMSIS and MBED libs analysis
225-
static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs)
226+
profile = extract_profile(parser, options, toolchain)
227+
static_analysis_scan(
228+
mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
229+
verbose=options.verbose, jobs=options.jobs,
230+
build_profile=profile)
226231
for lib_id in libraries:
227232
# Static check for library
228-
static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
229-
options=options.options,
230-
extra_verbose=options.extra_verbose_notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean,
231-
macros=options.macros)
233+
static_analysis_scan_lib(
234+
lib_id, mcu, toolchain, CPPCHECK_CMD,
235+
CPPCHECK_MSG_FORMAT,
236+
extra_verbose=options.extra_verbose_notify,
237+
verbose=options.verbose, jobs=options.jobs,
238+
clean=options.clean, macros=options.macros,
239+
build_profile=profile)
232240
pass
233241
except Exception, e:
234242
if options.verbose:
@@ -248,36 +256,37 @@
248256
else:
249257
try:
250258
mcu = TARGET_MAP[target]
259+
profile = extract_profile(parser, options, toolchain)
251260
if options.source_dir:
252261
lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
253-
options=options.options,
254262
extra_verbose=options.extra_verbose_notify,
255263
verbose=options.verbose,
256264
silent=options.silent,
257265
jobs=options.jobs,
258266
clean=options.clean,
259267
archive=(not options.no_archive),
260268
macros=options.macros,
261-
name=options.artifact_name)
269+
name=options.artifact_name,
270+
build_profile=profile)
262271
else:
263272
lib_build_res = build_mbed_libs(mcu, toolchain,
264-
options=options.options,
265273
extra_verbose=options.extra_verbose_notify,
266274
verbose=options.verbose,
267275
silent=options.silent,
268276
jobs=options.jobs,
269277
clean=options.clean,
270-
macros=options.macros)
278+
macros=options.macros,
279+
build_profile=profile)
271280

272281
for lib_id in libraries:
273282
build_lib(lib_id, mcu, toolchain,
274-
options=options.options,
275283
extra_verbose=options.extra_verbose_notify,
276284
verbose=options.verbose,
277285
silent=options.silent,
278286
clean=options.clean,
279287
macros=options.macros,
280-
jobs=options.jobs)
288+
jobs=options.jobs,
289+
build_profile=profile)
281290
if lib_build_res:
282291
successes.append(tt_id)
283292
else:

tools/build_api.py

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def get_mbed_official_release(version):
274274

275275

276276
def prepare_toolchain(src_paths, target, toolchain_name,
277-
macros=None, options=None, clean=False, jobs=1,
277+
macros=None, clean=False, jobs=1,
278278
notify=None, silent=False, verbose=False,
279279
extra_verbose=False, config=None,
280280
app_config=None, build_profile=None):
@@ -287,7 +287,6 @@ def prepare_toolchain(src_paths, target, toolchain_name,
287287
288288
Keyword arguments:
289289
macros - additional macros
290-
options - general compiler options like debug-symbols or small-build
291290
clean - Rebuild everything if True
292291
jobs - how many compilers we can run at once
293292
notify - Notify function for logs
@@ -296,6 +295,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
296295
extra_verbose - even more output!
297296
config - a Config object to use instead of creating one
298297
app_config - location of a chosen mbed_app.json file
298+
build_profile - a dict of flags that will be passed to the compiler
299299
"""
300300

301301
# We need to remove all paths which are repeated to avoid
@@ -309,7 +309,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
309309
# Toolchain instance
310310
try:
311311
toolchain = TOOLCHAIN_CLASSES[toolchain_name](
312-
target, options, notify, macros, silent,
312+
target, notify, macros, silent,
313313
extra_verbose=extra_verbose, build_profile=build_profile)
314314
except KeyError:
315315
raise KeyError("Toolchain %s not supported" % toolchain_name)
@@ -361,7 +361,7 @@ def scan_resources(src_paths, toolchain, dependencies_paths=None,
361361
return resources
362362

363363
def build_project(src_paths, build_path, target, toolchain_name,
364-
libraries_paths=None, options=None, linker_script=None,
364+
libraries_paths=None, linker_script=None,
365365
clean=False, notify=None, verbose=False, name=None,
366366
macros=None, inc_dirs=None, jobs=1, silent=False,
367367
report=None, properties=None, project_id=None,
@@ -378,7 +378,6 @@ def build_project(src_paths, build_path, target, toolchain_name,
378378
379379
Keyword arguments:
380380
libraries_paths - The location of libraries to include when linking
381-
options - general compiler options like debug-symbols or small-build
382381
linker_script - the file that drives the linker to do it's job
383382
clean - Rebuild everything if True
384383
notify - Notify function for logs
@@ -395,6 +394,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
395394
extra_verbose - even more output!
396395
config - a Config object to use instead of creating one
397396
app_config - location of a chosen mbed_app.json file
397+
build_profile - a dict of flags that will be passed to the compiler
398398
"""
399399

400400
# Convert src_path to a list if needed
@@ -411,8 +411,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
411411

412412
# Pass all params to the unified prepare_toolchain()
413413
toolchain = prepare_toolchain(
414-
src_paths, target, toolchain_name, macros=macros, options=options,
415-
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
414+
src_paths, target, toolchain_name, macros=macros, clean=clean,
415+
jobs=jobs, notify=notify, silent=silent, verbose=verbose,
416416
extra_verbose=extra_verbose, config=config, app_config=app_config,
417417
build_profile=build_profile)
418418

@@ -484,11 +484,12 @@ def build_project(src_paths, build_path, target, toolchain_name,
484484
raise
485485

486486
def build_library(src_paths, build_path, target, toolchain_name,
487-
dependencies_paths=None, options=None, name=None, clean=False,
487+
dependencies_paths=None, name=None, clean=False,
488488
archive=True, notify=None, verbose=False, macros=None,
489489
inc_dirs=None, jobs=1, silent=False, report=None,
490490
properties=None, extra_verbose=False, project_id=None,
491-
remove_config_header_file=False, app_config=None):
491+
remove_config_header_file=False, app_config=None,
492+
build_profile=None):
492493
""" Build a library
493494
494495
Positional arguments:
@@ -500,7 +501,6 @@ def build_library(src_paths, build_path, target, toolchain_name,
500501
501502
Keyword arguments:
502503
dependencies_paths - The location of libraries to include when linking
503-
options - general compiler options like debug-symbols or small-build
504504
name - the name of the library
505505
clean - Rebuild everything if True
506506
archive - whether the library will create an archive file
@@ -516,6 +516,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
516516
project_id - the name that goes in the report
517517
remove_config_header_file - delete config header file when done building
518518
app_config - location of a chosen mbed_app.json file
519+
build_profile - a dict of flags that will be passed to the compiler
519520
"""
520521

521522
# Convert src_path to a list if needed
@@ -537,9 +538,10 @@ def build_library(src_paths, build_path, target, toolchain_name,
537538

538539
# Pass all params to the unified prepare_toolchain()
539540
toolchain = prepare_toolchain(
540-
src_paths, target, toolchain_name, macros=macros, options=options,
541-
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
542-
extra_verbose=extra_verbose, app_config=app_config)
541+
src_paths, target, toolchain_name, macros=macros, clean=clean,
542+
jobs=jobs, notify=notify, silent=silent, verbose=verbose,
543+
extra_verbose=extra_verbose, app_config=app_config,
544+
build_profile=build_profile)
543545

544546
# The first path will give the name to the library
545547
if name is None:
@@ -640,9 +642,10 @@ def build_library(src_paths, build_path, target, toolchain_name,
640642
### Legacy methods ###
641643
######################
642644

643-
def build_lib(lib_id, target, toolchain_name, options=None, verbose=False,
645+
def build_lib(lib_id, target, toolchain_name, verbose=False,
644646
clean=False, macros=None, notify=None, jobs=1, silent=False,
645-
report=None, properties=None, extra_verbose=False):
647+
report=None, properties=None, extra_verbose=False,
648+
build_profile=None):
646649
""" Legacy method for building mbed libraries
647650
648651
Positional arguments:
@@ -651,7 +654,6 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False,
651654
toolchain_name - the name of the build tools
652655
653656
Keyword arguments:
654-
options - general compiler options like debug-symbols or small-build
655657
clean - Rebuild everything if True
656658
verbose - Write the actual tools command lines used if True
657659
macros - additional macros
@@ -661,6 +663,7 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False,
661663
report - a dict where a result may be appended
662664
properties - UUUUHHHHH beats me
663665
extra_verbose - even more output!
666+
build_profile - a dict of flags that will be passed to the compiler
664667
"""
665668
lib = Library(lib_id)
666669
if not lib.is_supported(target, toolchain_name):
@@ -716,8 +719,8 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False,
716719
try:
717720
# Toolchain instance
718721
toolchain = TOOLCHAIN_CLASSES[toolchain_name](
719-
target, options, macros=macros, notify=notify, silent=silent,
720-
extra_verbose=extra_verbose)
722+
target, macros=macros, notify=notify, silent=silent,
723+
extra_verbose=extra_verbose, build_profile=build_profile)
721724
toolchain.VERBOSE = verbose
722725
toolchain.jobs = jobs
723726
toolchain.build_all = clean
@@ -805,9 +808,10 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False,
805808

806809
# We do have unique legacy conventions about how we build and package the mbed
807810
# library
808-
def build_mbed_libs(target, toolchain_name, options=None, verbose=False,
811+
def build_mbed_libs(target, toolchain_name, verbose=False,
809812
clean=False, macros=None, notify=None, jobs=1, silent=False,
810-
report=None, properties=None, extra_verbose=False):
813+
report=None, properties=None, extra_verbose=False,
814+
build_profile=None):
811815
""" Function returns True is library was built and false if building was
812816
skipped
813817
@@ -816,7 +820,6 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False,
816820
toolchain_name - the name of the build tools
817821
818822
Keyword arguments:
819-
options - general compiler options like debug-symbols or small-build
820823
verbose - Write the actual tools command lines used if True
821824
clean - Rebuild everything if True
822825
macros - additional macros
@@ -826,6 +829,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False,
826829
report - a dict where a result may be appended
827830
properties - UUUUHHHHH beats me
828831
extra_verbose - even more output!
832+
build_profile - a dict of flags that will be passed to the compiler
829833
"""
830834

831835
if report != None:
@@ -860,8 +864,8 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False,
860864
try:
861865
# Toolchain
862866
toolchain = TOOLCHAIN_CLASSES[toolchain_name](
863-
target, options, macros=macros, notify=notify, silent=silent,
864-
extra_verbose=extra_verbose)
867+
target, macros=macros, notify=notify, silent=silent,
868+
extra_verbose=extra_verbose, build_profile=build_profile)
865869
toolchain.VERBOSE = verbose
866870
toolchain.jobs = jobs
867871
toolchain.build_all = clean
@@ -1097,9 +1101,9 @@ def get_target_supported_toolchains(target):
10971101

10981102

10991103
def static_analysis_scan(target, toolchain_name, cppcheck_cmd,
1100-
cppcheck_msg_format, options=None, verbose=False,
1104+
cppcheck_msg_format, verbose=False,
11011105
clean=False, macros=None, notify=None, jobs=1,
1102-
extra_verbose=False):
1106+
extra_verbose=False, build_profile=None):
11031107
"""Perform static analysis on a target and toolchain combination
11041108
11051109
Positional arguments:
@@ -1109,18 +1113,19 @@ def static_analysis_scan(target, toolchain_name, cppcheck_cmd,
11091113
cppcheck_msg_format - the format of the check messages
11101114
11111115
Keyword arguments:
1112-
options - things like debug-symbols, or small-build, etc.
11131116
verbose - more printing!
11141117
clean - start from a clean slate
11151118
macros - extra macros to compile with
11161119
notify - the notification event handling function
11171120
jobs - number of commands to run at once
11181121
extra_verbose - even moar printing
1122+
build_profile - a dict of flags that will be passed to the compiler
11191123
"""
11201124
# Toolchain
1121-
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options,
1122-
macros=macros, notify=notify,
1123-
extra_verbose=extra_verbose)
1125+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, macros=macros,
1126+
notify=notify,
1127+
extra_verbose=extra_verbose,
1128+
build_profile=build_profile)
11241129
toolchain.VERBOSE = verbose
11251130
toolchain.jobs = jobs
11261131
toolchain.build_all = clean
@@ -1242,30 +1247,30 @@ def static_analysis_scan(target, toolchain_name, cppcheck_cmd,
12421247

12431248

12441249
def static_analysis_scan_lib(lib_id, target, toolchain, cppcheck_cmd,
1245-
cppcheck_msg_format, options=None, verbose=False,
1250+
cppcheck_msg_format, verbose=False,
12461251
clean=False, macros=None, notify=None, jobs=1,
1247-
extra_verbose=False):
1252+
extra_verbose=False, build_profile=None):
12481253
"""Perform static analysis on a library as if it were to be compiled for a
12491254
particular target and toolchain combination
12501255
"""
12511256
lib = Library(lib_id)
12521257
if lib.is_supported(target, toolchain):
12531258
static_analysis_scan_library(
12541259
lib.source_dir, lib.build_dir, target, toolchain, cppcheck_cmd,
1255-
cppcheck_msg_format, lib.dependencies, options, verbose=verbose,
1260+
cppcheck_msg_format, lib.dependencies, verbose=verbose,
12561261
clean=clean, macros=macros, notify=notify, jobs=jobs,
1257-
extra_verbose=extra_verbose)
1262+
extra_verbose=extra_verbose, build_profile=build_profile)
12581263
else:
12591264
print('Library "%s" is not yet supported on target %s with toolchain %s'
12601265
% (lib_id, target.name, toolchain))
12611266

12621267

12631268
def static_analysis_scan_library(src_paths, build_path, target, toolchain_name,
12641269
cppcheck_cmd, cppcheck_msg_format,
1265-
dependencies_paths=None, options=None,
1270+
dependencies_paths=None,
12661271
name=None, clean=False, notify=None,
12671272
verbose=False, macros=None, jobs=1,
1268-
extra_verbose=False):
1273+
extra_verbose=False, build_profile=None):
12691274
""" Function scans library for statically detectable defects
12701275
12711276
Positional arguments:
@@ -1278,14 +1283,14 @@ def static_analysis_scan_library(src_paths, build_path, target, toolchain_name,
12781283
12791284
Keyword arguments:
12801285
dependencies_paths - the paths to sources that this library depends on
1281-
options - things like debug-symbols, or small-build, etc.
12821286
name - the name of this library
12831287
clean - start from a clean slate
12841288
notify - the notification event handling function
12851289
verbose - more printing!
12861290
macros - extra macros to compile with
12871291
jobs - number of commands to run at once
12881292
extra_verbose - even moar printing
1293+
build_profile - a dict of flags that will be passed to the compiler
12891294
"""
12901295
if type(src_paths) != ListType:
12911296
src_paths = [src_paths]
@@ -1296,9 +1301,10 @@ def static_analysis_scan_library(src_paths, build_path, target, toolchain_name,
12961301
src_path)
12971302

12981303
# Toolchain instance
1299-
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options,
1300-
macros=macros, notify=notify,
1301-
extra_verbose=extra_verbose)
1304+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, macros=macros,
1305+
notify=notify,
1306+
extra_verbose=extra_verbose,
1307+
build_profile=build_profile)
13021308
toolchain.VERBOSE = verbose
13031309
toolchain.jobs = jobs
13041310

0 commit comments

Comments
 (0)