当你使用 Taskgen.after 装饰你只是告诉waf运行 add_size 之后的方法 apply_link 任务生成步骤中的方法。由于你的任务生成器没有链接任何东西,你没有任何东西 apply_link 方法,你不需要它。
Taskgen.after
add_size
apply_link
你的问题是你使用 ant_glob 在构建目录中。第一次,没有任何内容,所以 ant_glob 什么都不返回,所以你的任务无关:)
ant_glob
您必须向任务生成器添加一个功能,以创建要调整大小的对象。例如:
@feature("size") # or feature("*") for every taskgen @after('apply_link') def process_sizes(self): if getattr(self, "link_task", None) is None: return objets_to_size = [] objects_to_size.extend(self.link_task.inputs) # object files objects_to_size.extend(self.link_task.outputs) # exe, libs ... for node in objects_to_size: out = node.change_ext('.log') self.create_task("size", node, out)
使用:
bld.program(source = "main.c", features = "size", target = "myexe")
您将获得链接过程的所有文件的大小。
@Taskgen.extension 仅用于 Taskgen.process_source 哪个过程 source 任务生成器的属性。它不适用于未在wscript中表示的中间对象。
@Taskgen.extension
Taskgen.process_source
source