Skip to content

Commit 708f638

Browse files
authored
Merge pull request #423 from bridadan/build_dir_fixes
Remove unnecessary creation of BUILD dir for certain commands.
2 parents ce8dd03 + 277854f commit 708f638

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

mbed/mbed.py

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,6 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
21442144
# Find the root of the program
21452145
program = Program(os.getcwd(), True)
21462146
program.check_requirements(True)
2147-
program.ignore_build_dir()
21482147
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
21492148
orig_path = os.getcwd()
21502149

@@ -2178,39 +2177,46 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
21782177
+ (['-v'] if verbose else [])
21792178
+ (list(chain.from_iterable(izip(repeat('--prefix'), config_prefix))) if config_prefix else []),
21802179
env=env)
2181-
elif compile_library:
2182-
# Compile as a library (current dir is default)
2183-
if not build:
2184-
build = os.path.join(os.path.relpath(program.path, orig_path), program.build_dir, 'libraries', os.path.basename(orig_path), target, tchain)
2185-
2186-
popen(['python', '-u', os.path.join(tools_dir, 'build.py')]
2187-
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2188-
+ ['-t', tchain, '-m', target]
2189-
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
2190-
+ list(chain.from_iterable(izip(repeat('--source'), source)))
2191-
+ ['--build', build]
2192-
+ (['-c'] if clean else [])
2193-
+ (['--artifact-name', artifact_name] if artifact_name else [])
2194-
+ (['-v'] if verbose else [])
2195-
+ args,
2196-
env=env)
21972180
else:
2198-
# Compile as application (root is default)
2181+
# If the user hasn't supplied a build directory, ignore the default build directory
21992182
if not build:
2200-
build = os.path.join(os.path.relpath(program.path, orig_path), program.build_dir, target, tchain)
2183+
program.ignore_build_dir()
2184+
2185+
build_path = build
22012186

2202-
popen(['python', '-u', os.path.join(tools_dir, 'make.py')]
2203-
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2204-
+ ['-t', tchain, '-m', target]
2205-
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
2206-
+ list(chain.from_iterable(izip(repeat('--source'), source)))
2207-
+ ['--build', build]
2208-
+ (['-c'] if clean else [])
2209-
+ (['--artifact-name', artifact_name] if artifact_name else [])
2210-
+ (['--app-config', app_config] if app_config else [])
2211-
+ (['-v'] if verbose else [])
2212-
+ args,
2213-
env=env)
2187+
if compile_library:
2188+
# Compile as a library (current dir is default)
2189+
if not build_path:
2190+
build_path = os.path.join(os.path.relpath(program.path, orig_path), program.build_dir, 'libraries', os.path.basename(orig_path), target, tchain)
2191+
2192+
popen(['python', '-u', os.path.join(tools_dir, 'build.py')]
2193+
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2194+
+ ['-t', tchain, '-m', target]
2195+
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
2196+
+ list(chain.from_iterable(izip(repeat('--source'), source)))
2197+
+ ['--build', build_path]
2198+
+ (['-c'] if clean else [])
2199+
+ (['--artifact-name', artifact_name] if artifact_name else [])
2200+
+ (['-v'] if verbose else [])
2201+
+ args,
2202+
env=env)
2203+
else:
2204+
# Compile as application (root is default)
2205+
if not build_path:
2206+
build_path = os.path.join(os.path.relpath(program.path, orig_path), program.build_dir, target, tchain)
2207+
2208+
popen(['python', '-u', os.path.join(tools_dir, 'make.py')]
2209+
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
2210+
+ ['-t', tchain, '-m', target]
2211+
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
2212+
+ list(chain.from_iterable(izip(repeat('--source'), source)))
2213+
+ ['--build', build_path]
2214+
+ (['-c'] if clean else [])
2215+
+ (['--artifact-name', artifact_name] if artifact_name else [])
2216+
+ (['--app-config', app_config] if app_config else [])
2217+
+ (['-v'] if verbose else [])
2218+
+ args,
2219+
env=env)
22142220

22152221
program.set_defaults(target=target, toolchain=tchain)
22162222

@@ -2238,7 +2244,6 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
22382244
# Find the root of the program
22392245
program = Program(os.getcwd(), True)
22402246
program.check_requirements(True)
2241-
program.ignore_build_dir()
22422247
# Save original working directory
22432248
orig_path = os.getcwd()
22442249

@@ -2257,15 +2262,16 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
22572262
source = [program.path]
22582263

22592264
# Setup the build path if not specified
2260-
if not build:
2261-
build = os.path.join(program.path, program.build_dir, 'tests', target, tchain)
2265+
build_path = build
2266+
if not build_path:
2267+
build_path = os.path.join(program.path, program.build_dir, 'tests', target, tchain)
22622268

22632269
if test_spec:
22642270
# Preserve path to given test spec
22652271
test_spec = os.path.relpath(os.path.join(orig_path, test_spec), program.path)
22662272
else:
22672273
# Create the path to the test spec file
2268-
test_spec = os.path.join(build, 'test_spec.json')
2274+
test_spec = os.path.join(build_path, 'test_spec.json')
22692275

22702276
if compile_list:
22712277
popen(['python', '-u', os.path.join(tools_dir, 'test.py'), '--list']
@@ -2279,13 +2285,17 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
22792285
env=env)
22802286

22812287
if compile_only or build_and_run_tests:
2288+
# If the user hasn't supplied a build directory, ignore the default build directory
2289+
if not build:
2290+
program.ignore_build_dir()
2291+
22822292
popen(['python', '-u', os.path.join(tools_dir, 'test.py')]
22832293
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
22842294
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
22852295
+ ['-t', tchain, '-m', target]
22862296
+ (['-c'] if clean else [])
22872297
+ list(chain.from_iterable(izip(repeat('--source'), source)))
2288-
+ ['--build', build]
2298+
+ ['--build', build_path]
22892299
+ ['--test-spec', test_spec]
22902300
+ (['-n', tests_by_name] if tests_by_name else [])
22912301
+ (['-v'] if verbose else [])
@@ -2326,7 +2336,6 @@ def export(ide=None, target=None, source=False, clean=False, supported=False):
23262336
# Find the root of the program
23272337
program = Program(os.getcwd(), True)
23282338
program.check_requirements(True)
2329-
program.ignore_build_dir()
23302339
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
23312340
orig_path = os.getcwd()
23322341
# Change directories to the program root to use mbed OS tools
@@ -2350,6 +2359,8 @@ def export(ide=None, target=None, source=False, clean=False, supported=False):
23502359

23512360
if not source or len(source) == 0:
23522361
source = [os.path.relpath(program.path, orig_path)]
2362+
2363+
program.ignore_build_dir()
23532364

23542365
popen(['python', '-u', os.path.join(tools_dir, 'project.py')]
23552366
+ list(chain.from_iterable(izip(repeat('-D'), macros)))

0 commit comments

Comments
 (0)