Skip to content

Commit badd753

Browse files
committed
mbed test: add argument --ignore to allow passing in extra mbedignore args
In particular this allows ignoring a project main.cpp file when running unit tests
1 parent 68ad00f commit badd753

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

tools/build_api.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
502502
notify=None, name=None, macros=None, inc_dirs=None, jobs=1,
503503
report=None, properties=None, project_id=None,
504504
project_description=None, config=None,
505-
app_config=None, build_profile=None, stats_depth=None):
505+
app_config=None, build_profile=None, stats_depth=None, ignore=None):
506506
""" Build a project. A project may be a test or a user program.
507507
508508
Positional arguments:
@@ -529,6 +529,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
529529
app_config - location of a chosen mbed_app.json file
530530
build_profile - a dict of flags that will be passed to the compiler
531531
stats_depth - depth level for memap to display file/dirs
532+
ignore - list of paths to add to mbedignore
532533
"""
533534

534535
# Convert src_path to a list if needed
@@ -548,6 +549,10 @@ def build_project(src_paths, build_path, target, toolchain_name,
548549
clean=clean, jobs=jobs, notify=notify, config=config,
549550
app_config=app_config, build_profile=build_profile)
550551

552+
if ignore:
553+
toolchain.add_ignore_patterns(root=".", base_path=".",
554+
patterns=ignore)
555+
551556
# The first path will give the name to the library
552557
name = (name or toolchain.config.name or
553558
basename(normpath(abspath(src_paths[0]))))
@@ -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
@@ -693,6 +699,10 @@ def build_library(src_paths, build_path, target, toolchain_name,
693699
clean=clean, jobs=jobs, notify=notify, app_config=app_config,
694700
build_profile=build_profile)
695701

702+
if ignore:
703+
toolchain.add_ignore_patterns(root=".", base_path=".",
704+
patterns=ignore)
705+
696706
# The first path will give the name to the library
697707
if name is None:
698708
name = basename(normpath(abspath(src_paths[0])))

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)