Ejemplo n.º 1
0
 def __init__(self, actionlist, logpath=None, patterns=_rxpatterns):
     ListAction.__init__(self, actionlist)
     self.logpath = logpath
     self.patterns = patterns
     # Disable filtering when log file is disabled.
     if not logpath:
         self.patterns = None
Ejemplo n.º 2
0
 def __call__(self, target, source, env, **kw):
     # Replace the SPAWN variable with our own instance of _SpawnerLogger.
     spawner = _SpawnerLogger()
     if self.logpath:
         spawner.open(self.logpath)
     spawner.setPassingPatterns(self.patterns)
     spawnsave = env['SPAWN']
     env['SPAWN'] = spawner.spawn
     try:
         status = ListAction.__call__(self, target, source, env, **kw)
     finally:
         spawner.close()
         env['SPAWN'] = spawnsave
     return status
Ejemplo n.º 3
0
def generate(env, **kw):
    """
        Populate the given environment with the information to run the tool
        Also inject the tool emitter for gcc dependency generation and parsing
        into existing Object / SharedObject builders in the environment
    """

    geBool = base.BindCallArguments(base.getList, None, None, env, lambda x: x)
    getList = base.BindCallArguments(base.getList, None, None, env, False)

    env.SetDefault\
        (
            GCCDEP_SUFFIX   = '.d',
            GCCDEP_CSUFFIXES = [ '.c' ] + ([ ] if SCons.Util.case_sensitive_suffixes('.c', 'C') else [ '.C' ] ),
            GCCDEP_CXXSUFFIXES  =
                [ '.cc', '.cpp', '.cxx', '.c++', '.C++' ]
                    +
                ([ '.C' ] if SCons.Util.case_sensitive_suffixes('.c', '.C') else [ ]),
            GCCDEP_FILENAME =
                lambda target, source, env, for_signature:
                    env.File(target[0]).Dir('depend').Dir\
                        (
                            re.sub
                                (
                                    '((?<=^)|(?<=/))\.\.(?=(/|$))',
                                    '__',
                                    str(env.Dir('#').rel_path(source[0].srcnode().dir))
                                )
                        )
                            .File(str(target[0].name) + env.subst('$GCCDEP_SUFFIX', False, source, target)),
            GCCDEP_CFLAGS_VAR        = 'CFLAGS',
            GCCDEP_CXXFLAGS_VAR      = 'CXXFLAGS',
            GCCDEP_MAKEDEP_CFLAGS    = [ ],
            GCCDEP_MAKEDEP_CXXFLAGS  = [ ],
            GCCDEP_OBJPREFIX         = '$OBJPREFIX',
            GCCDEP_OBJSUFFIX         = '$OBJSUFFIX',
            GCCDEP_SHOBJPREFIX       = '$SHOBJPREFIX',
            GCCDEP_SHOBJSUFFIX       = '$SHOBJSUFFIX',
            GCCDEP_CFLAGS            = [ '-MD', '-MF', '$GCCDEP_FILENAME' ],
            GCCDEP_CXXFLAGS          = [ '-MD', '-MF', '$GCCDEP_FILENAME' ],
            GCCDEP_CC                = '$CC',
            GCCDEP_GCC_BASENAME      = 'gcc',
            GCCDEP_SHCC              = '$SHCC',
            GCCDEP_GCC_SH_BASENAME   = 'gcc',
            GCCDEP_CXX               = '$CXX',
            GCCDEP_GXX_BASENAME      = 'g++',
            GCCDEP_SHCXX             = '$SHCXX',
            GCCDEP_GXX_SH_BASENAME   = 'g++',
            GCCDEP_CHECK_USING_GCC   =
                lambda target, source, env, for_signature:
                    not not re.match
                        (
                            r'^(.*\b)?' + re.escape(env.subst('$GCCDEP_GCC_BASENAME', 1, source, target)) + r'(-[0-9\.]+)?(\b|\s|$)',
                            find_tool_basename(env, env.subst('$GCCDEP_CC', 0, source, target))
                        ),
            GCCDEP_CHECK_USING_SH_GCC   =
                lambda target, source, env, for_signature:
                    not not re.match
                        (
                            r'^(.*\b)?' + re.escape(env.subst('$GCCDEP_GCC_SH_BASENAME', 1, source, target)) + r'(-[0-9\.]+)?(\b|\s|$)',
                            find_tool_basename(env, env.subst('$GCCDEP_SHCC', 0, source, target))
                        ),
            GCCDEP_CHECK_USING_GXX   =
                lambda target, source, env, for_signature:
                    not not re.match
                        (
                            r'^(.*\b)?' + re.escape(env.subst('$GCCDEP_GXX_BASENAME', 1, source, target)) + r'(-[0-9\.]+)?(\b|\s|$)',
                            find_tool_basename(env, env.subst('$GCCDEP_CXX', 0, source, target))
                        ),
            GCCDEP_CHECK_USING_SH_GXX   =
                lambda target, source, env, for_signature:
                    not not re.match
                        (
                            r'^(.*\b)?' + re.escape(env.subst('$GCCDEP_GXX_SH_BASENAME', 1, source, target)) + r'(-[0-9\.]+)?(\b|\s|$)',
                            find_tool_basename(env, env.subst('$GCCDEP_SHCXX', 0, source, target))
                        ),
            GCCDEP_INJECTED = False
        )

    env.Append\
        (
            **
            {
                env['GCCDEP_CFLAGS_VAR']:   [ '$GCCDEP_MAKEDEP_CFLAGS' ],
                env['GCCDEP_CXXFLAGS_VAR']: [ '$GCCDEP_MAKEDEP_CXXFLAGS' ]
            }
        )

    builders = [
        env['BUILDERS'][name] for name in ['StaticObject', 'SharedObject']
        if name in env['BUILDERS']
    ]

    if 'Object' in env['BUILDERS']:
        objectBuilder = env['BUILDERS']['Object']
        if objectBuilder not in builders:
            builders.append(objectBuilder)

    # print("Selected builders: " + str(builders))

    for builder in builders:
        # inject gcc_dep_emitter in the current builder
        if isinstance(builder.emitter, DictEmitter):
            for ext in getList('GCCDEP_CSUFFIXES') + getList(
                    'GCCDEP_CXXSUFFIXES'):
                if ext in builder.emitter:
                    if isinstance(builder.emitter[ext], ListEmitter):
                        if gcc_dep_emitter not in builder.emitter[ext]:
                            builder.emitter[ext].append(gcc_dep_emitter)
                            # print('\033[92m' "Emitter injected in Builder list in dict" '\033[0m')
                    else:
                        builder.emitter[ext] = ListEmitter(
                            [builder.emitter[ext], gcc_dep_emitter])
                        # print('\033[92m' "Emitter injected in Builder dict in a new list" '\033[0m')
                else:
                    build.emitter[ext] = gcc_dep_emitter
                    # print('\033[92m' "Emitter injected in Builder dict" '\033[0m')
        else:
            if isinstance(builder.emitter, ListEmitter):
                if gcc_dep_emitter not in builder.emitter:
                    builder.emitter.append(gcc_dep_emitter)
                    # print('\033[92m' "Emitter injected in Builder list" '\033[0m')
            else:
                old_emitter = builder.emitter[ext]
                builder.emitter[ext] = ListEmitter(
                    [old_emitter, gcc_dep_emitter])

        if isinstance(builder, CompositeBuilder):
            for ext in getList('GCCDEP_CSUFFIXES') + getList(
                    'GCCDEP_CXXSUFFIXES'):
                try:
                    if ext in builder.cmdgen:
                        builder.add_action\
                                (
                                    ext,
                                    ListAction
                                        (
                                            [
                                                builder.cmdgen[ext],
                                                env.Action(reload_dependency_file, lambda target, source, env: None)
                                            ]
                                        )
                                )
                except AttributeError:
                    pass

        env['GCCDEP_INJECTED'] = True
        env.AddMethod(XRefParseDepends)