From c07100423ea07b25f209414052bc2edfafa58a81 Mon Sep 17 00:00:00 2001 From: Aaron Boman Date: Sat, 8 Oct 2016 16:13:11 -0500 Subject: [PATCH] Provide help message when generator is handed empty list of sources. In Jam, the language itself would raise an error when the sources list was empty. In the Python port, it was assumed that sources was never empty and would run into an IndexError when the empty sources list tried to access the first element. This change checks sources first and provides an error message in the event that sources is empty. An empty source list can be passed in when the best alternative evalutates to an empty list of sources. This target is then added to a typed target, e.g. lib, which requires sources. --- src/build/generators.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/build/generators.py b/src/build/generators.py index c2e21510c..a87a0d33a 100644 --- a/src/build/generators.py +++ b/src/build/generators.py @@ -53,6 +53,7 @@ import os.path from virtual_target import Subvariant from . import virtual_target, type, property_set, property +from b2.exceptions import BaseBoostBuildException from b2.util.logger import * from b2.util.utility import * from b2.util import set as set_, is_iterable_typed, is_iterable @@ -158,6 +159,13 @@ def dout(message): if debug(): print __indent + message + +class InvalidTargetSource(BaseBoostBuildException): + """ + Should be raised when a target contains a source that is invalid. + """ + + class Generator: """ Creates a generator. manager: the build manager. @@ -336,11 +344,16 @@ class Generator: assert isinstance(name, basestring) or name is None assert isinstance(prop_set, property_set.PropertySet) assert is_iterable_typed(sources, virtual_target.VirtualTarget) - if project.manager ().logger ().on (): project.manager ().logger ().log (__name__, " generator '%s'" % self.id_) project.manager ().logger ().log (__name__, " composing: '%s'" % self.composing_) + if not sources: + s = 'An empty source list was passed in to the "{}" generator'.format(self.id_) + if name: + s += ' for target "{}"'.format(name) + raise InvalidTargetSource(s) + if not self.composing_ and len (sources) > 1 and len (self.source_types_) > 1: raise BaseException ("Unsupported source/source_type combination")