diff --git a/diskimage_builder/element_dependencies.py b/diskimage_builder/element_dependencies.py index 76c63a86..e404a92f 100644 --- a/diskimage_builder/element_dependencies.py +++ b/diskimage_builder/element_dependencies.py @@ -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) diff --git a/diskimage_builder/tests/test_elementdeps.py b/diskimage_builder/tests/test_elementdeps.py index 0c945d29..4700474e 100644 --- a/diskimage_builder/tests/test_elementdeps.py +++ b/diskimage_builder/tests/test_elementdeps.py @@ -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):