Skip to content

Commit d3cc4e1

Browse files
author
Cruz Monrreal
authored
Merge pull request #6833 from andrewleech/test_ignore_arg
mbed test: add argument `--ignore` to allow passing in mbedignore patterns
2 parents 598e511 + 3b79b3f commit d3cc4e1

File tree

7 files changed

+73
-46
lines changed

7 files changed

+73
-46
lines changed

tools/build.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
4242
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
4343
from tools.notifier.term import TerminalNotifier
44-
from tools.utils import argparse_filestring_type, args_error
44+
from tools.utils import argparse_filestring_type, args_error, argparse_many
4545
from tools.utils import argparse_filestring_type, argparse_dir_not_parent
4646

4747
if __name__ == '__main__':
@@ -129,6 +129,9 @@
129129
default=False,
130130
help="Makes compiler more verbose, CI friendly.")
131131

132+
parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
133+
default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")
134+
132135
options = parser.parse_args()
133136

134137
# Only prints matrix of supported toolchains
@@ -185,35 +188,35 @@
185188
mcu = TARGET_MAP[target]
186189
profile = extract_profile(parser, options, toolchain)
187190
if options.source_dir:
188-
lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
189-
extra_verbose=options.extra_verbose_notify,
190-
verbose=options.verbose,
191-
silent=options.silent,
192-
jobs=options.jobs,
193-
clean=options.clean,
194-
archive=(not options.no_archive),
195-
macros=options.macros,
196-
name=options.artifact_name,
197-
build_profile=profile)
191+
lib_build_res = build_library(
192+
options.source_dir, options.build_dir, mcu, toolchain,
193+
jobs=options.jobs,
194+
clean=options.clean,
195+
archive=(not options.no_archive),
196+
macros=options.macros,
197+
name=options.artifact_name,
198+
build_profile=profile,
199+
ignore=options.ignore,
200+
)
198201
else:
199-
lib_build_res = build_mbed_libs(mcu, toolchain,
200-
extra_verbose=options.extra_verbose_notify,
201-
verbose=options.verbose,
202-
silent=options.silent,
203-
jobs=options.jobs,
204-
clean=options.clean,
205-
macros=options.macros,
206-
build_profile=profile)
202+
lib_build_res = build_mbed_libs(
203+
mcu, toolchain,
204+
jobs=options.jobs,
205+
clean=options.clean,
206+
macros=options.macros,
207+
build_profile=profile,
208+
ignore=options.ignore,
209+
)
207210

208211
for lib_id in libraries:
209-
build_lib(lib_id, mcu, toolchain,
210-
extra_verbose=options.extra_verbose_notify,
211-
verbose=options.verbose,
212-
silent=options.silent,
213-
clean=options.clean,
214-
macros=options.macros,
215-
jobs=options.jobs,
216-
build_profile=profile)
212+
build_lib(
213+
lib_id, mcu, toolchain,
214+
clean=options.clean,
215+
macros=options.macros,
216+
jobs=options.jobs,
217+
build_profile=profile,
218+
ignore=options.ignore,
219+
)
217220
if lib_build_res:
218221
successes.append(tt_id)
219222
else:
@@ -226,7 +229,6 @@
226229
failures.append(tt_id)
227230
print(e)
228231

229-
230232
# Write summary of the builds
231233
print("\nCompleted in: (%.2f)s\n" % (time() - start))
232234

tools/build_api.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def target_supports_toolchain(target, toolchain_name):
301301
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
302302
macros=None, clean=False, jobs=1,
303303
notify=None, config=None, app_config=None,
304-
build_profile=None):
304+
build_profile=None, ignore=None):
305305
""" Prepares resource related objects - toolchain, target, config
306306
307307
Positional arguments:
@@ -317,6 +317,7 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
317317
config - a Config object to use instead of creating one
318318
app_config - location of a chosen mbed_app.json file
319319
build_profile - a list of mergeable build profiles
320+
ignore - list of paths to add to mbedignore
320321
"""
321322

322323
# We need to remove all paths which are repeated to avoid
@@ -348,6 +349,9 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
348349
toolchain.jobs = jobs
349350
toolchain.build_all = clean
350351

352+
if ignore:
353+
toolchain.add_ignore_patterns(root=".", base_path=".", patterns=ignore)
354+
351355
return toolchain
352356

353357
def _printihex(ihex):
@@ -502,7 +506,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
502506
notify=None, name=None, macros=None, inc_dirs=None, jobs=1,
503507
report=None, properties=None, project_id=None,
504508
project_description=None, config=None,
505-
app_config=None, build_profile=None, stats_depth=None):
509+
app_config=None, build_profile=None, stats_depth=None, ignore=None):
506510
""" Build a project. A project may be a test or a user program.
507511
508512
Positional arguments:
@@ -529,6 +533,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
529533
app_config - location of a chosen mbed_app.json file
530534
build_profile - a dict of flags that will be passed to the compiler
531535
stats_depth - depth level for memap to display file/dirs
536+
ignore - list of paths to add to mbedignore
532537
"""
533538

