Skip to content

Fix usage of custom targets in applications and tests #2196

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 2 commits 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
4 changes: 2 additions & 2 deletions tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
dependencies_paths=None, options=None, name=None, clean=False, archive=True,
notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None,
jobs=1, silent=False, report=None, properties=None, extra_verbose=False,
project_id=None):
project_id=None, config=None):
""" src_path: the path of the source directory
build_path: the path of the build directory
target: ['LPC1768', 'LPC11U24', 'LPC2368']
Expand All @@ -284,7 +284,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
name = project_name

# If the configuration object was not yet created, create it now
config = Config(target, src_paths)
config = config or Config(target, src_paths)

# If the 'target' argument is a string, convert it to a target instance
if isinstance(target, basestring):
Expand Down
11 changes: 8 additions & 3 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Config:
# If it does, it'll update the list of targets if need.
# If found more than once, an exception is raised
# top_level_dirs can be None (in this case, mbed_app_config.json will not be searched)
def __init__(self, target, top_level_dirs = []):
def __init__(self, target = None, top_level_dirs = []):
app_config_location = None
for s in (top_level_dirs or []):
full_path = os.path.join(s, self.__mbed_app_config_name)
Expand All @@ -182,12 +182,17 @@ def __init__(self, target, top_level_dirs = []):
self.lib_config_data = {}
# Make sure that each config is processed only once
self.processed_configs = {}
self.target = target if isinstance(target, basestring) else target.name
self.target_labels = Target.get_target(self.target).get_labels()
self.set_target(target)
self.added_features = set()
self.removed_features = set()
self.removed_unecessary_features = False

# Set the target used by the config system
def set_target(self, target):
if target is not None:
self.target = target if isinstance(target, basestring) else target.name
self.target_labels = Target.get_target(self.target).get_labels()

# Add one or more configuration files
def add_config_files(self, flist):
for f in flist:
Expand Down
37 changes: 28 additions & 9 deletions tools/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,29 @@
from tools.build_api import mcu_toolchain_matrix
from utils import argparse_filestring_type
from utils import argparse_many
from argparse import ArgumentTypeError
from argparse import ArgumentTypeError, ArgumentParser
from tools.toolchains import mbedToolchain
from tools.settings import CLI_COLOR_MAP
from tools.config import Config

if __name__ == '__main__':
# Parse Options
# Options parsing is done in two steps:
# - step 1: parse only --source
# - step 2: parse the rest of the options
# This needs to happen because the configuration system can add new custom targets.
# The configuration system needs the list of source directories (given by --source) to look for
# mbed_app.json (where new targets can be defined).
# After the configuration is created, the list of targets is automatically updated if needed and
# the parsing can continue with a complete list of targets.
# Step 1: parse only --source
parser = ArgumentParser(add_help = False)
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
default=None, help="The source (input) directory", action="append")
prev_options, rest = parser.parse_known_args()
config = Config(top_level_dirs = prev_options.source_dir)
# Step 2: parse the rest of the options
# We still add "--source" option to the arguments to give users a complete help text,
# but we don't use its value anymore
parser = get_default_options_parser()
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("-p",
Expand Down Expand Up @@ -108,7 +125,7 @@
default=None, help="Required peripherals")
parser.add_argument("--dep", dest="dependencies",
default=None, help="Dependencies")
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
parser.add_argument("--source", dest="source_dir_not_used", type=argparse_filestring_type,
default=None, help="The source (input) directory", action="append")
parser.add_argument("--duration", type=int, dest="duration",
default=None, help="Duration of the test")
Expand Down Expand Up @@ -181,7 +198,7 @@
type=argparse_filestring_type,
default=None, help="use the specified linker script")

options = parser.parse_args()
options = parser.parse_args(rest)

# Only prints matrix of supported toolchains
if options.supported_toolchains:
Expand All @@ -194,7 +211,7 @@
sys.exit()

# force program to "0" if a source dir is specified
if options.source_dir is not None:
if prev_options.source_dir is not None:
p = 0
else:
# Program Number or name
Expand All @@ -208,6 +225,7 @@
if options.mcu is None :
args_error(parser, "[ERROR] You should specify an MCU")
mcu = options.mcu[0]
config.set_target(mcu)

# Toolchain
if options.tool is None:
Expand Down Expand Up @@ -251,9 +269,9 @@
if options.testlib: test.dependencies.append(TEST_MBED_LIB)

build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
if options.source_dir is not None:
test.source_dir = options.source_dir
build_dir = options.source_dir
if prev_options.source_dir is not None:
test.source_dir = prev_options.source_dir
build_dir = prev_options.source_dir

if options.build_dir is not None:
build_dir = options.build_dir
Expand All @@ -267,7 +285,8 @@
silent=options.silent,
macros=options.macros,
jobs=options.jobs,
name=options.artifact_name)
name=options.artifact_name,
config=config)
print 'Image: %s'% bin_file

if options.disk:
Expand Down
34 changes: 28 additions & 6 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,29 @@
from utils import argparse_filestring_type, argparse_lowercase_type, argparse_many
from tools.toolchains import mbedToolchain
from tools.settings import CLI_COLOR_MAP
from argparse import ArgumentParser
from tools.config import Config

if __name__ == '__main__':
try:
# Parse Options
# Options parsing is done in two steps:
# - step 1: parse only --source
# - step 2: parse the rest of the options
# This needs to happen because the configuration system can add new custom targets.
# The configuration system needs the list of source directories (given by --source) to look for
# mbed_app.json (where new targets can be defined).
# After the configuration is created, the list of targets is automatically updated if needed and
# the parsing can continue with a complete list of targets.
# Step 1: parse only --source
parser = ArgumentParser(add_help = False)
parser.add_argument("--source", dest="source_dir",
type=argparse_filestring_type,
default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append")
prev_options, rest = parser.parse_known_args()
config = Config(top_level_dirs = prev_options.source_dir)
# Step 2: parse the rest of the options
# We still add "--source" option to the arguments to give users a complete help text,
# but we don't use its value anymore
parser = get_default_options_parser()

parser.add_argument("-D",
Expand All @@ -53,7 +72,7 @@
default=0,
help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")

parser.add_argument("--source", dest="source_dir",
parser.add_argument("--source", dest="source_dir_not_used",
type=argparse_filestring_type,
default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append")

Expand Down Expand Up @@ -93,7 +112,7 @@
default=False,
help="Verbose diagnostic output")

options = parser.parse_args()
options = parser.parse_args(rest)

# Filter tests by path if specified
if options.paths:
Expand Down Expand Up @@ -144,14 +163,15 @@
print "[ERROR] You must specify a build path"
sys.exit(1)

base_source_paths = options.source_dir
base_source_paths = prev_options.source_dir

# Default base source path is the current directory
if not base_source_paths:
base_source_paths = ['.']


target = options.mcu[0]
config.set_target(target)

build_report = {}
build_properties = {}
Expand All @@ -169,7 +189,8 @@
macros=options.macros,
verbose=options.verbose,
notify=notify,
archive=False)
archive=False,
config=config)

library_build_success = True
except ToolException, e:
Expand All @@ -195,7 +216,8 @@
verbose=options.verbose,
notify=notify,
jobs=options.jobs,
continue_on_build_fail=options.continue_on_build_fail)
continue_on_build_fail=options.continue_on_build_fail,
config=config)

# If a path to a test spec is provided, write it to a file
if options.test_spec:
Expand Down
5 changes: 3 additions & 2 deletions tools/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ def norm_relative_path(path, start):
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):
continue_on_build_fail=False, config=None):
"""Given the data structure from 'find_tests' and the typical build parameters,
build all the tests

Expand Down Expand Up @@ -2081,7 +2081,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
name=test_name,
report=report,
properties=properties,
verbose=verbose)
verbose=verbose,
config=config)

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