Skip to content

Removed custom targets from config system #2691

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 2 commits into from
Sep 14, 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
18 changes: 0 additions & 18 deletions docs/config_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,6 @@ For example, an application may want to remove features with extra space or runt
}
```

## Custom targets

Application configuration can optionally define application-specific targets. These are mbed targets that are needed just to compile this specific application, so it doesn't make sense to add them to the list of official mbed targets; on the contrary, since they're part of `mbed_app.json`, they're versioned together with the application and only known by the application. Application-specific targets are defined with the key `custom_targets` in the `mbed_app.json` file and have the same syntax as a regular target definition, for example:


```
{
"custom_targets": {
"k64f_myapp": {
"inherits": ["K64F"],
"extra_labels_add": ["CUSTOM_K64F_LIB"]
}
}
}
```

This will define a new target named `k64f_myapp` that inherits from the `K64F` mbed target, but with an extra label defined, which will change the way the build system looks for sources in the tree.

# Configuration data precedence

The order in which the various bits of configurations are considered is this:
Expand Down
11 changes: 4 additions & 7 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class Config(object):
__allowed_keys = {
"library": set(["name", "config", "target_overrides", "macros",
"__config_path"]),
"application": set(["config", "custom_targets", "target_overrides",
"application": set(["config", "target_overrides",
"macros", "__config_path"])
}

Expand All @@ -363,11 +363,9 @@ def __init__(self, target, top_level_dirs=None, app_config=None):
app_config - location of a chosen mbed_app.json file

NOTE: Construction of a Config object will look for the application
configuration file in top_level_dirs. If found once, it'll parse it and
check if it has a custom_targets function. If it does, it'll update the
list of targets as needed. If more than one config file is found, an
exception is raised. top_level_dirs may be None (in this case,
the constructor will not search for a configuration file)
configuration file in top_level_dirs. If found once, it'll parse it.
top_level_dirs may be None (in this case, the constructor will not
search for a configuration file).
"""
app_config_location = app_config
if app_config_location is None:
Expand Down Expand Up @@ -396,7 +394,6 @@ def __init__(self, target, top_level_dirs=None, app_config=None):
self.__mbed_app_config_name))
# Update the list of targets with the ones defined in the application
# config, if applicable
Target.add_py_targets(self.app_config_data.get("custom_targets", {}))
self.lib_config_data = {}
# Make sure that each config is processed only once
self.processed_configs = {}
Expand Down
24 changes: 0 additions & 24 deletions tools/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ class Target(object):
# need to be computed differently than regular attributes
cumulative_attributes = ['extra_labels', 'macros', 'device_has', 'features']

# List of targets that were added dynamically using "add_py_targets" (see
# below)
__py_targets = set()

# Default location of the 'targets.json' file
__targets_json_location_default = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', 'hal', 'targets.json')
Expand Down Expand Up @@ -226,26 +222,6 @@ def __getattr__(self, attrname):
self.__dict__[attrname] = result
return result

@staticmethod
def add_py_targets(new_targets):
"""Add one or more new target(s) represented as a Python dictionary
in 'new_targets'. It is an error to add a target with a name that
already exists.
"""
crt_data = Target.get_json_target_data()
for target_key, target_value in new_targets.items():
if crt_data.has_key(target_key):
raise Exception(
"Attempt to add target '%s' that already exists"
% target_key)
# Add target data to the internal target dictionary
crt_data[target_key] = target_value
# Create the new target and add it to the relevant data structures
new_target = Target(target_key)
TARGETS.append(new_target)
TARGET_MAP[target_key] = new_target
TARGET_NAMES.append(target_key)

@staticmethod
@cached
def get_target(target_name):
Expand Down
8 changes: 6 additions & 2 deletions tools/test/config_test/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ def test_tree(full_name, name):
if "test_data" in sys.modules:
del sys.modules["test_data"]
import test_data
# If the test defines custom targets, they must exist in a file called
# "targets.json" in the test's directory.
if os.path.isfile(os.path.join(full_name, "targets.json")):
set_targets_json_location(os.path.join(full_name, "targets.json"))
else: # uset the regular set of targets
set_targets_json_location()
for target, expected in test_data.expected_results.items():
sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target))
sys.stdout.flush()
err_msg = None
try:
# Use 'set_targets_json_location' to remove the previous custom targets from the target list
set_targets_json_location(Target._Target__targets_json_location)
cfg, macros, features = get_config(full_name, target, "GCC_ARM")
macros = Config.config_macros_to_macros(macros)
except ConfigException as e:
Expand Down
43 changes: 0 additions & 43 deletions tools/test/config_test/test01/mbed_app.json

This file was deleted.

42 changes: 42 additions & 0 deletions tools/test/config_test/test01/targets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"b1": {
"extra_labels": [],
"default_lib": "std",
"core": "Cortex-M0",
"config": {
"base1_1": "v_base1_1_b1",
"base1_2": "v_base1_2_b1",
"base1_3": "v_base1_3_b1"
}
},
"d1": {
"inherits": ["b1"],
"config": {
"derived1": "v_derived1_d1",
"derived2": "v_derived2_d1"
},
"overrides": {
"base1_1": "v_base1_1_d1",
"base1_2": "v_base1_2_d1"
}
},
"b2": {
"config": {
"base2_1": "v_base2_1_b2",
"base2_2": "v_base2_2_b2"
}
},
"f": {
"inherits": ["b2", "d1"],
"config": {
"f1_1": "v_f1_1_f",
"f1_2": "v_f1_2_f"
},
"overrides": {
"base2_1": "v_base2_1_f",
"base1_1": "v_base1_1_f",
"derived2": "v_derived2_f",
"f1_1": "v_f1_1_f_override"
}
}
}
47 changes: 0 additions & 47 deletions tools/test/config_test/test02/mbed_app.json

This file was deleted.

46 changes: 46 additions & 0 deletions tools/test/config_test/test02/targets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"b1": {
"extra_labels": [],
"default_lib": "std",
"core": "Cortex-M0",
"config": {
"base1_1": "v_base1_1_b1",
"base1_2": "v_base1_2_b1",
"base1_3": "v_base1_3_b1"
}
},
"d1": {
"inherits": ["b1"],
"config": {
"derived1": "v_derived1_d1",
"derived2": "v_derived2_d1"
},
"overrides": {
"base1_1": "v_base1_1_d1",
"base1_2": "v_base1_2_d1"
}
},
"b2": {
"inherits": ["b1"],
"config": {
"base2_1": "v_base2_1_b2",
"base2_2": "v_base2_2_b2"
},
"overrides": {
"base1_2": "v_base1_2_b2"
}
},
"f": {
"inherits": ["d1", "b2"],
"config": {
"f1_1": "v_f1_1_f",
"f1_2": "v_f1_2_f"
},
"overrides": {
"base2_1": "v_base2_1_f",
"base1_1": "v_base1_1_f",
"derived2": "v_derived2_f",
"f1_1": "v_f1_1_f_override"
}
}
}
46 changes: 0 additions & 46 deletions tools/test/config_test/test03/mbed_app.json

This file was deleted.

45 changes: 45 additions & 0 deletions tools/test/config_test/test03/targets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"b1": {
"extra_labels": [],
"default_lib": "std",
"core": "Cortex-M0",
"config": {
"base1_1": "v_base1_1_b1",
"base1_2": "v_base1_2_b1",
"base1_3": "v_base1_3_b1"
}
},
"d1": {
"inherits": ["b1"],
"config": {
"derived1": "v_derived1_d1",
"derived2": "v_derived2_d1"
},
"overrides": {
"base1_1": "v_base1_1_d1",
"base1_2": "v_base1_2_d1"
}
},
"b2": {
"config": {
"base2_1": "v_base2_1_b2",
"base2_2": "v_base2_2_b2"
},
"overrides": {
"base1_1": "v_base1_1_b2"
}
},
"f": {
"inherits": ["b2", "d1"],
"config": {
"f1_1": "v_f1_1_f",
"f1_2": "v_f1_2_f"
},
"overrides": {
"base2_1": "v_base2_1_f",
"base1_1": "v_base1_1_f",
"derived2": "v_derived2_f",
"f1_1": "v_f1_1_f_override"
}
}
}
Loading