From 452f7b8d5aaa6e85e3b01b970cd9cbc842b34b86 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 10 Mar 2016 14:52:02 +1100 Subject: [PATCH] Clear up "already provided" message I got quite confused what this was trying to tell me at first. It's saying that you requested an element but another element already provides that element, so we don't know which one to choose. To help clarify the situation to the user, keep track of what is providing elements so we can describe where the conflict came from. Change-Id: Ie7471ac900a8cbee5684c928badd1b8ce6d3e3cf --- diskimage_builder/element_dependencies.py | 22 ++++++++++++++------- diskimage_builder/tests/test_elementdeps.py | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/diskimage_builder/element_dependencies.py b/diskimage_builder/element_dependencies.py index b840c558b..93ba504df 100644 --- a/diskimage_builder/element_dependencies.py +++ b/diskimage_builder/element_dependencies.py @@ -91,6 +91,7 @@ def expand_dependencies(user_elements, elements_dir=None): final_elements = set(user_elements) check_queue = collections.deque(user_elements) provided = set() + provided_by = collections.defaultdict(list) while check_queue: # bug #1303911 - run through the provided elements first to avoid @@ -98,10 +99,15 @@ def expand_dependencies(user_elements, elements_dir=None): element = check_queue.popleft() if element in provided: continue - deps = dependencies(element, elements_dir) - provided.update(provides(element, elements_dir)) - check_queue.extend(deps - (final_elements | provided)) - final_elements.update(deps) + element_deps = dependencies(element, elements_dir) + element_provides = provides(element, elements_dir) + # save which elements provide another element for potential + # error message + for provide in element_provides: + provided_by[provide].append(element) + provided.update(element_provides) + check_queue.extend(element_deps - (final_elements | provided)) + final_elements.update(element_deps) if "operating-system" not in provided: logger.error( @@ -110,9 +116,11 @@ def expand_dependencies(user_elements, elements_dir=None): conflicts = set(user_elements) & provided if conflicts: - logger.error("Following elements were explicitly required " - "but are provided by other included elements: %s" % - ", ".join(conflicts)) + logger.error( + "The following elements are already provided by another element") + for element in conflicts: + logger.error("%s : already provided by %s" % + (element, provided_by[element])) sys.exit(-1) return final_elements - provided diff --git a/diskimage_builder/tests/test_elementdeps.py b/diskimage_builder/tests/test_elementdeps.py index f6039f84d..c2f20bcdc 100644 --- a/diskimage_builder/tests/test_elementdeps.py +++ b/diskimage_builder/tests/test_elementdeps.py @@ -141,7 +141,9 @@ class TestElementDeps(testtools.TestCase): element_dependencies.expand_dependencies, ['circular1', 'operating-system'], elements_dir=self.element_dir) - self.assertIn("provided by other included elements: operating-system", + # ensure we get the error message about what's providing the + # conflicting package + self.assertIn("operating-system : already provided by ['circular1']", self.log_fixture.output)