Skip to content

Commit b4e8cf6

Browse files
author
Bogdan Marinescu
committed
Fixed config-related options for the IAR assembler
The IAR assembler doesn't accept '--preinclude', but it accepts -D. This commit changes the way the config-related macros are propagated to the IAR assembler to use '-D' instead of '--preinclude'. This is the only change related to functionality, the others are small, backward compatible changes to the config code to make passing arguments to the toolchain instances easier. Tested by compiled blinky with IAR, GCC_ARM and ARM for K64F.
1 parent 703aee4 commit b4e8cf6

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

tools/build_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def build_project(src_path, build_path, target, toolchain_name,
217217
# Load resources into the config system which might expand/modify resources based on config data
218218
resources = config.load_resources(resources)
219219

220-
# Set the toolchain's config header with the config data
221-
toolchain.set_config_header_content(config.get_config_data_header())
220+
# Set the toolchain's configuration data
221+
toolchain.set_config_data(config.get_config_data())
222222

223223
# Compile Sources
224224
objects = toolchain.compile_sources(resources, build_path, resources.inc_dirs)
@@ -361,8 +361,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
361361
# Load resources into the config system which might expand/modify resources based on config data
362362
resources = config.load_resources(resources)
363363

364-
# Set the toolchain's config header with the config data
365-
toolchain.set_config_header_content(config.get_config_data_header())
364+
# Set the toolchain's configuration data
365+
toolchain.set_config_data(config.get_config_data())
366366

367367
# Copy headers, objects and static libraries - all files needed for static lib
368368
toolchain.copy_files(resources.headers, build_path, resources=resources)

tools/config.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def get_config_data(self):
354354
return all_params, macros
355355

356356
# Helper: verify if there are any required parameters without a value in 'params'
357-
def _check_required_parameters(self, params):
357+
@staticmethod
358+
def _check_required_parameters(params):
358359
for p in params.values():
359360
if p.required and (p.value is None):
360361
raise ConfigException("Required parameter '%s' defined by '%s' doesn't have a value" % (p.name, p.defined_by))
@@ -371,11 +372,18 @@ def parameters_to_macros(params):
371372
def config_macros_to_macros(macros):
372373
return [m.name for m in macros.values()]
373374

375+
# Return the configuration data converted to a list of C macros
376+
# config - configuration data as (ConfigParam instances, ConfigMacro instances) tuple
377+
# (as returned by get_config_data())
378+
@staticmethod
379+
def config_to_macros(config):
380+
params, macros = config[0], config[1]
381+
Config._check_required_parameters(params)
382+
return Config.config_macros_to_macros(macros) + Config.parameters_to_macros(params)
383+
374384
# Return the configuration data converted to a list of C macros
375385
def get_config_data_macros(self):
376-
params, macros = self.get_config_data()
377-
self._check_required_parameters(params)
378-
return self.config_macros_to_macros(macros) + self.parameters_to_macros(params)
386+
return self.config_to_macros(self.get_config_data())
379387

380388
# Returns any features in the configuration data
381389
def get_features(self):
@@ -419,14 +427,16 @@ def load_resources(self, resources):
419427

420428
return resources
421429

422-
423430
# Return the configuration data converted to the content of a C header file,
424431
# meant to be included to a C/C++ file. The content is returned as a string.
425432
# If 'fname' is given, the content is also written to the file called "fname".
426433
# WARNING: if 'fname' names an existing file, that file will be overwritten!
427-
def get_config_data_header(self, fname = None):
428-
params, macros = self.get_config_data()
429-
self._check_required_parameters(params)
434+
# config - configuration data as (ConfigParam instances, ConfigMacro instances) tuple
435+
# (as returned by get_config_data())
436+
@staticmethod
437+
def config_to_header(config, fname = None):
438+
params, macros = config[0], config[1]
439+
Config._check_required_parameters(params)
430440
header_data = "// Automatically generated configuration file.\n"
431441
header_data += "// DO NOT EDIT, content will be overwritten.\n\n"
432442
header_data += "#ifndef __MBED_CONFIG_DATA__\n"
@@ -459,3 +469,10 @@ def get_config_data_header(self, fname = None):
459469
with open(fname, "wt") as f:
460470
f.write(header_data)
461471
return header_data
472+
473+
# Return the configuration data converted to the content of a C header file,
474+
# meant to be included to a C/C++ file. The content is returned as a string.
475+
# If 'fname' is given, the content is also written to the file called "fname".
476+
# WARNING: if 'fname' names an existing file, that file will be overwritten!
477+
def get_config_data_header(self, fname = None):
478+
return self.config_to_header(self.get_config_data(), fname)

tools/toolchains/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from os.path import join, splitext, exists, relpath, dirname, basename, split, abspath
2626
from inspect import getmro
2727
from copy import deepcopy
28+
from tools.config import Config
2829

2930
from multiprocessing import Pool, cpu_count
3031
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path
@@ -245,8 +246,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
245246
# Labels generated from toolchain and target rules/features (used for selective build)
246247
self.labels = None
247248

248-
# config_header_content will hold the content of the config header (if used)
249-
self.config_header_content = None
249+
# This will hold the configuration data (as returned by Config.get_config_data())
250+
self.config_data = None
250251

251252
# Non-incremental compile
252253
self.build_all = False
@@ -892,26 +893,27 @@ def mem_stats(self, map):
892893
map_csv = splitext(map)[0] + "_map.csv"
893894
memap.generate_output('csv-ci', map_csv)
894895

895-
# "Prefix headers" are automatically included by the compiler at the beginning of
896-
# each source file. They are used to provide configuration data.
897-
# header_content - the content of the config header file.
898-
def set_config_header_content(self, header_content):
899-
self.config_header_content = header_content
896+
# Set the configuration data
897+
def set_config_data(self, config_data):
898+
self.config_data = config_data
900899

901900
# Return the location of the config header. This function will create the config
902901
# header first if needed. The header will be written in a file called "mbed_conf.h"
903902
# located in the project's build directory.
904903
# If config headers are not used (self.config_header_content is None), the function
905904
# returns None
906905
def get_config_header(self):
907-
if self.config_header_content is None:
906+
if self.config_data is None:
908907
return None
909908
config_file = join(self.build_dir, "mbed_config.h")
910909
if not exists(config_file):
911910
with open(config_file, "wt") as f:
912-
f.write(self.config_header_content)
911+
f.write(Config.config_to_header(self.config_data))
913912
return config_file
914913

914+
# Return the list of macros geenrated by the build system
915+
def get_config_macros(self):
916+
return Config.config_to_macros(self.config_data) if self.config_data else []
915917

916918
from tools.settings import ARM_BIN
917919
from tools.settings import GCC_ARM_PATH, GCC_CR_PATH

tools/toolchains/iar.py

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

129-
def get_compile_options(self, defines, includes):
129+
def get_compile_options(self, defines, includes, for_asm=False):
130130
opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
131-
config_header = self.get_config_header()
132-
if config_header is not None:
133-
opts = opts + ['--preinclude', config_header]
131+
if for_asm:
132+
# The assembler doesn't support '--preinclude', so we need to add
133+
# the macros directly
134+
opts = opts + ['-D%s' % d for d in self.get_config_macros()]
135+
else:
136+
config_header = self.get_config_header()
137+
if config_header is not None:
138+
opts = opts + ['--preinclude', config_header]
134139
return opts
135140

136141
@hook_tool
137142
def assemble(self, source, object, includes):
138143
# Build assemble command
139-
cmd = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-o", object, source]
144+
cmd = self.asm + self.get_compile_options(self.get_symbols(), includes, for_asm=True) + ["-o", object, source]
140145

141146
# Call cmdline hook
142147
cmd = self.hook.get_cmdline_assembler(cmd)

0 commit comments

Comments
 (0)