Skip to content

Commit 51ac3b9

Browse files
authored
Merge pull request #835 from screamerbg/feature_test_macros
Feature: Macros handling to `mbed test`
2 parents a3c9887 + 41d954b commit 51ac3b9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

mbed/mbed.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,12 @@ def set_defaults(self, target=None, toolchain=None):
17601760
if toolchain and not self.get_cfg('TOOLCHAIN'):
17611761
self.set_cfg('TOOLCHAIN', toolchain)
17621762

1763-
def get_macros(self):
1764-
macros = []
1763+
def get_macros(self, more_macros=None):
1764+
macros = more_macros or []
1765+
# backwards compatibility with old MACROS.txt file
17651766
if os.path.isfile('MACROS.txt'):
17661767
with open('MACROS.txt') as f:
1767-
macros = f.read().splitlines()
1768+
macros.extend(f.read().splitlines())
17681769
return macros
17691770

17701771

@@ -2613,6 +2614,7 @@ def _safe_append_profile_to_build_path(build_path, profile):
26132614
@subcommand('compile',
26142615
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
26152616
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2617+
dict(name=['-D', '--macro'], action='append', help='Add a macro definition'),
26162618
dict(name=['--profile'], action='append', help='Path of a build profile configuration file (or name of Mbed OS profile). Default: develop'),
26172619
dict(name='--library', dest='compile_library', action='store_true', help='Compile the current program or library as a static library.'),
26182620
dict(name='--config', dest='compile_config', action='store_true', help='Show run-time compile configuration'),
@@ -2628,7 +2630,10 @@ def _safe_append_profile_to_build_path(build_path, profile):
26282630
dict(name='--app-config', dest="app_config", help="Path of an application configuration file. Default is to look for \"mbed_app.json\"."),
26292631
help='Compile code using the mbed build tools',
26302632
description="Compile this program using the mbed build tools.")
2631-
def compile_(toolchain=None, target=None, profile=False, compile_library=False, compile_config=False, config_prefix=None, source=False, build=False, clean=False, flash=False, sterm=False, artifact_name=None, supported=False, app_config=None):
2633+
def compile_(toolchain=None, target=None, macro=False, profile=False,
2634+
compile_library=False, compile_config=False, config_prefix=None,
2635+
source=False, build=False, clean=False, flash=False, sterm=False,
2636+
artifact_name=None, supported=False, app_config=None):
26322637
# Gather remaining arguments
26332638
args = remainder
26342639
# Find the root of the program
@@ -2657,7 +2662,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
26572662

26582663
target = program.get_target(target)
26592664
tchain = program.get_toolchain(toolchain)
2660-
macros = program.get_macros()
2665+
macros = program.get_macros(macro)
26612666
profile = program.get_profile(profile)
26622667

26632668
if compile_config:
@@ -2753,6 +2758,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
27532758
@subcommand('test',
27542759
dict(name=['-t', '--toolchain'], help='Compile toolchain. Example: ARM, GCC_ARM, IAR'),
27552760
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
2761+
dict(name=['-D', '--macro'], action='append', help='Add a macro definition'),
27562762
dict(name='--compile-list', dest='compile_list', action='store_true',
27572763
help='List all tests that can be built'),
27582764
dict(name='--run-list', dest='run_list', action='store_true', help='List all built tests that can be ran'),
@@ -2780,12 +2786,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
27802786
help="Run Icetea tests. If used without --greentea flag then run only icetea tests."),
27812787
help='Find, build and run tests',
27822788
description="Find, build, and run tests in a program and libraries")
2783-
def test_(toolchain=None, target=None, compile_list=False, run_list=False,
2784-
compile_only=False, run_only=False, tests_by_name=None, source=False,
2785-
profile=False, build=False, clean=False, test_spec=None,
2786-
app_config=None, test_config=None, coverage=None, make_program=None,
2787-
new=None, generator=None, regex=None, unittests=None,
2788-
build_data=None, greentea=None, icetea=None):
2789+
def test_(toolchain=None, target=None, macro=False, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None, coverage=None, make_program=None, new=None, generator=None, regex=None, unittests=None, build_data=None, greentea=None, icetea=None):
27892790

27902791
# Default behaviour is to run only greentea tests
27912792
if not (greentea or icetea or unittests):
@@ -2811,7 +2812,8 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
28112812
orig_path = getcwd()
28122813
orig_target = target
28132814

2814-
macros = program.get_macros()
2815+
macros = program.get_macros(macro)
2816+
macros.append("MBED_TEST_MODE")
28152817
tools_dir = program.get_tools()
28162818
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
28172819

0 commit comments

Comments
 (0)