def _find_objects_r(env, nodes, object_builders, objects, excludes, recur): """Helper function (recursion) for _find_objects()""" from SCons.Util import NodeList if recur <= 0: raise GCovRecursionError("Maximum recursion depth exceeded") children = NodeList() for node in nodes: if node not in excludes: children.extend(node.children()) if node.has_builder(): builder = node.get_builder() if builder in object_builders: objects.append(node) if len(children) > 0: _find_objects_r(env, children, object_builders, objects, excludes, recur - 1)
def _object2gcda(env, objects, target): """Determine gcda files corresponding to a given objects""" import os from SCons.Util import NodeList, is_List objects = env.arg2nodes(objects, target = target) gcdas = NodeList() for obj in objects: gcda = os.path.splitext(str(obj))[0] + env.get('GCCCOV_GCDA_SUFFIX','.gcda') gcdas.append(gcda) excludes = env.get('GCCCOV_EXCLUDE',[]) excludes = env.arg2nodes(excludes, target = target) gcdas = env.arg2nodes(gcdas, target = target) for exclude in excludes: if exclude in gcdas: gcdas.remove(exclude) return gcdas
def test_null(self): """Test a null NodeList""" nl = NodeList([]) r = str(nl) assert r == '', r for node in nl: raise Exception("should not enter this loop")
def _GcdaGenerator(env, target, target_factory=_null, **overrides): """Tell that **target** produces one or more ``*.gcda`` files. :Parameters: env An instance of SCons Environment. target Target node, which is supposed to produce ``*.gcda`` files, usually it's an alias to a test runner, for example ``'check'`` Alias. target_factory Factory used to generate the **target**, by default it's ``env.ans.Alias``. overrides Key-value parameters used to override current construction variables provided by **env**. This method searches the current dependency tree starting from **target**. During search it recognizes all Object files (``*.o``, ``*.os``, etc) produced by Object builders of **env** and, for each Object file, generates corresponding ``*.gcda`` node as a side effect of **target**. """ from SCons.Util import NodeList env = env.Override(overrides) if env.get('GCCCOV_DISABLE'): return target if target_factory is _null: target_factory = env.get('GCCCOV_RUNTEST_FACTORY', env.ans.Alias) target = env.arg2nodes(target, target_factory, target=target) result = {} for tgt in target: gcda = _FindGcdaNodes(env, tgt) env.SideEffect(gcda, tgt) noclean = env.get('GCCCOV_NOCLEAN', []) noclean = env.arg2nodes(noclean, target=tgt) clean = NodeList([f for f in gcda if f not in noclean]) noignore = env.get('GCCCOV_NOIGNORE', []) noignore = env.arg2nodes(noignore, target=tgt) ignore = NodeList([f for f in gcda if f not in noignore]) if len(clean) > 0: env.Clean(tgt, clean) if len(ignore) > 0: env.Ignore('.', gcda) result[tgt] = gcda return result
def _find_objects(env, target): """Find all object files that the **target** node depends on. :Parameters: env : SCons.Environment.Environment a SCons Environment object target node where we start our recursive search, usually program name or an alias which depends on one or more programs. Of course it may be a list of such things. Typically it's an alias target which runs test program (the 'check' target). """ from SCons.Util import NodeList, unique nodes = env.arg2nodes(target, target=target) object_builders = _get_object_builders(env) objects = NodeList() excludes = env.get('GCCCOV_EXCLUDE', []) excludes = env.arg2nodes(excludes, target=target) recur = env.get('GCCCOV_MAX_RECURSION', 256) _find_objects_r(env, nodes, object_builders, objects, excludes, recur) return NodeList(unique(objects))
def test_callable_attributes(self): """Test callable attributes of a NodeList class""" class TestClass: def __init__(self, name, child=None): self.child = child self.bar = name def foo(self): return self.bar + "foo" def getself(self): return self t1 = TestClass('t1', TestClass('t1child')) t2 = TestClass('t2', TestClass('t2child')) t3 = TestClass('t3') nl = NodeList([t1, t2, t3]) assert nl.foo() == ['t1foo', 't2foo', 't3foo'], nl.foo() assert nl.bar == ['t1', 't2', 't3'], nl.bar assert nl.getself().bar == ['t1', 't2', 't3'], nl.getself().bar assert nl[0:2].child.foo() == ['t1childfoo', 't2childfoo'], \ nl[0:2].child.foo() assert nl[0:2].child.bar == ['t1child', 't2child'], \ nl[0:2].child.bar
def test_simple_attributes(self): """Test simple attributes of a NodeList class""" class TestClass: def __init__(self, name, child=None): self.child = child self.bar = name t1 = TestClass('t1', TestClass('t1child')) t2 = TestClass('t2', TestClass('t2child')) t3 = TestClass('t3') nl = NodeList([t1, t2, t3]) assert nl.bar == ['t1', 't2', 't3'], nl.bar assert nl[0:2].child.bar == ['t1child', 't2child'], \ nl[0:2].child.bar
def _object2gcda(env, objects, target): """Determine gcda files corresponding to a given objects""" import os from SCons.Util import NodeList, is_List objects = env.arg2nodes(objects, target=target) gcdas = NodeList() for obj in objects: gcda = os.path.splitext(str(obj))[0] + env.get('GCCCOV_GCDA_SUFFIX', '.gcda') gcdas.append(gcda) excludes = env.get('GCCCOV_EXCLUDE', []) excludes = env.arg2nodes(excludes, target=target) gcdas = env.arg2nodes(gcdas, target=target) for exclude in excludes: if exclude in gcdas: gcdas.remove(exclude) return gcdas