SCons:我如何附加听众?

时间:2012-09-05 13:24:18

标签: build scons

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

我知道通过-listener选项可以对ANT构建进行类似的操作。你能告诉SCons构建怎么做吗?

1 个答案:

答案 0 :(得分:2)

在SCons中构建目标时,您可以通过AddPostAction(目标,操作)功能将后期操作与文档here相关联。

这是一个带有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,我不明白这是怎么回事。