Skip to content
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

Fix targets py #2148

Merged
merged 3 commits into from
Jul 12, 2016
Merged

Fix targets py #2148

merged 3 commits into from
Jul 12, 2016

Conversation

bogdanm
Copy link
Contributor

@bogdanm bogdanm commented Jul 12, 2016

  1. Fixes to caching function results in targets.py
  2. Added the ability to use a different targets.json with targets.py

theotherjimmy and others added 2 commits July 12, 2016 13:03
Now funnctions are looked up in the cache using a (function name,
arguments) key, which makes it possible to cache different invocations
of the functions (with different arguments).
Also applied the @cached attribute to get_target.
With this change, it becomes possible to use targets.py with any
targets.json, not just the default one in ../hal/targets.json.
targets.py will still be initialized with the default targets.json, but
the code can then call "set_targets_json_location" to specify the new
location of targets.json. set_targets_json_location modifies all the
data "in place"; that is, it doesn't create a new TARGET_MAP,
TARGET_NAMES or alike, but rather modified the existing ones. This is
important, because code using this construct:

from tools.targets import TARGET_MAP

can work unmodified with this change.
@bogdanm
Copy link
Contributor Author

bogdanm commented Jul 12, 2016

@screamerbg @theotherjimmy

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 12, 2016

0.24s$ PYTHONPATH=. python tools/test/config_test/config_test.py
test01:'test single target inheritance'(d1) Traceback (most recent call last):
  File "tools/test/config_test/config_test.py", line 103, in <module>
    failed += test_tree(full_name, test_name)
  File "tools/test/config_test/config_test.py", line 46, in test_tree
    cfg, macros, features = get_config(full_name, target, "GCC_ARM")
  File "/home/travis/build/mbedmicro/mbed/tools/build_api.py", line 88, in get_config
    config = Config(target, src_paths)
  File "/home/travis/build/mbedmicro/mbed/tools/config.py", line 181, in __init__
    Target.add_py_targets(self.app_config_data.get("custom_targets", {}))
  File "/home/travis/build/mbedmicro/mbed/tools/targets.py", line 193, in add_py_targets
    old_target = Target.__target_map.get(tk, None)
AttributeError: class Target has no attribute '_Target__target_map'

Previously, add_py_targets assumed that it is not an error to add an
existing target if that target was previously added using
add_py_targets. This was done to aid testing, but it was weird, error
prone and broke with the latest changes to the caching mechanism. With
this commit:

- it is always an error to add a target that was previously added, which
  is much more consistent.
- tests for the configuration mechanism use the newly added
  'set_targets_json_location' function to clear the internal caches in
  targets.py (and thus all previously added custom targets). As a side
  effect, this commit also tests the 'set_targets_json_location'
  function itself.
@bogdanm
Copy link
Contributor Author

bogdanm commented Jul 12, 2016

Thanks, @0xc0170! Fixed in the latest commit.

@theotherjimmy
Copy link
Contributor

👍 thanks for the credit!

@bogdanm bogdanm merged commit 99dbc8b into master Jul 12, 2016
@bogdanm bogdanm deleted the fix_targets_py branch July 12, 2016 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants