Skip to content

Commit a7a163b

Browse files
committed
Merge pull request #161 from ARMmbed/config_system
Config system
2 parents 752b2ac + c74a6a4 commit a7a163b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2001
-52
lines changed

.mbedignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ mbed/docs/*
22
mbed/libraries/*
33
mbed/travis/*
44
mbed/workspace_tools/*
5+
tools/*

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test:
44
- cd ../testproject && mbed compile -m K64F -t GCC_ARM -j 0 --source=. --source=mbed-os/TESTS/integration/basic
55
- cd ../testproject && mbed compile -m K64F -t GCC_ARM -j 0 --tests
66
- cd ../testproject && mbed compile -m LPC1768 -t GCC_ARM -j 0 --source=. --source=mbed-os/TESTS/integration/basic
7+
- cd ../testproject && export PYTHONPATH=$(readlink -f mbed-os) && python mbed-os/tools/test/config_test/config_test.py
78

89
dependencies:
910
pre:

docs/config_system.md

Lines changed: 270 additions & 0 deletions
Large diffs are not rendered by default.

tools/build_api.py

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from tools.toolchains import TOOLCHAIN_CLASSES
3434
from jinja2 import FileSystemLoader
3535
from jinja2.environment import Environment
36-
36+
from tools.config import Config
3737

3838
def prep_report(report, target_name, toolchain_name, id_name):
3939
# Setup report keys
@@ -76,21 +76,46 @@ def add_result_to_report(report, result):
7676
result_wrap = { 0: result }
7777
report[target][toolchain][id_name].append(result_wrap)
7878

79+
def get_config(src_path, target, toolchain_name):
80+
# Convert src_path to a list if needed
81+
src_paths = [src_path] if type(src_path) != ListType else src_path
82+
# We need to remove all paths which are repeated to avoid
83+
# multiple compilations and linking with the same objects
84+
src_paths = [src_paths[0]] + list(set(src_paths[1:]))
85+
86+
# Create configuration object
87+
config = Config(target, src_paths)
88+
89+
# If the 'target' argument is a string, convert it to a target instance
90+
if isinstance(target, str):
91+
try:
92+
target = TARGET_MAP[target]
93+
except KeyError:
94+
raise KeyError("Target '%s' not found" % target)
95+
96+
# Toolchain instance
97+
try:
98+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options=None, notify=None, macros=None, silent=True, extra_verbose=False)
99+
except KeyError as e:
100+
raise KeyError("Toolchain %s not supported" % toolchain_name)
101+
102+
# Scan src_path for config files
103+
resources = toolchain.scan_resources(src_paths[0])
104+
for path in src_paths[1:]:
105+
resources.add(toolchain.scan_resources(path))
106+
107+
config.add_config_files(resources.json_files)
108+
return config.get_config_data()
109+
79110
def build_project(src_path, build_path, target, toolchain_name,
80111
libraries_paths=None, options=None, linker_script=None,
81112
clean=False, notify=None, verbose=False, name=None, macros=None, inc_dirs=None,
82-
jobs=1, silent=False, report=None, properties=None, project_id=None, project_description=None, extra_verbose=False):
113+
jobs=1, silent=False, report=None, properties=None, project_id=None, project_description=None,
114+
extra_verbose=False, config=None):
83115
""" This function builds project. Project can be for example one test / UT
84116
"""
85-
# Toolchain instance
86-
try:
87-
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose)
88-
except KeyError as e:
89-
raise KeyError("Toolchain %s not supported" % toolchain_name)
90117

91-
toolchain.VERBOSE = verbose
92-
toolchain.jobs = jobs
93-
toolchain.build_all = clean
118+
# Convert src_path to a list if needed
94119
src_paths = [src_path] if type(src_path) != ListType else src_path
95120

96121
# We need to remove all paths which are repeated to avoid
@@ -100,6 +125,26 @@ def build_project(src_path, build_path, target, toolchain_name,
100125
abs_path = abspath(first_src_path)
101126
project_name = basename(normpath(abs_path))
102127

128+
# If the configuration object was not yet created, create it now
129+
config = config or Config(target, src_paths)
130+
131+
# If the 'target' argument is a string, convert it to a target instance
132+
if isinstance(target, str):
133+
try:
134+
target = TARGET_MAP[target]
135+
except KeyError:
136+
raise KeyError("Target '%s' not found" % target)
137+
138+
# Toolchain instance
139+
try:
140+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose)
141+
except KeyError as e:
142+
raise KeyError("Toolchain %s not supported" % toolchain_name)
143+
144+
toolchain.VERBOSE = verbose
145+
toolchain.jobs = jobs
146+
toolchain.build_all = clean
147+
103148
if name is None:
104149
# We will use default project name based on project folder name
105150
name = project_name
@@ -148,13 +193,18 @@ def build_project(src_path, build_path, target, toolchain_name,
148193
resources.inc_dirs.extend(inc_dirs)
149194
else:
150195
resources.inc_dirs.append(inc_dirs)
196+
197+
# Update the configuration with any .json files found while scanning
198+
config.add_config_files(resources.json_files)
199+
# And add the configuration macros to the toolchain
200+
toolchain.add_macros(config.get_config_data_macros())
201+
151202
# Compile Sources
152203
for path in src_paths:
153204
src = toolchain.scan_resources(path)
154205
objects = toolchain.compile_sources(src, build_path, resources.inc_dirs)
155206
resources.objects.extend(objects)
156207

157-
158208
# Link Program
159209
res, needed_update = toolchain.link_program(resources, build_path, name)
160210

@@ -190,7 +240,6 @@ def build_project(src_path, build_path, target, toolchain_name,
190240
# Let Exception propagate
191241
raise e
192242

193-
194243
def build_library(src_paths, build_path, target, toolchain_name,
195244
dependencies_paths=None, options=None, name=None, clean=False, archive=True,
196245
notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None,
@@ -279,13 +328,19 @@ def build_library(src_paths, build_path, target, toolchain_name,
279328
else:
280329
tmp_path = build_path
281330

331+
# Handle configuration
332+
config = Config(target)
333+
282334
# Copy headers, objects and static libraries
283335
for resource in resources:
284336
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
285337
toolchain.copy_files(resource.objects, build_path, rel_path=resource.base_path)
286338
toolchain.copy_files(resource.libraries, build_path, rel_path=resource.base_path)
287339
if resource.linker_script:
288340
toolchain.copy_files(resource.linker_script, build_path, rel_path=resource.base_path)
341+
config.add_config_files(resource.json_files)
342+
343+
toolchain.add_macros(config.get_config_data_macros())
289344

290345
# Compile Sources
291346
objects = []

0 commit comments

Comments
 (0)