@@ -1760,11 +1760,12 @@ def set_defaults(self, target=None, toolchain=None):
1760
1760
if toolchain and not self .get_cfg ('TOOLCHAIN' ):
1761
1761
self .set_cfg ('TOOLCHAIN' , toolchain )
1762
1762
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
1765
1766
if os .path .isfile ('MACROS.txt' ):
1766
1767
with open ('MACROS.txt' ) as f :
1767
- macros = f .read ().splitlines ()
1768
+ macros . extend ( f .read ().splitlines () )
1768
1769
return macros
1769
1770
1770
1771
@@ -2613,6 +2614,7 @@ def _safe_append_profile_to_build_path(build_path, profile):
2613
2614
@subcommand ('compile' ,
2614
2615
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, GCC_ARM, IAR' ),
2615
2616
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' ),
2616
2618
dict (name = ['--profile' ], action = 'append' , help = 'Path of a build profile configuration file (or name of Mbed OS profile). Default: develop' ),
2617
2619
dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current program or library as a static library.' ),
2618
2620
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):
2628
2630
dict (name = '--app-config' , dest = "app_config" , help = "Path of an application configuration file. Default is to look for \" mbed_app.json\" ." ),
2629
2631
help = 'Compile code using the mbed build tools' ,
2630
2632
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 ):
2632
2637
# Gather remaining arguments
2633
2638
args = remainder
2634
2639
# Find the root of the program
@@ -2657,7 +2662,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2657
2662
2658
2663
target = program .get_target (target )
2659
2664
tchain = program .get_toolchain (toolchain )
2660
- macros = program .get_macros ()
2665
+ macros = program .get_macros (macro )
2661
2666
profile = program .get_profile (profile )
2662
2667
2663
2668
if compile_config :
@@ -2753,6 +2758,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2753
2758
@subcommand ('test' ,
2754
2759
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, GCC_ARM, IAR' ),
2755
2760
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' ),
2756
2762
dict (name = '--compile-list' , dest = 'compile_list' , action = 'store_true' ,
2757
2763
help = 'List all tests that can be built' ),
2758
2764
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,
2780
2786
help = "Run Icetea tests. If used without --greentea flag then run only icetea tests." ),
2781
2787
help = 'Find, build and run tests' ,
2782
2788
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 ):
2789
2790
2790
2791
# Default behaviour is to run only greentea tests
2791
2792
if not (greentea or icetea or unittests ):
@@ -2811,7 +2812,8 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
2811
2812
orig_path = getcwd ()
2812
2813
orig_target = target
2813
2814
2814
- macros = program .get_macros ()
2815
+ macros = program .get_macros (macro )
2816
+ macros .append ("MBED_TEST_MODE" )
2815
2817
tools_dir = program .get_tools ()
2816
2818
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
2817
2819
0 commit comments