534539
# Convert src_path to a list if needed
@@ -546,7 +551,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
546551
toolchain = prepare_toolchain(
547552
src_paths, build_path, target, toolchain_name, macros=macros,
548553
clean=clean, jobs=jobs, notify=notify, config=config,
549-
app_config=app_config, build_profile=build_profile)
554+
app_config=app_config, build_profile=build_profile, ignore=ignore)
550555

551556
# The first path will give the name to the library
552557
name = (name or toolchain.config.name or
@@ -643,7 +648,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
643648
archive=True, notify=None, macros=None, inc_dirs=None, jobs=1,
644649
report=None, properties=None, project_id=None,
645650
remove_config_header_file=False, app_config=None,
646-
build_profile=None):
651+
build_profile=None, ignore=None):
647652
""" Build a library
648653
649654
Positional arguments:
@@ -668,6 +673,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
668673
remove_config_header_file - delete config header file when done building
669674
app_config - location of a chosen mbed_app.json file
670675
build_profile - a dict of flags that will be passed to the compiler
676+
ignore - list of paths to add to mbedignore
671677
"""
672678

673679
# Convert src_path to a list if needed
@@ -691,7 +697,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
691697
toolchain = prepare_toolchain(
692698
src_paths, build_path, target, toolchain_name, macros=macros,
693699
clean=clean, jobs=jobs, notify=notify, app_config=app_config,
694-
build_profile=build_profile)
700+
build_profile=build_profile, ignore=ignore)
695701

696702
# The first path will give the name to the library
697703
if name is None:
@@ -793,7 +799,7 @@ def mbed2_obj_path(target_name, toolchain_name):
793799

794800
def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
795801
notify=None, jobs=1, report=None, properties=None,
796-
build_profile=None):
802+
build_profile=None, ignore=None):
797803
""" Legacy method for building mbed libraries
798804
799805
Positional arguments:
@@ -809,6 +815,7 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
809815
report - a dict where a result may be appended
810816
properties - UUUUHHHHH beats me
811817
build_profile - a dict of flags that will be passed to the compiler
818+
ignore - list of paths to add to mbedignore
812819
"""
813820
lib = Library(lib_id)
814821
if not lib.is_supported(target, toolchain_name):
@@ -872,7 +879,8 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
872879

873880
toolchain = prepare_toolchain(
874881
src_paths, tmp_path, target, toolchain_name, macros=macros,
875-
notify=notify, build_profile=build_profile, jobs=jobs, clean=clean)
882+
notify=notify, build_profile=build_profile, jobs=jobs, clean=clean,
883+
ignore=ignore)
876884

877885
notify.info("Building library %s (%s, %s)" %
878886
(name.upper(), target.name, toolchain_name))
@@ -948,7 +956,7 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
948956
# library
949957
def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
950958
notify=None, jobs=1, report=None, properties=None,
951-
build_profile=None):
959+
build_profile=None, ignore=None):
952960
""" Function returns True is library was built and false if building was
953961
skipped
954962
@@ -964,6 +972,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
964972
report - a dict where a result may be appended
965973
properties - UUUUHHHHH beats me
966974
build_profile - a dict of flags that will be passed to the compiler
975+
ignore - list of paths to add to mbedignore
967976
"""
968977

969978
if report != None:
@@ -1007,7 +1016,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
10071016

10081017
toolchain = prepare_toolchain(
10091018
[""], tmp_path, target, toolchain_name, macros=macros, notify=notify,
1010-
build_profile=build_profile, jobs=jobs, clean=clean)
1019+
build_profile=build_profile, jobs=jobs, clean=clean, ignore=ignore)
10111020

10121021
# Take into account the library configuration (MBED_CONFIG_FILE)
10131022
config = toolchain.config

tools/export/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos, notify):
221221
def export_project(src_paths, export_path, target, ide, libraries_paths=None,
222222
linker_script=None, notify=None, name=None, inc_dirs=None,
223223
jobs=1, config=None, macros=None, zip_proj=None,
224-
inc_repos=False, build_profile=None, app_config=None):
224+
inc_repos=False, build_profile=None, app_config=None,
225+
ignore=None):
225226
"""Generates a project file and creates a zip archive if specified
226227
227228
Positional Arguments:
@@ -242,6 +243,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
242243
macros - User-defined macros
243244
zip_proj - string name of the zip archive you wish to creat (exclude arg
244245
if you do not wish to create an archive
246+
ignore - list of paths to add to mbedignore
245247
"""
246248

