@@ -1760,8 +1760,8 @@ 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 , macros = [] ):
1764
+ # backwards compatibility with old MACROS.txt file
1765
1765
if os .path .isfile ('MACROS.txt' ):
1766
1766
with open ('MACROS.txt' ) as f :
1767
1767
macros = f .read ().splitlines ()
@@ -2613,6 +2613,7 @@ def _safe_append_profile_to_build_path(build_path, profile):
2613
2613
@subcommand ('compile' ,
2614
2614
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, GCC_ARM, IAR' ),
2615
2615
dict (name = ['-m' , '--target' ], help = 'Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
2616
+ dict (name = ['-D' , '--macro' ], action = 'append' , help = 'Add a macro definition' ),
2616
2617
dict (name = ['--profile' ], action = 'append' , help = 'Path of a build profile configuration file (or name of Mbed OS profile). Default: develop' ),
2617
2618
dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current program or library as a static library.' ),
2618
2619
dict (name = '--config' , dest = 'compile_config' , action = 'store_true' , help = 'Show run-time compile configuration' ),
@@ -2627,7 +2628,10 @@ def _safe_append_profile_to_build_path(build_path, profile):
2627
2628
dict (name = '--app-config' , dest = "app_config" , help = "Path of an application configuration file. Default is to look for \" mbed_app.json\" ." ),
2628
2629
help = 'Compile code using the mbed build tools' ,
2629
2630
description = "Compile this program using the mbed build tools." )
2630
- 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 ):
2631
+ def compile_ (toolchain = None , target = None , macro = False , profile = False ,
2632
+ compile_library = False , compile_config = False , config_prefix = None ,
2633
+ source = False , build = False , clean = False , flash = False , sterm = False ,
2634
+ artifact_name = None , supported = False , app_config = None ):
2631
2635
# Gather remaining arguments
2632
2636
args = remainder
2633
2637
# Find the root of the program
@@ -2656,7 +2660,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2656
2660
2657
2661
target = program .get_target (target )
2658
2662
tchain = program .get_toolchain (toolchain )
2659
- macros = program .get_macros ()
2663
+ macros = program .get_macros (macro )
2660
2664
profile = program .get_profile (profile )
2661
2665
2662
2666
if compile_config :
@@ -2750,6 +2754,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2750
2754
@subcommand ('test' ,
2751
2755
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, GCC_ARM, IAR' ),
2752
2756
dict (name = ['-m' , '--target' ], help = 'Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
2757
+ dict (name = ['-D' , '--macro' ], action = 'append' , help = 'Add a macro definition' ),
2753
2758
dict (name = '--compile-list' , dest = 'compile_list' , action = 'store_true' ,
2754
2759
help = 'List all tests that can be built' ),
2755
2760
dict (name = '--run-list' , dest = 'run_list' , action = 'store_true' , help = 'List all built tests that can be ran' ),
@@ -2777,12 +2782,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2777
2782
help = "Run Icetea tests. If used without --greentea flag then run only icetea tests." ),
2778
2783
help = 'Find, build and run tests' ,
2779
2784
description = "Find, build, and run tests in a program and libraries" )
2780
- def test_ (toolchain = None , target = None , compile_list = False , run_list = False ,
2781
- compile_only = False , run_only = False , tests_by_name = None , source = False ,
2782
- profile = False , build = False , clean = False , test_spec = None ,
2783
- app_config = None , test_config = None , coverage = None , make_program = None ,
2784
- new = None , generator = None , regex = None , unittests = None ,
2785
- build_data = None , greentea = None , icetea = None ):
2785
+ 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 ):
2786
2786
2787
2787
# Default behaviour is to run only greentea tests
2788
2788
if not (greentea or icetea or unittests ):
@@ -2808,7 +2808,8 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False,
2808
2808
orig_path = getcwd ()
2809
2809
orig_target = target
2810
2810
2811
- macros = program .get_macros ()
2811
+ macros = program .get_macros (macro )
2812
+ macros .append ("MBED_TEST_MODE" )
2812
2813
tools_dir = program .get_tools ()
2813
2814
build_and_run_tests = not compile_list and not run_list and not compile_only and not run_only
2814
2815
0 commit comments