Skip to content

[Exporters] Update exporters to include and use mbed_conf.h (Was #1964) #1975

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

Merged
merged 11 commits into from
Jun 28, 2016
Merged
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
2 changes: 2 additions & 0 deletions tools/export/atmelstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AtmelStudio(Exporter):

DOT_IN_RELATIVE_PATH = True

MBED_CONFIG_HEADER_SUPPORTED = True

def generate(self):

source_files = []
Expand Down
2 changes: 2 additions & 0 deletions tools/export/codered.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class CodeRed(Exporter):
NAME = 'CodeRed'
TOOLCHAIN = 'GCC_CR'

MBED_CONFIG_HEADER_SUPPORTED = True

TARGETS = [
'LPC1768',
'LPC4088',
Expand Down
2 changes: 2 additions & 0 deletions tools/export/emblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class IntermediateFile(Exporter):
# we support all GCC targets (is handled on IDE side)
TARGETS = gccTargets

MBED_CONFIG_HEADER_SUPPORTED = True

FILE_TYPES = {
'headers': 'h',
'c_sources': 'c',
Expand Down
16 changes: 13 additions & 3 deletions tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, target, inputDir, program_name, build_url_resolver, extra_sym
self.extra_symbols = extra_symbols
self.config_macros = []
self.sources_relative = sources_relative
self.config_header = None

def get_toolchain(self):
return self.TOOLCHAIN
Expand All @@ -48,6 +49,9 @@ def flags(self):
def progen_flags(self):
if not hasattr(self, "_progen_flag_cache") :
self._progen_flag_cache = dict([(key + "_flags", value) for key,value in self.flags.iteritems()])
if self.config_header:
self._progen_flag_cache['c_flags'] += self.toolchain.get_config_option(self.config_header)
self._progen_flag_cache['cxx_flags'] += self.toolchain.get_config_option(self.config_header)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that you might need to add this to ASM files as well, since some toolchains (like GCC) can preprocess the ASM file before invoking the assembler, and we use this feature in a few parts of the system. Not sure though if this is something that we want to enable for all toolchains or only for a few of them.

return self._progen_flag_cache

def __scan_and_copy(self, src_path, trg_path):
Expand Down Expand Up @@ -167,9 +171,15 @@ def scan_and_copy_resources(self, prj_paths, trg_path, relative=False):
# Loads the resources into the config system which might expand/modify resources based on config data
self.resources = config.load_resources(resources)

# And add the configuration macros to the toolchain
self.config_macros = config.get_config_data_macros()


if hasattr(self, "MBED_CONFIG_HEADER_SUPPORTED") and self.MBED_CONFIG_HEADER_SUPPORTED :
# Add the configuration file to the target directory
self.config_header = self.toolchain.MBED_CONFIG_FILE_NAME
config.get_config_data_header(join(trg_path, self.config_header))
self.config_macros = []
else :
# And add the configuration macros to the toolchain
self.config_macros = config.get_config_data_macros()
# Check the existence of a binary build of the mbed library for the desired target
# This prevents exporting the mbed libraries from source
# if not self.toolchain.mbed_libs:
Expand Down
2 changes: 2 additions & 0 deletions tools/export/gccarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class GccArm(Exporter):

DOT_IN_RELATIVE_PATH = True

MBED_CONFIG_HEADER_SUPPORTED = True

def generate(self):
# "make" wants Unix paths
self.resources.win_to_unix()
Expand Down
2 changes: 2 additions & 0 deletions tools/export/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class IAREmbeddedWorkbench(Exporter):
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
PROGEN_ACTIVE = True

MBED_CONFIG_HEADER_SUPPORTED = True

# backward compatibility with our scripts
TARGETS = []
for target in TARGET_NAMES:
Expand Down
2 changes: 2 additions & 0 deletions tools/export/simplicityv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class SimplicityV3(Exporter):

DOT_IN_RELATIVE_PATH = False

MBED_CONFIG_HEADER_SUPPORTED = True

orderedPaths = Folder("Root")

def check_and_add_path(self, path):
Expand Down
8 changes: 5 additions & 3 deletions tools/export/uvision4.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Uvision4(Exporter):
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
PROGEN_ACTIVE = True

MBED_CONFIG_HEADER_SUPPORTED = True

# backward compatibility with our scripts
TARGETS = []
for target in TARGET_NAMES:
Expand Down Expand Up @@ -69,16 +71,16 @@ def generate(self):
# get flags from toolchain and apply
project_data['tool_specific']['uvision']['misc'] = {}
# asm flags only, common are not valid within uvision project, they are armcc specific
project_data['tool_specific']['uvision']['misc']['asm_flags'] = list(set(self.toolchain.flags['asm']))
project_data['tool_specific']['uvision']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
# cxx flags included, as uvision have them all in one tab
project_data['tool_specific']['uvision']['misc']['c_flags'] = list(set(self.toolchain.flags['common'] + self.toolchain.flags['c'] + self.toolchain.flags['cxx']))
project_data['tool_specific']['uvision']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
# not compatible with c99 flag set in the template
project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--c99")
# ARM_INC is by default as system inclusion, not required for exported project
project_data['tool_specific']['uvision']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"")
# cpp is not required as it's implicit for cpp files
project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--cpp")
project_data['tool_specific']['uvision']['misc']['ld_flags'] = self.toolchain.flags['ld']
project_data['tool_specific']['uvision']['misc']['ld_flags'] = self.progen_flags['ld_flags']

i = 0
for macro in project_data['common']['macros']:
Expand Down
8 changes: 5 additions & 3 deletions tools/export/uvision5.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Uvision5(Exporter):
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
PROGEN_ACTIVE = True

MBED_CONFIG_HEADER_SUPPORTED = True

# backward compatibility with our scripts
TARGETS = []
for target in TARGET_NAMES:
Expand Down Expand Up @@ -69,16 +71,16 @@ def generate(self):
# get flags from toolchain and apply
project_data['tool_specific']['uvision5']['misc'] = {}
# asm flags only, common are not valid within uvision project, they are armcc specific
project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.toolchain.flags['asm']))
project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
# cxx flags included, as uvision have them all in one tab
project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(self.toolchain.flags['common'] + self.toolchain.flags['c'] + self.toolchain.flags['cxx']))
project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
# ARM_INC is by default as system inclusion, not required for exported project
project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"")
# not compatible with c99 flag set in the template
project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--c99")
# cpp is not required as it's implicit for cpp files
project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--cpp")
project_data['tool_specific']['uvision5']['misc']['ld_flags'] = self.toolchain.flags['ld']
project_data['tool_specific']['uvision5']['misc']['ld_flags'] = self.progen_flags['ld_flags']

