gpt4 book ai didi

c - Waf:许多文件的任务创建

转载 作者:太空宇宙 更新时间:2023-11-03 23:27:55 26 4
gpt4 key购买 nike

是否有更好/更短的方法来创建这两个可处理多个文件的任务?我更喜欢 new_task_generator 而不是神秘的类。

Files = ["src1.c", "src2.c"]

for File in Files:
bld.new_task_gen(
name = "Proc1_task",
source = File,
target= File + ".p1",
rule ="Proc1.exe ${SRC} > ${TGT}")

for File in Files:
bld.new_task_gen(
name = "Proc2_task",
after = "Proc1_task", # not parallel with Proc1_task
source = File,
target= File + ".p2",
rule ="Proc2.exe ${SRC} > ${TGT}")

Proc1.exeProc2.exe 每次调用只接受一个文件。

最佳答案

如果你的源文件有一个特定的扩展名,比如.c,最简单的方法是给这个扩展名添加一个钩子(Hook):

@extension('.c')
def process_my_extension(self, node):

task1 = self.create_task("task1", node, node.change_ext(".p1"))
task2 = self.create_task("task2", node, node.change_ext(".p2"))

task2.set_run_after(task1)

class task1_task(Task.Task):

run_str = "Proc1.exe ${SRC} > ${TGT}"
ext_in = ['.c']
ext_out = ['.p1']

class task2_task(Task.Task):

run_str = "Proc2.exe ${SRC} > ${TGT}"
ext_in = ['.c']
ext_out = ['.p2']

最好是在您在主 wscript 中加载的特定文件 (mytool.py) 中执行此操作:

def configure(conf):

conf.load("mytool", tooldir = ".") # load your mytool.py

def build(bld):

bld(
source = ["src1.c", "src2.c", ],
)

关于c - Waf:许多文件的任务创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22520140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com