Skip to content

Commit 3b79b3f

Browse files
committed
add --ignore argument to mbed compile & mbed export commands
1 parent badd753 commit 3b79b3f

File tree

5 files changed

+60
-49
lines changed

5 files changed

+60
-49
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: 14 additions & 15 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):
@@ -547,11 +551,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
547551
toolchain = prepare_toolchain(
548552
src_paths, build_path, target, toolchain_name, macros=macros,
549553
clean=clean, jobs=jobs, notify=notify, config=config,
550-
app_config=app_config, build_profile=build_profile)
551-
552-
if ignore:
553-
toolchain.add_ignore_patterns(root=".", base_path=".",
554-
patterns=ignore)
554+
app_config=app_config, build_profile=build_profile, ignore=ignore)
555555

556556
# The first path will give the name to the library
557557
name = (name or toolchain.config.name or
@@ -697,11 +697,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
697697
toolchain = prepare_toolchain(
698698
src_paths, build_path, target, toolchain_name, macros=macros,
699699
clean=clean, jobs=jobs, notify=notify, app_config=app_config,
700-
build_profile=build_profile)
701-
702-
if ignore:
703-
toolchain.add_ignore_patterns(root=".", base_path=".",
704-
patterns=ignore)
700+
build_profile=build_profile, ignore=ignore)
705701

706702
# The first path will give the name to the library
707703
if name is None:
@@ -803,7 +799,7 @@ def mbed2_obj_path(target_name, toolchain_name):
803799

804800
def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
805801
notify=None, jobs=1, report=None, properties=None,
806-
build_profile=None):
802+
build_profile=None, ignore=None):
807803
""" Legacy method for building mbed libraries
808804
809805
Positional arguments:
@@ -819,6 +815,7 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
819815
report - a dict where a result may be appended
820816
properties - UUUUHHHHH beats me
821817
build_profile - a dict of flags that will be passed to the compiler
818+
ignore - list of paths to add to mbedignore
822819
"""
823820
lib = Library(lib_id)
824821
if not lib.is_supported(target, toolchain_name):
@@ -882,7 +879,8 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
882879

883880
toolchain = prepare_toolchain(
884881
src_paths, tmp_path, target, toolchain_name, macros=macros,
885-
notify=notify, build_profile=build_profile, jobs=jobs, clean=clean)
882+
notify=notify, build_profile=build_profile, jobs=jobs, clean=clean,
883+
ignore=ignore)
886884

887885
notify.info("Building library %s (%s, %s)" %
888886
(name.upper(), target.name, toolchain_name))
@@ -958,7 +956,7 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
958956
# library
959957
def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
960958
notify=None, jobs=1, report=None, properties=None,
961-
build_profile=None):
959+
build_profile=None, ignore=None):
962960
""" Function returns True is library was built and false if building was
963961
skipped
964962
@@ -974,6 +972,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
974972
report - a dict where a result may be appended
975973
properties - UUUUHHHHH beats me
976974
build_profile - a dict of flags that will be passed to the compiler
975+
ignore - list of paths to add to mbedignore
977976
"""
978977

979978
if report != None:
@@ -1017,7 +1016,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
10171016

10181017
toolchain = prepare_toolchain(
10191018
[""], tmp_path, target, toolchain_name, macros=macros, notify=notify,
1020-
build_profile=build_profile, jobs=jobs, clean=clean)
1019+
build_profile=build_profile, jobs=jobs, clean=clean, ignore=ignore)
10211020

10221021
# Take into account the library configuration (MBED_CONFIG_FILE)
10231022
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

0 commit comments

Comments
 (0)