如何在 scons 中每次构建后运行一些代码?

发布于 2024-12-27 16:02:58 字数 636 浏览 1 评论 0原文

我正在寻找一种方法来注册诸如 scons 中的最终构建回调之类的东西。例如,我现在正在做这样的事情:

def print_build_summary():
    failures = SCons.Script.GetBuildFailures()
    notifyExe = 'notify-send '
    if len(failures) > 0:
        notifyExe = notifyExe + ' --urgency=critical Build Failed'
    else:
        notifyExe = notifyExe + ' --urgency=normal Build Succeed'

    os.system(notifyExe)

atexit.register(print_build_summary)

这只适用于非交互模式。我希望能够在每次构建结束时弹出类似的内容,特别是在交互式 scons 会话中运行多个“构建”命令时。

环顾四周,我发现的唯一建议似乎是使用依赖系统或 AddPostAction 调用来启用此功能。对我来说,这样做似乎不太正确,因为它并不是真正的依赖项(严格来说,它甚至不是构建的一部分) - 它只是需要在每个构建结束。

谢谢!

I'm looking for a way to register somthing like an end-build callback in scons. For example, I'm doing something like this right now:

def print_build_summary():
    failures = SCons.Script.GetBuildFailures()
    notifyExe = 'notify-send '
    if len(failures) > 0:
        notifyExe = notifyExe + ' --urgency=critical Build Failed'
    else:
        notifyExe = notifyExe + ' --urgency=normal Build Succeed'

    os.system(notifyExe)

atexit.register(print_build_summary)

This only works in non-interactive mode. I'd like to be able to pop up something like this at the end of every build, specifically, when running multiple 'build' commands in an interactive scons session.

The only suggestions I've found, looking around, seem to be to use the dependency system or the AddPostAction call to glom this on. It doesn't seem quite right to me to do it that way, since it's not really a dependency (it's not even really a part of the build, strictly speaking) - it's just a static bit of code that needs to be run at the end of every build.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2025-01-03 16:02:58

我不认为使用依赖系统来解决这个问题有什么问题。这就是我通常这样做的方式:

def finish( target, source, env ):
    raise Exception( 'DO IT' )

finish_command = Command( 'finish', [], finish )
Depends( finish_command, DEFAULT_TARGETS )
Default( finish_command )

这会创建一个命令,该命令取决于其执行的默认目标(因此您知道它总是最后运行 - 请参阅 scons 手册中的 DEFAULT_TARGETS )。希望这有帮助。

I don't think there's anything wrong with using the dependency system to resolve this. This is how I normally do it:

def finish( target, source, env ):
    raise Exception( 'DO IT' )

finish_command = Command( 'finish', [], finish )
Depends( finish_command, DEFAULT_TARGETS )
Default( finish_command )

This creates a command that depends on the default targets for it's execution (so you know it'll always run last - see DEFAULT_TARGETS in scons manual). Hope this helps.

何其悲哀 2025-01-03 16:02:58

我一直在研究这个问题,但没有发现 SCons 提供任何有帮助的东西。这似乎是一个非常有用的功能,也许 SCons 开发人员正在关注这些线程并会采纳建议......

我查看了源代码并弄清楚了如何做到这一点。我将尝试向 scons.org 上的 SCons 开发人员建议这一更改。

如果您有兴趣,该文件为 engine/SCons/Script/Main.py,函数为 _build_targets()。在此函数结束时,您只需添加对用户提供的回调的调用即可。当然,如果您在网络中的多台不同计算机上构建,则此解决方案不会很有用,因为您必须将更改移植到需要的任何地方,但如果您只在一台计算机上构建,那么也许您可以进行更改直到/如果 SCons 官方提供解决方案。

如果您需要帮助实施更改,请告诉我,我会看看我能做些什么。

另一种选择是将调用包装到 SCons,并让包装器脚本执行所需的操作,但这在 SCons 交互模式下没有帮助。

希望这会有所帮助,

布雷迪

编辑

我为此创建了一个功能请求:http://scons.tigris.org/issues/show_bug.cgi?id=2834

Ive been looking into this and havent found that SCons offers anything that would help. This seems like quite a usefull feature, maybe the SCons developers are watching these threads and will take the suggestion...

I looked at the source code and figured out how to do it. I'll try to suggest this change to the SCons developers on scons.org.

If you're interested, the file is engine/SCons/Script/Main.py, and the function is _build_targets(). At the end of this funcion, you would simply need to add a call to a user supplied callback. Of course this solution would not be very useful if you build on several different machines in your network, since you would have to port the change everywhere its needed, but if you're only building on one machine, then maybe you could make the change until/if SCons officially provides a solution.

Let me know if you need help implementing the change, and I'll see what I can do.

Another option would be to wrap the call to SCons, and have the wrapper script perform the desired actions, but that wouldnt help in SCons interactive mode.

Hope this helps,

Brady

EDIT:

I create a feature request for this: http://scons.tigris.org/issues/show_bug.cgi?id=2834

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文