From 2d82bc7382628c7adf382dd2f82193fd43725c5b Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 1 Dec 2014 13:04:20 +0000 Subject: Fix potential issue where two packages of different kinds share a name This isn't a perfect fix. If this situation occurs the tool will generate an invalid stratum and the user will need to rename one of the chunks. But this is a better than what would have happened before: one of the chunks would have been silently ignored. --- baserockimport/mainloop.py | 31 +++++++++++++++---------------- baserockimport/package.py | 6 ++++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/baserockimport/mainloop.py b/baserockimport/mainloop.py index 32dbf24..36a7016 100644 --- a/baserockimport/mainloop.py +++ b/baserockimport/mainloop.py @@ -260,19 +260,19 @@ class ImportLoop(object): version, is_build_dep, to_process, processed, errors): failed_dep_package = find( - errors, lambda i: i.match(name, version)) + errors, lambda i: i.match(kind, name, version)) if failed_dep_package: logging.debug( "Ignoring %s as it failed earlier.", failed_dep_package) return dep_package = find( - processed, lambda i: i.match(name, version)) + processed, lambda i: i.match(kind, name, version)) if dep_package is None: # Not yet processed queue_item = find( - to_process, lambda i: i.match(name, version)) + to_process, lambda i: i.match(kind, name, version)) if queue_item is None: queue_item = baserockimport.package.Package( kind, name, version) @@ -568,21 +568,20 @@ class ImportLoop(object): else: raise cliapp.AppException('No morphology for %s' % package) - def format_build_dep(name, version): - dep_package = find(graph, lambda p: p.match(name, version)) + def format_build_dep(kind, name, version): + dep_package = find( + graph, lambda p: p.match(kind, name, version)) return '%s-%s' % (name, dep_package.version_in_use) - def get_build_deps(morphology): - deps = dict() - for kind in self.importers: - field = 'x-build-dependencies-%s' % kind - deps.update(morphology.get(field, [])) - return deps - - build_depends = [ - format_build_dep(name, version) for name, version in - get_build_deps(m).iteritems() - ] + def get_build_deps(morphology, kind): + field = 'x-build-dependencies-%s' % kind + return morphology.get(field, {}) + + build_depends = [] + for kind in self.importers: + for name, version in get_build_deps(m, kind).iteritems(): + build_depends.extend( + format_build_dep(kind, name, version)) entry = { 'name': m['name'], diff --git a/baserockimport/package.py b/baserockimport/package.py index 6095b30..1739292 100644 --- a/baserockimport/package.py +++ b/baserockimport/package.py @@ -48,8 +48,10 @@ class Package(object): def add_required_by(self, item): self.required_by.append('%s-%s' % (item.name, item.version)) - def match(self, name, version): - return (self.name==name and self.version==version) + def match(self, kind, name, version): + return (self.kind == kind and + self.name == name and + self.version == version) # FIXME: these accessors are useless, but I want there to be some way # of making it clear that some of the state of the Package object is -- cgit v1.2.1