Skip to content

Commit af71d87

Browse files
authored
Merge pull request #1975 from theotherjimmy/export-mbed-conf
[Exporters] Update exporters to include and use mbed_conf.h (Was #1964)
2 parents 05b8db4 + 8e11fa2 commit af71d87

File tree

13 files changed

+51
-13
lines changed

13 files changed

+51
-13
lines changed

tools/export/atmelstudio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class AtmelStudio(Exporter):
3333

3434
DOT_IN_RELATIVE_PATH = True
3535

36+
MBED_CONFIG_HEADER_SUPPORTED = True
37+
3638
def generate(self):
3739

3840
source_files = []

tools/export/codered.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class CodeRed(Exporter):
2222
NAME = 'CodeRed'
2323
TOOLCHAIN = 'GCC_CR'
2424

25+
MBED_CONFIG_HEADER_SUPPORTED = True
26+
2527
TARGETS = [
2628
'LPC1768',
2729
'LPC4088',

tools/export/emblocks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class IntermediateFile(Exporter):
3131
# we support all GCC targets (is handled on IDE side)
3232
TARGETS = gccTargets
3333

34+
MBED_CONFIG_HEADER_SUPPORTED = True
35+
3436
FILE_TYPES = {
3537
'headers': 'h',
3638
'c_sources': 'c',

tools/export/exporters.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, target, inputDir, program_name, build_url_resolver, extra_sym
3636
self.extra_symbols = extra_symbols
3737
self.config_macros = []
3838
self.sources_relative = sources_relative
39+
self.config_header = None
3940

4041
def get_toolchain(self):
4142
return self.TOOLCHAIN
@@ -48,6 +49,9 @@ def flags(self):
4849
def progen_flags(self):
4950
if not hasattr(self, "_progen_flag_cache") :
5051
self._progen_flag_cache = dict([(key + "_flags", value) for key,value in self.flags.iteritems()])
52+
if self.config_header:
53+
self._progen_flag_cache['c_flags'] += self.toolchain.get_config_option(self.config_header)
54+
self._progen_flag_cache['cxx_flags'] += self.toolchain.get_config_option(self.config_header)
5155
return self._progen_flag_cache
5256

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

170-
# And add the configuration macros to the toolchain
171-
self.config_macros = config.get_config_data_macros()
172-
174+
175+
if hasattr(self, "MBED_CONFIG_HEADER_SUPPORTED") and self.MBED_CONFIG_HEADER_SUPPORTED :
176+
# Add the configuration file to the target directory
177+
self.config_header = self.toolchain.MBED_CONFIG_FILE_NAME
178+
config.get_config_data_header(join(trg_path, self.config_header))
179+
self.config_macros = []
180+
else :
181+
# And add the configuration macros to the toolchain
182+
self.config_macros = config.get_config_data_macros()
173183
# Check the existence of a binary build of the mbed library for the desired target
174184
# This prevents exporting the mbed libraries from source
175185
# if not self.toolchain.mbed_libs:

tools/export/gccarm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class GccArm(Exporter):
121121

122122
DOT_IN_RELATIVE_PATH = True
123123

124+
MBED_CONFIG_HEADER_SUPPORTED = True
125+
124126
def generate(self):
125127
# "make" wants Unix paths
126128
self.resources.win_to_unix()

tools/export/iar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class IAREmbeddedWorkbench(Exporter):
3333
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
3434
PROGEN_ACTIVE = True
3535

36+
MBED_CONFIG_HEADER_SUPPORTED = True
37+
3638
# backward compatibility with our scripts
3739
TARGETS = []
3840
for target in TARGET_NAMES:

tools/export/simplicityv3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class SimplicityV3(Exporter):
101101

102102
DOT_IN_RELATIVE_PATH = False
103103

104+
MBED_CONFIG_HEADER_SUPPORTED = True
105+
104106
orderedPaths = Folder("Root")
105107

106108
def check_and_add_path(self, path):

tools/export/uvision4.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Uvision4(Exporter):
3434
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
3535
PROGEN_ACTIVE = True
3636

37+
MBED_CONFIG_HEADER_SUPPORTED = True
38+
3739
# backward compatibility with our scripts
3840
TARGETS = []
3941
for target in TARGET_NAMES:
@@ -69,16 +71,16 @@ def generate(self):
6971
# get flags from toolchain and apply
7072
project_data['tool_specific']['uvision']['misc'] = {}
7173
# asm flags only, common are not valid within uvision project, they are armcc specific
72-
project_data['tool_specific']['uvision']['misc']['asm_flags'] = list(set(self.toolchain.flags['asm']))
74+
project_data['tool_specific']['uvision']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
7375
# cxx flags included, as uvision have them all in one tab
74-
project_data['tool_specific']['uvision']['misc']['c_flags'] = list(set(self.toolchain.flags['common'] + self.toolchain.flags['c'] + self.toolchain.flags['cxx']))
76+
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']))
7577
# not compatible with c99 flag set in the template
7678
project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--c99")
7779
# ARM_INC is by default as system inclusion, not required for exported project
7880
project_data['tool_specific']['uvision']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"")
7981
# cpp is not required as it's implicit for cpp files
8082
project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--cpp")
81-
project_data['tool_specific']['uvision']['misc']['ld_flags'] = self.toolchain.flags['ld']
83+
project_data['tool_specific']['uvision']['misc']['ld_flags'] = self.progen_flags['ld_flags']
8284

8385
i = 0
8486
for macro in project_data['common']['macros']:

tools/export/uvision5.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Uvision5(Exporter):
3434
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
3535
PROGEN_ACTIVE = True
3636

37+
MBED_CONFIG_HEADER_SUPPORTED = True
38+
3739
# backward compatibility with our scripts
3840
TARGETS = []
3941
for target in TARGET_NAMES:
@@ -69,16 +71,16 @@ def generate(self):
6971
# get flags from toolchain and apply
7072
project_data['tool_specific']['uvision5']['misc'] = {}
7173
# asm flags only, common are not valid within uvision project, they are armcc specific
72-
project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.toolchain.flags['asm']))
74+
project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
7375
# cxx flags included, as uvision have them all in one tab
74-
project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(self.toolchain.flags['common'] + self.toolchain.flags['c'] + self.toolchain.flags['cxx']))
76+
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']))
7577
# ARM_INC is by default as system inclusion, not required for exported project
7678
project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"")
7779
# not compatible with c99 flag set in the template
7880
project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--c99")
7981
# cpp is not required as it's implicit for cpp files
8082
project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--cpp")
81-
project_data['tool_specific']['uvision5']['misc']['ld_flags'] = self.toolchain.flags['ld']
83+
project_data['tool_specific']['uvision5']['misc']['ld_flags'] = self.progen_flags['ld_flags']
8284