247249
# Convert src_path to a list if needed
@@ -269,7 +271,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
269271
toolchain = prepare_toolchain(
270272
paths, "", target, toolchain_name, macros=macros, jobs=jobs,
271273
notify=notify, config=config, build_profile=build_profile,
272-
app_config=app_config)
274+
app_config=app_config, ignore=ignore)
273275

274276
toolchain.RESPONSE_FILES = False
275277
if name is None:

tools/make.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
default=None, help="The build (output) directory")
141141
parser.add_argument("-N", "--artifact-name", dest="artifact_name",
142142
default=None, help="The built project's name")
143+
parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
144+
default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")
143145
parser.add_argument("-d", "--disk", dest="disk",
144146
default=None, help="The mbed disk")
145147
parser.add_argument("-s", "--serial", dest="serial",
@@ -284,7 +286,8 @@
284286
build_profile=extract_profile(parser,
285287
options,
286288
toolchain),
287-
stats_depth=options.stats_depth)
289+
stats_depth=options.stats_depth,
290+
ignore=options.ignore)
288291
print('Image: %s'% bin_file)
289292

290293
if options.disk:

tools/project.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def setup_project(ide, target, program=None, source_dir=None, build=None, export
7373

7474
def export(target, ide, build=None, src=None, macros=None, project_id=None,
7575
zip_proj=False, build_profile=None, export_path=None, notify=None,
76-
app_config=None):
76+
app_config=None, ignore=None):
7777
"""Do an export of a project.
7878
7979
Positional arguments:
@@ -87,6 +87,7 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
8787
project_id - the name of the project
8888
clean - start from a clean state before exporting
8989
zip_proj - create a zip file or not
90+
ignore - list of paths to add to mbedignore
9091
9192
Returns an object of type Exporter (tools/exports/exporters.py)
9293
"""
@@ -98,7 +99,7 @@ def export(target, ide, build=None, src=None, macros=None, project_id=None,
9899
return export_project(src, project_dir, target, ide, name=name,
99100
macros=macros, libraries_paths=lib, zip_proj=zip_name,
100101
build_profile=build_profile, notify=notify,
101-
app_config=app_config)
102+
app_config=app_config, ignore=ignore)
102103

103104

104105
def main():
@@ -197,6 +198,9 @@ def main():
197198
dest="app_config",
198199
default=None)
199200

201+
parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
202+
default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")
203+
200204
options = parser.parse_args()
201205

202206
# Print available tests in order and exit
@@ -273,7 +277,8 @@ def main():
273277
src=options.source_dir, macros=options.macros,
274278
project_id=options.program, zip_proj=zip_proj,
275279
build_profile=profile, app_config=options.app_config,
276-
export_path=options.build_dir, notify = notify)
280+
export_path=options.build_dir, notify=notify,
281+
ignore=options.ignore)
277282
except NotSupportedException as exc:
278283
print("[ERROR] %s" % str(exc))
279284

tools/test.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@
112112
default=2,
113113
help="Depth level for static memory report")
114114

115+
parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
116+
default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")
117+
115118
options = parser.parse_args()
116119

117120
# Filter tests by path if specified
@@ -153,6 +156,7 @@
153156
if not config:
154157
config = get_default_config(options.source_dir or ['.'], mcu)
155158

159+
156160
# Find all tests in the relevant paths
157161
for path in all_paths:
158162
all_tests.update(find_tests(path, mcu, toolchain,
@@ -205,7 +209,8 @@
205209
macros=options.macros,
206210
notify=notify, archive=False,
207211
app_config=config,
208-
build_profile=profile)
212+
build_profile=profile,
213+
ignore=options.ignore)
209214

210215
library_build_success = True
211216
except ToolException as e:
@@ -233,7 +238,8 @@
233238
continue_on_build_fail=options.continue_on_build_fail,
234239
app_config=config,
235240
build_profile=profile,
236-
stats_depth=options.stats_depth)
241+
stats_depth=options.stats_depth,
242+
ignore=options.ignore)
237243

238244
# If a path to a test spec is provided, write it to a file
239245
if options.test_spec:

tools/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22102210
clean=False, notify=None, jobs=1, macros=None,
22112211
silent=False, report=None, properties=None,
22122212
continue_on_build_fail=False, app_config=None,
2213-
build_profile=None, stats_depth=None):
2213+
build_profile=None, stats_depth=None, ignore=None):
22142214
"""Given the data structure from 'find_tests' and the typical build parameters,
22152215
build all the tests
22162216

0 commit comments

Comments
 (0)