可以指示Bazel使用单个命令来更新N个目标吗? [英] Can Bazel be instructed to use a single command for updating N targets?

查看:86
本文介绍了可以指示Bazel使用单个命令来更新N个目标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google Bazel构建工具可以很容易地解释,需要将特定目录树中的每个CoffeeScript文件编译为相应的输出JavaScript文件:

The Google Bazel build tool makes it easy enough to explain that each CoffeeScript file in a particular directory tree needs to be compiled to a corresponding output JavaScript file:

[genrule(
    name = 'compile-' + f,
    srcs = [f],
    outs = [f.replace('src/', 'static/').replace('.coffee', '.js')],
    cmd = 'coffee --compile --map --output $$(dirname $@) $<',
) for f in glob(['src/**/*.coffee'])]

但是,假设有100个CoffeeScript文件,这将分别调用coffee工具100次,从而使编译过程增加了许多秒钟.如果相反,可以向Bazel解释coffee命令可以将许多输入文件作为输入,那么可以将文件分批处理并提供给更少的coffee调用,从而可以在更多文件上分摊流程的启动时间不仅仅是一个.

But given, say, 100 CoffeeScript files, this will invoke the coffee tool 100 separate times, adding many seconds to the compilation process. If instead it could be explained to Bazel that the coffee command can take many input files as input, then files could be batched together and offered to fewer coffee invocations, allowing the startup time of the process to be amortized over more files than just one.

有什么办法向Bazel解释coffee可以一次被多个文件调用吗?

Is there any way to explain to Bazel that coffee can be invoked with many files at once?

推荐答案

我没有使用过咖啡脚本,因此可能需要进行调整(特别是--output @D部分),但是类似的方法可能会起作用:

I haven't worked with coffee script, so this may need to be adjusted (particularly the --output @D part), but something like this might work:

coffee_files = glob(['src/**/*.coffee'])

genrule(
    name = 'compile-coffee-files',
    srcs = coffee_files,
    outs = [f.replace('src/', 'static/').replace('.coffee', '.js') for f in coffee_files],
    cmd = 'coffee --compile --map --output @D $(SRCS)' % coffee)

请注意,如果仅更改一个输入Coffee脚本文件,则整个genrule将重新运行所有100个文件(与java_library包含100个输入java文件的情况相同).

Note that if just one input coffee script file is changed, the entire genrule will be rerun with all 100 files (the same as with, say, a java_library with 100 input java files).

这篇关于可以指示Bazel使用单个命令来更新N个目标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