8385
i = 0
8486
for macro in project_data['common']['macros']:

tools/toolchains/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ class mbedToolchain:
227227
GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%"
228228
GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?P<severity>warning) \[(?P<file>[^:]+):(?P<line>\d+)\] \- (?P<message>.*)"')
229229

230+
MBED_CONFIG_FILE_NAME="mbed_config.h"
231+
230232
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
231233
self.target = target
232234
self.name = self.__class__.__name__
@@ -908,7 +910,7 @@ def set_config_data(self, config_data):
908910
def get_config_header(self):
909911
if self.config_data is None:
910912
return None
911-
config_file = join(self.build_dir, "mbed_config.h")
913+
config_file = join(self.build_dir, self.MBED_CONFIG_FILE_NAME)
912914
if not exists(config_file):
913915
with open(config_file, "wt") as f:
914916
f.write(Config.config_to_header(self.config_data))

tools/toolchains/arm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,14 @@ def get_dep_option(self, object):
114114
dep_path = base + '.d'
115115
return ["--depend", dep_path]
116116

117+
def get_config_option(self, config_header) :
118+
return ['--preinclude=' + config_header]
119+
117120
def get_compile_options(self, defines, includes):
118121
opts = ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)]
119122
config_header = self.get_config_header()
120123
if config_header is not None:
121-
opts = opts + ['--preinclude', config_header]
124+
opts = opts + self.get_config_option(config_header)
122125
return opts
123126

124127
@hook_tool

tools/toolchains/gcc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,14 @@ def get_dep_option(self, object):
165165
dep_path = base + '.d'
166166
return ["-MD", "-MF", dep_path]
167167

168+
def get_config_option(self, config_header):
169+
return ['-include', config_header]
170+
168171
def get_compile_options(self, defines, includes):
169172
opts = ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)]
170173
config_header = self.get_config_header()
171174
if config_header is not None:
172-
opts = opts + ['-include', config_header]
175+
opts = opts + self.get_config_option(config_header)
173176
return opts
174177

175178
@hook_tool

tools/toolchains/iar.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,20 @@ def cc_extra(self, object):
126126
base, _ = splitext(object)
127127
return ["-l", base + '.s.txt']
128128

129+
def get_config_option(self, config_header):
130+
return ['--preinclude=' + config_header]
131+
129132
def get_compile_options(self, defines, includes, for_asm=False):
130133
opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
134+
config_header = self.get_config_header()
131135
if for_asm:
132136
# The assembler doesn't support '--preinclude', so we need to add
133137
# the macros directly
134138
opts = opts + ['-D%s' % d for d in self.get_config_macros()]
135139
else:
136140
config_header = self.get_config_header()
137141
if config_header is not None:
138-
opts = opts + ['--preinclude', config_header]
142+
opts = opts + self.get_config_option(config_header)
139143
return opts
140144

141145
@hook_tool

0 commit comments

Comments
 (0)