Can Bazel be instructed to use a single command for updating N targets?

余生颓废 提交于 2019-12-25 18:31:34

问题


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'])]

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.

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


回答1:


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)

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).



来源:https://stackoverflow.com/questions/37169521/can-bazel-be-instructed-to-use-a-single-command-for-updating-n-targets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!