Skip to content

Commit a3b9d0c

Browse files
committed
Merge pull request #123 from bridadan/test-compile-from-mbed-tools
Test compile from mbed tools
2 parents feff58a + 0cc88f2 commit a3b9d0c

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

mbed/mbed.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,9 @@ def status(ignore=False):
12331233
dict(name='--build', help="Build directory. Default: .build/"),
12341234
dict(name='--library', dest="compile_library", action="store_true", help="Compile the current %s as a static library." % cwd_type),
12351235
dict(name='--tests', dest="compile_tests", action="store_true", help="Compile tests in TESTS directory."),
1236+
dict(name='--test_spec', dest="test_spec", help="Destination path for a test spec file that can be used by the Greentea automated test tool. (Default is 'test_spec.json')"),
12361237
help='Compile program using the native mbed OS build system.')
1237-
def compile(toolchain=None, mcu=None, source=False, build=False, compile_library=False, compile_tests=False):
1238+
def compile(toolchain=None, mcu=None, source=False, build=False, compile_library=False, compile_tests=False, test_spec="test_spec.json"):
12381239
args = remainder
12391240
orig_path = os.getcwd() # remember the original path. this is needed for compiling only the libraries and tests for the current folder.
12401241
root_path = Repo.findroot(os.getcwd())
@@ -1270,37 +1271,24 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
12701271
env = os.environ.copy()
12711272
env['PYTHONPATH'] = os.path.abspath(root_path)
12721273

1273-
def test(arg, env):
1274-
print arg
1274+
if not source or len(source) == 0:
1275+
source = [os.path.relpath(root_path, orig_path)]
12751276

12761277
if compile_tests:
12771278
# Compile tests
12781279
if not build:
1279-
build = os.path.join('.build', target, tchain)
1280-
1281-
tests_path = 'TESTS'
1282-
if os.path.exists(tests_path):
1283-
# Loop on test group directories
1284-
for d in os.listdir(tests_path):
1285-
# dir name host_tests is reserved for host python scripts.
1286-
if d != "host_tests":
1287-
# Loop on test case directories
1288-
for td in os.listdir(os.path.join(tests_path, d)):
1289-
# compile each test
1290-
popen(['python', os.path.join(tools_dir, 'make.py')]
1291-
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
1292-
+ ['-t', tchain, '-m', target]
1293-
+ ['--source', os.path.join(tests_path, d, td), '--source', '.']
1294-
+ ['--build', build]
1295-
+ (['-v'] if verbose else [])
1296-
+ args,
1297-
env=env)
1298-
if "-c" in args:
1299-
args.remove('-c')
1280+
build = os.path.join(os.path.relpath(root_path, orig_path), '.build/tests', target, tchain)
1281+
1282+
popen(['python', os.path.join(tools_dir, 'test.py')]
1283+
+ ['-t', tchain, '-m', target]
1284+
+ list(chain.from_iterable(izip(repeat('--source'), source)))
1285+
+ ['--build', build]
1286+
+ ['--test-spec', test_spec]
1287+
+ (['-v'] if verbose else [])
1288+
+ args,
1289+
env=env)
13001290
elif compile_library:
13011291
# Compile as a library (current dir is default)
1302-
if not source or len(source) == 0:
1303-
source = [os.path.relpath(root_path, orig_path)]
13041292
if not build:
13051293
build = os.path.join(os.path.relpath(root_path, orig_path), '.build', 'libraries', os.path.basename(orig_path), target, tchain)
13061294

@@ -1314,8 +1302,6 @@ def test(arg, env):
13141302
env=env)
13151303
else:
13161304
# Compile as application (root is default)
1317-
if not source or len(source) == 0:
1318-
source = [os.path.relpath(root_path, orig_path)]
13191305
if not build:
13201306
build = os.path.join(os.path.relpath(root_path, orig_path), '.build', target, tchain)
13211307

0 commit comments

Comments
 (0)