[Scons-users] SCons, forced includes and dependencies

Sazonov Boris bsazonov at gmail.com
Sat May 28 12:04:18 EDT 2016


Hi.
In my project I need to use '-include' gcc flag to include a special
header before every source file. This file contains include and some
defines to annotate g++ STL implementation, which are necessary to
check multithreaded code under Helgrind.

First of all, I add '-include' flag for compiler:

env.Append(CPPFLAGS = ['-include', GetAbsolutePath('test/helgrind.h')])

But it doesn't create dependency on this file. And I want all of my
cpp files to depend on this header. To solve it, I've come up with
scanner wrapper and overriding object builder in the environment:

def forced_include_scanner(node, env, path, wrapped_scanner):
  flags = env['CPPFLAGS']
  print(wrapped_scanner(node, env, path)) # Returns an empty list
  return map(lambda f: f[1], filter(lambda f: f[0] == '-include',
zip(flags, flags[1:]))) + wrapped_scanner(node, env, path)

obj_bld = env['BUILDERS']['Object']
env['BUILDERS']['Object'] = Builder(action = obj_bld.action, suffix =
obj_bld.suffix, src_suffix = obj_bld.src_suffix, source_scanner =
SCons.Scanner.Base(function = forced_include_scanner, name =
"ForcedIncludeScanner", argument = obj_bld.source_scanner))

The problem is that wrapped_scanner(node, env, path) returns an empty list.
What am I doing wrong?

Thanks in advance!
Regards,
Boris Sazonov


More information about the Scons-users mailing list