i = 0
for macro in project_data['common']['macros']:
Expand Down
4 changes: 3 additions & 1 deletion tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ class mbedToolchain:
GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%"
GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?P<severity>warning) \[(?P<file>[^:]+):(?P<line>\d+)\] \- (?P<message>.*)"')

MBED_CONFIG_FILE_NAME="mbed_config.h"

def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
self.target = target
self.name = self.__class__.__name__
Expand Down Expand Up @@ -908,7 +910,7 @@ def set_config_data(self, config_data):
def get_config_header(self):
if self.config_data is None:
return None
config_file = join(self.build_dir, "mbed_config.h")
config_file = join(self.build_dir, self.MBED_CONFIG_FILE_NAME)
if not exists(config_file):
with open(config_file, "wt") as f:
f.write(Config.config_to_header(self.config_data))
Expand Down
5 changes: 4 additions & 1 deletion tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ def get_dep_option(self, object):
dep_path = base + '.d'
return ["--depend", dep_path]

def get_config_option(self, config_header) :
return ['--preinclude=' + config_header]

def get_compile_options(self, defines, includes):
opts = ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)]
config_header = self.get_config_header()
if config_header is not None:
opts = opts + ['--preinclude', config_header]
opts = opts + self.get_config_option(config_header)
return opts

@hook_tool
Expand Down
5 changes: 4 additions & 1 deletion tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ def get_dep_option(self, object):
dep_path = base + '.d'
return ["-MD", "-MF", dep_path]

def get_config_option(self, config_header):
return ['-include', config_header]

def get_compile_options(self, defines, includes):
opts = ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)]
config_header = self.get_config_header()
if config_header is not None:
opts = opts + ['-include', config_header]
opts = opts + self.get_config_option(config_header)
return opts

@hook_tool
Expand Down
6 changes: 5 additions & 1 deletion tools/toolchains/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,20 @@ def cc_extra(self, object):
base, _ = splitext(object)
return ["-l", base + '.s.txt']

def get_config_option(self, config_header):
return ['--preinclude=' + config_header]

def get_compile_options(self, defines, includes, for_asm=False):
opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
config_header = self.get_config_header()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated (see below in the else: block). Not a real problem though.

if for_asm:
# The assembler doesn't support '--preinclude', so we need to add
# the macros directly
opts = opts + ['-D%s' % d for d in self.get_config_macros()]
else:
config_header = self.get_config_header()
if config_header is not None:
opts = opts + ['--preinclude', config_header]
opts = opts + self.get_config_option(config_header)
return opts

@hook_tool
Expand Down