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:
Jon-Paul Sullivan 2014-04-07 17:59:33 +01:00
parent f49e8a42c4
commit c357ca6634
2 changed files with 22 additions and 4 deletions

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import argparse import argparse
import collections
import os import os
import sys import sys
@ -84,11 +85,13 @@ def expand_dependencies(user_elements, elements_dir=None):
including any transitive dependencies. including any transitive dependencies.
""" """
final_elements = set(user_elements) final_elements = set(user_elements)
check_queue = list(user_elements) check_queue = collections.deque(user_elements)
provided = set() provided = set()
while check_queue: 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: if element in provided:
continue continue
deps = dependencies(element, elements_dir) deps = dependencies(element, elements_dir)

View File

@ -51,9 +51,17 @@ class TestElementDeps(testtools.TestCase):
[], [],
['virtual']) ['virtual'])
_populate_element(self.element_dir, 'requires_virtual', ['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, 'circular1', ['circular2'])
_populate_element(self.element_dir, 'circular2', ['circular1']) _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): def test_non_transitive_deps(self):
result = element_dependencies.expand_dependencies( result = element_dependencies.expand_dependencies(
@ -90,7 +98,7 @@ class TestElementDeps(testtools.TestCase):
def test_provide(self): def test_provide(self):
result = element_dependencies.expand_dependencies( result = element_dependencies.expand_dependencies(
['requires_virtual', 'provides_virtual'], ['provides_virtual', 'requires_virtual'],
elements_dir=self.element_dir) elements_dir=self.element_dir)
self.assertEqual(set(['requires_virtual', 'provides_virtual']), result) self.assertEqual(set(['requires_virtual', 'provides_virtual']), result)
@ -100,6 +108,13 @@ class TestElementDeps(testtools.TestCase):
['virtual', 'provides_virtual'], ['virtual', 'provides_virtual'],
self.element_dir) 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): class TestElements(testtools.TestCase):
def test_depends_on_env(self): def test_depends_on_env(self):