Build 斯科斯:我如何连接一个侦听器?

Build 斯科斯:我如何连接一个侦听器?,build,scons,Build,Scons,我需要附加到SCons构建,以便在构建过程中发生事件时得到通知:文件编译、文件链接等 我知道通过-listener选项对ANT构建也有类似的可能。您能告诉我如何为SCON生成操作吗?当目标在SCON中生成时,您可以通过AddPostAction(target,action)功能将post操作关联起来,如文档所示 下面是一个简单的python函数操作示例: # Create yourAction here: # can be a python function or external (she

我需要附加到SCons构建,以便在构建过程中发生事件时得到通知:文件编译、文件链接等


我知道通过-listener选项对ANT构建也有类似的可能。您能告诉我如何为SCON生成操作吗?

当目标在SCON中生成时,您可以通过AddPostAction(target,action)功能将post操作关联起来,如文档所示

下面是一个简单的python函数操作示例:

# Create yourAction here:
#   can be a python function or external (shell) command line

def helloWorldAction(target = None, source = None, env = None):
    '''
      target: a Node object representing the target file
      source: a Node object representing the source file
      env: the construction environment used for building the target file
      The target and source arguments may be lists of Node objects if there 
      is more than one target file or source file.
    '''

    print "PostAction for target: %s" % str(target)

    # you can get a map of the source files like this:
    # source_file_names = map(lambda x: str(x), source)
    # compilation options, etc can be retrieved from the env

    return 0

env = Environment()
progTarget = env.Program(target = "helloWorld", source = "helloWorld.cc")
env.AddPostAction(progTarget, helloWorldAction)
# Or create the action object like this:
# a = Action(helloWorldAction)
然后,每次构建helloWorld时,
helloWorldAction
python函数都将在之后执行


关于在不修改给定的SConstruct的情况下执行此操作,我不认为这是可能的。

谢谢,您能否给出一个简单操作的示例(例如打印helloWorld.cc的编译选项)?另外,我想问,在给定SConstruct脚本(可能是遗留的)的情况下,是否有任何方法可以不经修改就完成类似的事情?@Nelly,我添加了一个python函数操作,您必须对其进行测试。