Skip to content

Commit ceda396

Browse files
committed
Add simple build profiles to toolchains
1 parent b481da4 commit ceda396

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

tools/build_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
277277
macros=None, options=None, clean=False, jobs=1,
278278
notify=None, silent=False, verbose=False,
279279
extra_verbose=False, config=None,
280-
app_config=None):
280+
app_config=None, build_profile=None):
281281
""" Prepares resource related objects - toolchain, target, config
282282
283283
Positional arguments:
@@ -310,7 +310,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
310310
try:
311311
toolchain = TOOLCHAIN_CLASSES[toolchain_name](
312312
target, options, notify, macros, silent,
313-
extra_verbose=extra_verbose)
313+
extra_verbose=extra_verbose, build_profile=build_profile)
314314
except KeyError:
315315
raise KeyError("Toolchain %s not supported" % toolchain_name)
316316

@@ -366,7 +366,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
366366
macros=None, inc_dirs=None, jobs=1, silent=False,
367367
report=None, properties=None, project_id=None,
368368
project_description=None, extra_verbose=False, config=None,
369-
app_config=None):
369+
app_config=None, build_profile=None):
370370
""" Build a project. A project may be a test or a user program.
371371
372372
Positional arguments:
@@ -413,7 +413,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
413413
toolchain = prepare_toolchain(
414414
src_paths, target, toolchain_name, macros=macros, options=options,
415415
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
416-
extra_verbose=extra_verbose, config=config, app_config=app_config)
416+
extra_verbose=extra_verbose, config=config, app_config=app_config,
417+
build_profile=build_profile)
417418

418419
# The first path will give the name to the library
419420
if name is None:

tools/make.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
TEST BUILD & RUN
2020
"""
2121
import sys
22+
import json
2223
from time import sleep
2324
from shutil import copy
2425
from os.path import join, abspath, dirname
@@ -180,6 +181,9 @@
180181
parser.add_argument("-l", "--linker", dest="linker_script",
181182
type=argparse_filestring_type,
182183
default=None, help="use the specified linker script")
184+
parser.add_argument("--profile", dest="profile",
185+
type=argparse_filestring_type,
186+
default=None)
183187

184188
options = parser.parse_args()
185189

@@ -220,6 +224,17 @@
220224
if options.source_dir and not options.build_dir:
221225
args_error(parser, "argument --build is required when argument --source is provided")
222226

227+
if options.profile:
228+
contents = json.load(open(options.profile))
229+
try:
230+
profile = contents[toolchain]
231+
except KeyError:
232+
args_error(parser, ("argument --profile: toolchain {} is not"
233+
" supported by profile {}").format(toolchain,
234+
options.profile))
235+
else:
236+
profile = None
237+
223238
if options.color:
224239
# This import happens late to prevent initializing colorization when we don't need it
225240
import colorize
@@ -280,7 +295,8 @@
280295
macros=options.macros,
281296
jobs=options.jobs,
282297
name=options.artifact_name,
283-
app_config=options.app_config)
298+
app_config=options.app_config,
299+
build_profile=profile)
284300
print 'Image: %s'% bin_file
285301

286302
if options.disk:

tools/toolchains/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ class mbedToolchain:
217217

218218
__metaclass__ = ABCMeta
219219

220-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
220+
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, build_profile=None):
221221
self.target = target
222222
self.name = self.__class__.__name__
223223

224224
# compile/assemble/link/binary hooks
225225
self.hook = hooks.Hook(target, self)
226226

227227
# Toolchain flags
228-
self.flags = deepcopy(self.DEFAULT_FLAGS)
228+
self.flags = deepcopy(build_profile or self.DEFAULT_FLAGS)
229229

230230
# User-defined macros
231231
self.macros = macros or []

tools/toolchains/arm.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ def check_executable():
5151
Returns False otherwise."""
5252
return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
5353

54-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
55-
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
54+
def __init__(self, target, options=None, notify=None, macros=None,
55+
silent=False, extra_verbose=False, build_profile=None):
56+
mbedToolchain.__init__(self, target, options, notify, macros, silent,
57+
extra_verbose=extra_verbose,
58+
build_profile=build_profile)
5659

5760
if target.core == "Cortex-M0+":
5861
cpu = "Cortex-M0"
@@ -241,8 +244,10 @@ def binary(self, resources, elf, bin):
241244

242245

243246
class ARM_STD(ARM):
244-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
245-
ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
247+
def __init__(self, target, options=None, notify=None, macros=None,
248+
silent=False, extra_verbose=False, build_profile=None):
249+
ARM.__init__(self, target, options, notify, macros, silent,
250+
extra_verbose=extra_verbose, build_profile=build_profile)
246251

247252
# Run-time values
248253
self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")])
@@ -251,8 +256,10 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
251256
class ARM_MICRO(ARM):
252257
PATCHED_LIBRARY = False
253258

254-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
255-
ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
259+
def __init__(self, target, options=None, notify=None, macros=None,
260+
silent=False, extra_verbose=False, build_profile=None):
261+
ARM.__init__(self, target, options, notify, macros, silent,
262+
extra_verbose=extra_verbose, build_profile=build_profile)
256263

257264
# Extend flags
258265
self.flags['common'].extend(["-D__MICROLIB"])

tools/toolchains/gcc.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ class GCC(mbedToolchain):
4646
"-Wl,--wrap,exit", "-Wl,--wrap,atexit"],
4747
}
4848

49-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path="", extra_verbose=False):
50-
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
49+
def __init__(self, target, options=None, notify=None, macros=None,
50+
silent=False, tool_path="", extra_verbose=False,
51+
build_profile=None):
52+
mbedToolchain.__init__(self, target, options, notify, macros, silent,
53+
extra_verbose=extra_verbose,
54+
build_profile=build_profile)
5155

5256
if target.core == "Cortex-M0+":
5357
cpu = "cortex-m0plus"
@@ -280,8 +284,11 @@ def check_executable():
280284
Returns False otherwise."""
281285
return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1)
282286

283-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
284-
GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose)
287+
def __init__(self, target, options=None, notify=None, macros=None,
288+
silent=False, extra_verbose=False, build_profile=None):
289+
GCC.__init__(self, target, options, notify, macros, silent,
290+
TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose,
291+
build_profile=build_profile)
285292

286293
# Use latest gcc nanolib
287294
if "std-lib" in self.options:
@@ -312,8 +319,11 @@ def check_executable():
312319
Returns False otherwise."""
313320
return mbedToolchain.generic_check_executable("GCC_CR", 'arm-none-eabi-gcc', 1)
314321

315-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
316-
GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose)
322+
def __init__(self, target, options=None, notify=None, macros=None,
323+
silent=False, extra_verbose=False, build_profile=None):
324+
GCC.__init__(self, target, options, notify, macros, silent,
325+
TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose,
326+
build_profile=build_profile)
317327

318328
additional_compiler_flags = [
319329
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",

tools/toolchains/iar.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ def check_executable():
5454
Returns False otherwise."""
5555
return mbedToolchain.generic_check_executable("IAR", 'iccarm', 2, "bin")
5656

57-
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
58-
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
57+
def __init__(self, target, options=None, notify=None, macros=None,
58+
silent=False, extra_verbose=False, build_profile=None):
59+
mbedToolchain.__init__(self, target, options, notify, macros, silent,
60+
extra_verbose=extra_verbose,
61+
build_profile=build_profile)
5962
if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD":
6063
cpuchoice = "Cortex-M7"
6164
else:

0 commit comments

Comments
 (0)