Iterate over provided elements first
To ensure that we have the list of provided elements from the command line before looking up dependencies, use a deque and popleft() to take the elements on a first-in/first-out basis. Change-Id: I0a2c21fa081763fd3cc8358be25dafeee1ed4718 Closes-Bug: #1303911
This commit is contained in:
parent
f49e8a42c4
commit
c357ca6634
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import os
|
||||
import sys
|
||||
|
||||
@ -84,11 +85,13 @@ def expand_dependencies(user_elements, elements_dir=None):
|
||||
including any transitive dependencies.
|
||||
"""
|
||||
final_elements = set(user_elements)
|
||||
check_queue = list(user_elements)
|
||||
check_queue = collections.deque(user_elements)
|
||||
provided = set()
|
||||
|
||||
while check_queue:
|
||||
element = check_queue.pop()
|
||||
# bug #1303911 - run through the provided elements first to avoid
|
||||
# adding unwanted dependencies and looking for virtual elements
|
||||
element = check_queue.popleft()
|
||||
if element in provided:
|
||||
continue
|
||||
deps = dependencies(element, elements_dir)
|
||||
|
@ -51,9 +51,17 @@ class TestElementDeps(testtools.TestCase):
|
||||
[],
|
||||
['virtual'])
|
||||
_populate_element(self.element_dir, 'requires_virtual', ['virtual'])
|
||||
_populate_element(self.element_dir, 'virtual', [])
|
||||
_populate_element(self.element_dir, 'virtual', ['extra_dependency'])
|
||||
_populate_element(self.element_dir, 'extra_dependency', [])
|
||||
_populate_element(self.element_dir, 'circular1', ['circular2'])
|
||||
_populate_element(self.element_dir, 'circular2', ['circular1'])
|
||||
_populate_element(self.element_dir,
|
||||
'provides_new_virtual',
|
||||
[],
|
||||
['new_virtual'])
|
||||
_populate_element(self.element_dir,
|
||||
'requires_new_virtual',
|
||||
['new_virtual'])
|
||||
|
||||
def test_non_transitive_deps(self):
|
||||
result = element_dependencies.expand_dependencies(
|
||||
@ -90,7 +98,7 @@ class TestElementDeps(testtools.TestCase):
|
||||
|
||||
def test_provide(self):
|
||||
result = element_dependencies.expand_dependencies(
|
||||
['requires_virtual', 'provides_virtual'],
|
||||
['provides_virtual', 'requires_virtual'],
|
||||
elements_dir=self.element_dir)
|
||||
self.assertEqual(set(['requires_virtual', 'provides_virtual']), result)
|
||||
|
||||
@ -100,6 +108,13 @@ class TestElementDeps(testtools.TestCase):
|
||||
['virtual', 'provides_virtual'],
|
||||
self.element_dir)
|
||||
|
||||
def test_provide_virtual_ordering(self):
|
||||
result = element_dependencies.expand_dependencies(
|
||||
['requires_new_virtual', 'provides_new_virtual'],
|
||||
elements_dir=self.element_dir)
|
||||
self.assertEqual(set(['requires_new_virtual', 'provides_new_virtual']),
|
||||
result)
|
||||
|
||||
|
||||
class TestElements(testtools.TestCase):
|
||||
def test_depends_on_env(self):
|
||||
|
Loading…
Reference in New Issue
Block a user