bazel: Distributed caching: build fails when build inputs include directories

Consider this repository https://github.com/dfabulich/hazelcast-input-dir

In its WORKSPACE, it declares a new_http_archive whose output includes directories:

new_http_archive(
    name='babel_6_5_2',
    url='https://registry.npmjs.org/babel/-/babel-6.5.2.tgz',
    build_file_content="filegroup(name='raw', srcs=glob(['*'], exclude_directories=0), visibility=['//visibility:public'])",
)

Its BUILD file includes a simple genrule that depends on those files.

genrule(
    name='x',
    srcs=['@babel_6_5_2//:raw'],
    outs=['x.txt'],
    cmd='echo $(locations @babel_6_5_2//:raw) > $@',
)

Finally, its tools/bazel.rc uses a local hazelcast node.

build --hazelcast_node=127.0.0.1:5701 --genrule_strategy=remote --spawn_strategy=remote

When you bazel clean && bazel build :x the build fails:

$ bazel clean && bazel build :x
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
INFO: Found 1 target...
WARNING: /tmp/dgf/hazelcast-input-dir/BUILD:1:1: input 'external/babel_6_5_2/package' to //:x is a directory; dependency checking of directories is unsound.
ERROR: /tmp/dgf/hazelcast-input-dir/BUILD:1:1: Executing genrule //:x failed: Failed to get digest for input.: Input is a directory: external/babel_6_5_2/package.
Target //:x failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.176s, Critical Path: 0.00s

Whereas if you bazel clean && bazel build --genrule_strategy= :x to disable distributed caching, the build succeeds with a warning.

$ bazel clean && bazel build --genrule_strategy= :x
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
INFO: Found 1 target...
WARNING: /tmp/dgf/hazelcast-input-dir/BUILD:1:1: input 'external/babel_6_5_2/package' to //:x is a directory; dependency checking of directories is unsound.
Target //:x up-to-date:
  bazel-genfiles/x.txt
INFO: Elapsed time: 1.249s, Critical Path: 0.04s

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20 (19 by maintainers)

Commits related to this issue

Most upvoted comments

https://docs.aspect.build/rules/aspect_bazel_lib/docs/run_binary/ is a genrule-style rule that knows how to output a proper Bazel directory artifact.