我想注入一个"清理"目标,它取决于许多其他目标在它关闭之前完成和gzip的一些日志文件.重要的是我不要早点gzip,因为这会导致一些工具失败.
如何为Scons注入一个清理目标来执行?
例如,我有目标foo和bar.我想注入一个名为'cleanup'的新自定义目标,它依赖于foo和bar,并在它们完成后运行,而无需用户指定
% scons foo cleanup
我希望他们输入:
% scons foo
但是让scons像用户输入一样执行
% scons foo cleanup
我已经尝试创建清理目标并附加到sys.argv,但似乎scons在到达我的代码时已经处理了sys.argv,因此它不处理我手动附加到的'cleanup'目标sys.argv中.
您不应该使用_Add_Targets
或未记录的功能,您只需将清理目标添加到BUILD_TARGETS
:
from SCons.Script import BUILD_TARGETS BUILD_TARGETS.append('cleanup')
如果你使用这个记录的目标列表而不是未记录的函数,那么在进行簿记时不会混淆scons.此评论块可在以下位置找到SCons/Script/__init__.py
:
# BUILD_TARGETS can be modified in the SConscript files. If so, we # want to treat the modified BUILD_TARGETS list as if they specified # targets on the command line. To do that, though, we need to know if # BUILD_TARGETS was modified through "official" APIs or by hand. We do # this by updating two lists in parallel, the documented BUILD_TARGETS # list, above, and this internal _build_plus_default targets list which # should only have "official" API changes. Then Script/Main.py can # compare these two afterwards to figure out if the user added their # own targets to BUILD_TARGETS.
所以我想它的目的是改变BUILD_TARGETS
而不是调用内部辅助函数