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
Changes from 1 commit
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
Next Next commit
Fixes to function caching in targets.py
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.
  • Loading branch information
theotherjimmy authored and Bogdan Marinescu committed Jul 12, 2016
commit 50dbce9e74018bf41f93dbd65969f4a49e8335f5
14 changes: 5 additions & 9 deletions tools/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,16 @@ class HookError(Exception):
caches = {}
def cached(func):
def wrapper(*args, **kwargs):
if not caches.has_key(func):
caches[func] = func(*args, **kwargs)
return caches[func]
if not caches.has_key((func.__name__, args)):
caches[(func.__name__, args)] = func(*args, **kwargs)
return caches[(func.__name__, args)]
return wrapper

class Target:
# Cumulative attributes can have values appended to them, so they
# need to be computed differently than regular attributes
__cumulative_attributes = ['extra_labels', 'macros', 'device_has', 'features']

# {target_name: target_instance} map for all the targets in the system
__target_map = {}

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

Expand Down Expand Up @@ -200,10 +197,9 @@ def add_py_targets(new_targets):

# Return the target instance starting from the target name
@staticmethod
@cached
def get_target(name):
if not Target.__target_map.has_key(name):
Target.__target_map[name] = Target(name)
return Target.__target_map[name]
return Target(name)

def __init__(self, name):
self.name = name
Expand Down