Skip to content

Change how the config system is used #2162

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
wants to merge 1 commit into from
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
3 changes: 3 additions & 0 deletions hal/api/mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#define MBED_LIBRARY_VERSION 121

// Include the configuration data as early as possible
#include "mbed_config.h"

#include "toolchain.h"
#include "platform.h"

Expand Down
2 changes: 1 addition & 1 deletion tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def load_resources(self, resources):
# (as returned by get_config_data())
@staticmethod
def config_to_header(config, fname = None):
params, macros = config[0], config[1]
params, macros = (config[0], config[1]) if config else ({}, {})
Config._check_required_parameters(params)
header_data = "// Automatically generated configuration file.\n"
header_data += "// DO NOT EDIT, content will be overwritten.\n\n"
Expand Down
2 changes: 0 additions & 2 deletions tools/export/atmelstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class AtmelStudio(Exporter):

DOT_IN_RELATIVE_PATH = True

MBED_CONFIG_HEADER_SUPPORTED = True

def generate(self):

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

MBED_CONFIG_HEADER_SUPPORTED = True

TARGETS = [
'LPC1768',
'LPC4088',
Expand Down
2 changes: 0 additions & 2 deletions tools/export/emblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ 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: 3 additions & 13 deletions tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ 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 @@ -49,9 +48,6 @@ 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)
return self._progen_flag_cache

def __scan_and_copy(self, src_path, trg_path):
Expand Down Expand Up @@ -166,20 +162,14 @@ def scan_and_copy_resources(self, prj_paths, trg_path, relative=False):
# use the prj_dir (source, not destination)
resources = self.toolchain.scan_resources(prj_paths[0])
for path in prj_paths[1:]:
resources.add(toolchain.scan_resources(path))
resources.add(self.toolchain.scan_resources(path))

# Loads the resources into the config system which might expand/modify resources based on config data
self.resources = config.load_resources(resources)

# Generate configuration header
config.get_config_data_header(join(trg_path, self.toolchain.MBED_CONFIG_FILE_NAME))

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: 0 additions & 2 deletions tools/export/gccarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ class GccArm(Exporter):

DOT_IN_RELATIVE_PATH = True

MBED_CONFIG_HEADER_SUPPORTED = True

def generate(self):
# "make" wants Unix paths
if self.sources_relative:
Expand Down
2 changes: 0 additions & 2 deletions tools/export/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ 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: 0 additions & 2 deletions tools/export/simplicityv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ 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
2 changes: 0 additions & 2 deletions tools/export/uvision4.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ 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
2 changes: 0 additions & 2 deletions tools/export/uvision5.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ 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
42 changes: 28 additions & 14 deletions tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,11 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
self.to_be_compiled = len(files_to_compile)
self.compiled = 0

inc_paths = resources.inc_dirs
# Create the configuration header and append its path to the include list
# "create_config_header" needs to know the build directory
self.build_dir = build_path
config_file_location = self.create_config_header()
inc_paths = resources.inc_dirs + [dirname(config_file_location)]
if inc_dirs is not None:
inc_paths.extend(inc_dirs)
# De-duplicate include paths
Expand All @@ -656,8 +660,6 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
inc_paths = sorted(set(inc_paths))
# Unique id of all include paths
self.inc_md5 = md5(' '.join(inc_paths)).hexdigest()
# Where to store response files
self.build_dir = build_path

objects = []
queue = []
Expand Down Expand Up @@ -944,18 +946,30 @@ def mem_stats(self, map):
def set_config_data(self, config_data):
self.config_data = config_data

# Return the location of the config header. This function will create the config
# header first if needed. The header will be written in a file called "mbed_conf.h"
# located in the project's build directory.
# If config headers are not used (self.config_header_content is None), the function
# returns None
def get_config_header(self):
if self.config_data is None:
return None
config_file = join(self.build_dir, self.MBED_CONFIG_FILE_NAME)
if not exists(config_file):
# Creates the configuration header if needed:
# - if there is no configuration data, an empty (no config data) "mbed_config.h" is created
# - if there is configuration data and "mbed_config.h" does not exist, it is created.
# - if there is configuration data similar to the previous configuration data,
# "mbed_config.h" is left untouched
# - if there is new configuration data, "mbed_config.h" is overriden
# basedir: the base directory for "mbed_config.h" (defaults to self.build.dir if not specified)
# The function returns the location of "mbed_config.h"
def create_config_header(self, basedir = None):
config_file = join(basedir or self.build_dir, self.MBED_CONFIG_FILE_NAME)
# If the file exists, read its current content in prev_data
if exists(config_file):
with open(config_file, "rt") as f:
prev_data = f.read()
else:
prev_data = None
# Get the current configuration data
crt_data = Config.config_to_header(self.config_data)
# Create the config file if it contains different data or if it doesn't exist
# (both conditions are covered by 'prev_data != crt_data', since crt_data can
# never be None).
if prev_data != crt_data:
with open(config_file, "wt") as f:
f.write(Config.config_to_header(self.config_data))
f.write(crt_data)
return config_file

# Return the list of macros geenrated by the build system
Expand Down
9 changes: 1 addition & 8 deletions tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,8 @@ 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 + self.get_config_option(config_header)
return opts
return ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)]

@hook_tool
def assemble(self, source, object, includes):
Expand Down
9 changes: 1 addition & 8 deletions tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,8 @@ 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 + self.get_config_option(config_header)
return opts
return ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)]

@hook_tool
def assemble(self, source, object, includes):
Expand Down
19 changes: 3 additions & 16 deletions tools/toolchains/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,13 @@ 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()
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 + self.get_config_option(config_header)
return opts
def get_compile_options(self, defines, includes):
return ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]

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

# Call cmdline hook
cmd = self.hook.get_cmdline_assembler(cmd)
Expand Down