Benjamin Schubert pushed to branch bschubert/optimize-sort at BuildStream / buildstream
Commits:
-
ac16ef17
by Benjamin Schubert at 2019-01-30T17:07:05Z
3 changed files:
Changes:
... | ... | @@ -79,7 +79,7 @@ class LoadElement(): |
79 | 79 |
])
|
80 | 80 |
|
81 | 81 |
# Extract the Dependencies
|
82 |
- self.deps = _extract_depends_from_node(self.node)
|
|
82 |
+ self.deps = _extract_depends_from_node(self.node, loader=self._loader)
|
|
83 | 83 |
|
84 | 84 |
# depends():
|
85 | 85 |
#
|
... | ... | @@ -132,11 +132,11 @@ class LoadElement(): |
132 | 132 |
# Returns:
|
133 | 133 |
# (list): a list of Dependency objects
|
134 | 134 |
#
|
135 |
-def _extract_depends_from_node(node, *, key=None):
|
|
135 |
+def _extract_depends_from_node(node, *, loader, key=None):
|
|
136 | 136 |
if key is None:
|
137 |
- build_depends = _extract_depends_from_node(node, key=Symbol.BUILD_DEPENDS)
|
|
138 |
- runtime_depends = _extract_depends_from_node(node, key=Symbol.RUNTIME_DEPENDS)
|
|
139 |
- depends = _extract_depends_from_node(node, key=Symbol.DEPENDS)
|
|
137 |
+ build_depends = _extract_depends_from_node(node, loader=loader, key=Symbol.BUILD_DEPENDS)
|
|
138 |
+ runtime_depends = _extract_depends_from_node(node, loader=loader, key=Symbol.RUNTIME_DEPENDS)
|
|
139 |
+ depends = _extract_depends_from_node(node, loader=loader, key=Symbol.DEPENDS)
|
|
140 | 140 |
return build_depends + runtime_depends + depends
|
141 | 141 |
elif key == Symbol.BUILD_DEPENDS:
|
142 | 142 |
default_dep_type = Symbol.BUILD
|
... | ... | @@ -154,7 +154,7 @@ def _extract_depends_from_node(node, *, key=None): |
154 | 154 |
dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index])
|
155 | 155 |
|
156 | 156 |
if isinstance(dep, str):
|
157 |
- dependency = Dependency(dep, provenance=dep_provenance, dep_type=default_dep_type)
|
|
157 |
+ dependency = Dependency(dep, loader=loader, provenance=dep_provenance, dep_type=default_dep_type)
|
|
158 | 158 |
|
159 | 159 |
elif isinstance(dep, Mapping):
|
160 | 160 |
if default_dep_type:
|
... | ... | @@ -176,6 +176,7 @@ def _extract_depends_from_node(node, *, key=None): |
176 | 176 |
filename = _yaml.node_get(dep, str, Symbol.FILENAME)
|
177 | 177 |
junction = _yaml.node_get(dep, str, Symbol.JUNCTION, default_value=None)
|
178 | 178 |
dependency = Dependency(filename,
|
179 |
+ loader=loader,
|
|
179 | 180 |
dep_type=dep_type,
|
180 | 181 |
junction=junction,
|
181 | 182 |
provenance=dep_provenance)
|
... | ... | @@ -125,7 +125,7 @@ class Loader(): |
125 | 125 |
junction, name, loader = self._parse_name(target, rewritable, ticker,
|
126 | 126 |
fetch_subprojects=fetch_subprojects)
|
127 | 127 |
loader._load_file(name, rewritable, ticker, fetch_subprojects, yaml_cache)
|
128 |
- deps.append(Dependency(name, junction=junction))
|
|
128 |
+ deps.append(Dependency(name, junction=junction, loader=loader))
|
|
129 | 129 |
profile_end(Topics.LOAD_PROJECT, target)
|
130 | 130 |
|
131 | 131 |
#
|
... | ... | @@ -318,7 +318,10 @@ class Loader(): |
318 | 318 |
deps_names = [dep.name for dep in element.deps]
|
319 | 319 |
self._warn_invalid_elements(deps_names)
|
320 | 320 |
|
321 |
- element.deps.sort(key=cmp_to_key(sort_deps))
|
|
321 |
+ def sort_by_load_index(dep_a, dep_b):
|
|
322 |
+ return dep_a.index - dep_b.index
|
|
323 |
+ |
|
324 |
+ element.deps.sort(key=cmp_to_key(sort_by_load_index))
|
|
322 | 325 |
|
323 | 326 |
element.index = next(element.next_id)
|
324 | 327 |
|
... | ... | @@ -56,9 +56,14 @@ class Symbol(): |
56 | 56 |
# dependency was declared
|
57 | 57 |
#
|
58 | 58 |
class Dependency():
|
59 |
- def __init__(self, name,
|
|
59 |
+ def __init__(self, name, loader,
|
|
60 | 60 |
dep_type=None, junction=None, provenance=None):
|
61 | 61 |
self.name = name
|
62 |
+ self.loader = loader
|
|
62 | 63 |
self.dep_type = dep_type
|
63 | 64 |
self.junction = junction
|
64 | 65 |
self.provenance = provenance
|
66 |
+ |
|
67 |
+ @property
|
|
68 |
+ def index(self):
|
|
69 |
+ return self.loader.get_element_for_dep(self).index
|