Skip to content

[tools!] Allow command line passing of cflags #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
print e
else:
# Build
extra_flags = {'cflags': options.cflags, 'asmflags': options.asmflags,
'ldflags': options.ldflags, 'cxxflags': options.cxxflags}
for toolchain in toolchains:
for target in targets:
tt_id = "%s::%s" % (toolchain, target)
Expand All @@ -249,7 +251,8 @@
clean=options.clean,
archive=(not options.no_archive),
macros=options.macros,
name=options.artifact_name)
name=options.artifact_name,
extra_flags=extra_flags)
else:
lib_build_res = build_mbed_libs(mcu, toolchain,
options=options.options,
Expand Down
25 changes: 19 additions & 6 deletions tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def get_mbed_official_release(version):
def prepare_toolchain(src_paths, target, toolchain_name,
macros=None, options=None, clean=False, jobs=1,
notify=None, silent=False, verbose=False,
extra_verbose=False, config=None):
extra_verbose=False, config=None, extra_flags=None):
""" Prepares resource related objects - toolchain, target, config

Positional arguments:
Expand Down Expand Up @@ -318,6 +318,17 @@ def prepare_toolchain(src_paths, target, toolchain_name,
except KeyError:
raise KeyError("Toolchain %s not supported" % toolchain_name)

if extra_flags and 'cflags' in extra_flags:
toolchain.cc.extend(extra_flags['cflags'])
if extra_flags and 'cxxflags' in extra_flags:
toolchain.cppc.extend(extra_flags['cxxflags'])
if extra_flags and 'ldflags' in extra_flags:
toolchain.hook.hook_cmdline_linker(
lambda name, flags: flags + extra_flags['ldflags'])
if extra_flags and 'asmflags' in extra_flags:
toolchain.hook.hook_cmdline_assembler(
lambda name, flags: flags + extra_flags['asmflags'])

toolchain.config = config
toolchain.jobs = jobs
toolchain.build_all = clean
Expand Down Expand Up @@ -369,7 +380,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
clean=False, notify=None, verbose=False, name=None,
macros=None, inc_dirs=None, jobs=1, silent=False,
report=None, properties=None, project_id=None,
project_description=None, extra_verbose=False, config=None):
project_description=None, extra_verbose=False, config=None,
extra_flags=None):
""" Build a project. A project may be a test or a user program.

Positional arguments:
Expand Down Expand Up @@ -415,7 +427,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, target, toolchain_name, macros=macros, options=options,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose, config=config)
extra_verbose=extra_verbose, config=config, extra_flags=extra_flags)

# The first path will give the name to the library
if name is None:
Expand Down Expand Up @@ -489,7 +501,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
archive=True, notify=None, verbose=False, macros=None,
inc_dirs=None, jobs=1, silent=False, report=None,
properties=None, extra_verbose=False, project_id=None,
remove_config_header_file=False):
remove_config_header_file=False, extra_flags=None):
""" Build a library

Positional arguments:
Expand Down Expand Up @@ -539,7 +551,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, target, toolchain_name, macros=macros, options=options,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose)
extra_verbose=extra_verbose, extra_flags=extra_flags)

# The first path will give the name to the library
if name is None:
Expand Down Expand Up @@ -807,7 +819,8 @@ def build_lib(lib_id, target, toolchain_name, options=None, verbose=False,
# library
def build_mbed_libs(target, toolchain_name, options=None, verbose=False,
clean=False, macros=None, notify=None, jobs=1, silent=False,
report=None, properties=None, extra_verbose=False):
report=None, properties=None, extra_verbose=False,
extra_flags=None):
""" Function returns True is library was built and false if building was
skipped

Expand Down
5 changes: 4 additions & 1 deletion tools/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@
build_dir = options.build_dir

try:
extra_flags = {'cflags': options.cflags, 'asmflags': options.asmflags,
'ldflags': options.ldflags, 'cxxflags': options.cxxflags}
bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, test.dependencies, options.options,
linker_script=options.linker_script,
clean=options.clean,
Expand All @@ -268,7 +270,8 @@
silent=options.silent,
macros=options.macros,
jobs=options.jobs,
name=options.artifact_name)
name=options.artifact_name,
extra_flags=extra_flags)
print 'Image: %s'% bin_file

if options.disk:
Expand Down
4 changes: 4 additions & 0 deletions tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def get_default_options_parser(add_clean=True, add_options=True):
parser.add_argument("--cflags", default=[], action="append",
help="Extra flags to provide to the C compiler")

parser.add_argument("--cxxflags", default=[], dest="cxxflags",
action="append",
help="Extra flags to provide to the C++ compiler")

parser.add_argument("--asmflags", default=[], action="append",
help="Extra flags to provide to the assembler")

Expand Down
52 changes: 31 additions & 21 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,23 @@

library_build_success = False
try:
extra_flags = {'cflags': options.cflags, 'asmflags': options.asmflags,
'ldflags': options.ldflags,
'cxxflags': options.cxxflags}
# Build sources
build_library(base_source_paths, options.build_dir, mcu, toolchain,
options=options.options,
jobs=options.jobs,
clean=options.clean,
report=build_report,
properties=build_properties,
name="mbed-build",
macros=options.macros,
verbose=options.verbose,
notify=notify,
archive=False,
remove_config_header_file=True)
options=options.options,
jobs=options.jobs,
clean=options.clean,
report=build_report,
properties=build_properties,
name="mbed-build",
macros=options.macros,
verbose=options.verbose,
notify=notify,
archive=False,
extra_flags=extra_flags,
remove_config_header_file=True)

library_build_success = True
except ToolException, e:
Expand All @@ -195,16 +199,22 @@
print "Failed to build library"
else:
# Build all the tests
test_build_success, test_build = build_tests(tests, [options.build_dir], options.build_dir, mcu, toolchain,
options=options.options,
clean=options.clean,
report=build_report,
properties=build_properties,
macros=options.macros,
verbose=options.verbose,
notify=notify,
jobs=options.jobs,
continue_on_build_fail=options.continue_on_build_fail)
extra_flags = {'cflags': options.cflags,
'asmflags': options.asmflags,
'ldflags': options.ldflags,
'cxxflags': options.cxxflags}
test_build_success, test_build = build_tests(
tests, [options.build_dir], options.build_dir, mcu, toolchain,
options=options.options,
clean=options.clean,
report=build_report,
properties=build_properties,
macros=options.macros,
verbose=options.verbose,
notify=notify,
jobs=options.jobs,
continue_on_build_fail=options.continue_on_build_fail,
extra_flags=extra_flags)

# If a path to a test spec is provided, write it to a file
if options.test_spec:
Expand Down
9 changes: 5 additions & 4 deletions tools/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2058,9 +2058,9 @@ def norm_relative_path(path, start):
return path

def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
options=None, clean=False, notify=None, verbose=False, jobs=1,
macros=None, silent=False, report=None, properties=None,
continue_on_build_fail=False):
options=None, clean=False, notify=None, verbose=False, jobs=1,
macros=None, silent=False, report=None, properties=None,
continue_on_build_fail=False, extra_flags=None):
"""Given the data structure from 'find_tests' and the typical build parameters,
build all the tests

Expand Down Expand Up @@ -2101,7 +2101,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
project_id=test_name,
report=report,
properties=properties,
verbose=verbose)
verbose=verbose,
extra_flags=extra_flags)

except Exception, e:
if not isinstance(e, NotSupportedException):
Expand Down