1

ファイルのコンパイル、ファイルのリンクなど、SConsビルド中に何かが起こったときに通知を受け取るには、SConsビルドにアタッチする必要があります。

-listenerオプションを介したANTビルドでも同様のことが可能であることを私は知っています。SConsビルドでそれを行う方法を教えてください。

4

1 に答える 1

2

ターゲットがSConsに組み込まれている場合、ここに記載されているように、AddPostAction(target、action)関数を介してポストアクションを関連付けることができます

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がビルドされるたびに、helloWorldActionPython関数が後続で実行されます。

与えられたSConstructを変更せずにこれを行うことに関して、私はそれがどのように可能であるかわかりません。

于 2012-09-05T13:31:45.767 に答える