Skip to content

Commit 76578ad

Browse files
committed
Propagate "clean" option for library builds
Keep the server program cycle target dependent Keep program compilation and linking separate Compile separately sources from different directory roots
1 parent dafcf7f commit 76578ad

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

workspace_tools/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
try:
8787
mcu = TARGET_MAP[target]
8888
build_mbed_libs(mcu, toolchain, options=options.options,
89-
verbose=options.verbose)
89+
verbose=options.verbose, clean=options.clean)
9090
for lib_id in libraries:
9191
build_lib(lib_id, mcu, toolchain, options=options.options,
92-
verbose=options.verbose)
92+
verbose=options.verbose, clean=options.clean)
9393
successes.append(id)
9494
except Exception, e:
9595
if options.verbose:

workspace_tools/build_api.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from types import ListType
44

55
from workspace_tools.utils import mkdir
6-
from workspace_tools.toolchains import TOOLCHAIN_CLASSES, Resources
6+
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
77
from workspace_tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON
88
from workspace_tools.libraries import Library
99

@@ -22,7 +22,9 @@ def build_project(src_path, build_path, target, toolchain_name,
2222

2323
# Scan src_path and libraries_paths for resources
2424
resources = toolchain.scan_resources(src_path)
25+
src_paths = [src_path]
2526
if libraries_paths is not None:
27+
src_paths.extend(libraries_paths)
2628
for path in libraries_paths:
2729
resources.add(toolchain.scan_resources(path))
2830

@@ -35,8 +37,14 @@ def build_project(src_path, build_path, target, toolchain_name,
3537
rmtree(build_path)
3638
mkdir(build_path)
3739

38-
# Build Program
39-
return toolchain.build_program(resources, build_path, name)
40+
# Compile Sources
41+
for path in src_paths:
42+
src = toolchain.scan_resources(path)
43+
objects = toolchain.compile_sources(src, build_path, resources.inc_dirs)
44+
resources.objects.extend(objects)
45+
46+
# Link Program
47+
return toolchain.link_program(resources, build_path, name)
4048

4149

4250
"""
@@ -73,10 +81,11 @@ def build_library(src_paths, build_path, target, toolchain_name,
7381
resources.append(toolchain.scan_resources(src_path))
7482

7583
# Dependencies Include Paths
76-
dependencies = Resources()
84+
dependencies_include_dir = []
7785
if dependencies_paths is not None:
7886
for path in dependencies_paths:
79-
dependencies.add(toolchain.scan_resources(path))
87+
lib_resources = toolchain.scan_resources(path)
88+
dependencies_include_dir.extend(lib_resources.inc_dirs)
8089

8190
# Create the desired build directory structure
8291
bin_path = join(build_path, toolchain.obj_path)
@@ -91,21 +100,23 @@ def build_library(src_paths, build_path, target, toolchain_name,
91100
# Compile Sources
92101
objects = []
93102
for resource in resources:
94-
objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies.inc_dirs))
103+
objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))
95104

96105
toolchain.build_library(objects, bin_path, name)
97106

98107

99-
def build_lib(lib_id, target, toolchain, options=None, verbose=False):
108+
def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=False):
100109
lib = Library(lib_id)
101110
if lib.is_supported(target, toolchain):
102-
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options, verbose=verbose)
111+
build_library(lib.source_dir, lib.build_dir, target, toolchain,
112+
lib.dependencies, options,
113+
verbose=verbose, clean=clean)
103114
else:
104115
print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
105116

106117

107118
# We do have unique legacy conventions about how we build and package the mbed library
108-
def build_mbed_libs(target, toolchain_name, options=None, verbose=False):
119+
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False):
109120
# Check toolchain support
110121
if toolchain_name not in target.supported_toolchains:
111122
print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
@@ -114,6 +125,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False):
114125
# Toolchain
115126
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options)
116127
toolchain.VERBOSE = verbose
128+
toolchain.build_all = clean
117129

118130
# Source and Build Paths
119131
BUILD_TARGET = join(MBED_LIBRARIES, "TARGET_" + target.name)

workspace_tools/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from workspace_tools.utils import delete_dir_files
1717
from workspace_tools.settings import *
1818
from workspace_tools.tests import *
19+
from workspace_tools.targets import TARGET_MAP
1920

2021

2122
class ProcessObserver(Thread):
@@ -127,6 +128,7 @@ def handle(self):
127128

128129
disk = mut['disk']
129130
port = mut['port']
131+
target = TARGET_MAP[mut['mcu']]
130132

131133
# Program
132134
# When the build and test system were separate, this was relative to a
@@ -145,7 +147,7 @@ def handle(self):
145147
for f in test.extra_files:
146148
copy(f, disk)
147149

148-
sleep(1)
150+
sleep(target.program_cycle_s)
149151

150152
# Host test
151153
self.request.setblocking(0)

workspace_tools/toolchains/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,13 @@ def build_library(self, objects, dir, name):
349349
self.info("Library: %s" % lib)
350350
self.archive(objects, fout)
351351

352-
def build_program(self, r, tmp_path, name):
353-
objects = self.compile_sources(r, tmp_path) + r.objects
354-
352+
def link_program(self, r, tmp_path, name):
355353
elf = join(tmp_path, name + '.elf')
356354
bin = join(tmp_path, name + '.bin')
357355

358-
if self.need_update(elf, objects + r.libraries + [r.linker_script]):
356+
if self.need_update(elf, r.objects + r.libraries + [r.linker_script]):
359357
self.progress("link", name)
360-
self.link(elf, objects, r.libraries, r.lib_dirs, r.linker_script)
358+
self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)
361359

362360
if self.need_update(bin, [elf]):
363361
self.progress("elf2bin", name)

0 commit comments

Comments
 (0)