bazel-contrib / bazel-contrib/rules_scala

thrift_library fails silently if unzip is not installed

Open
#169 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
384
Forks
292
Avg merge
2d 21h
Merged PRs (30d)
46

Description

Hello!

I couldn't get the following to work on my Ubuntu box even though it worked flawlessly on OS X. The generated jar files would turn up empty. Looking at the commands executed (using `-s`) I noticed the `unzip` command. On a hunch I checked `unzip`, and it turns out it wasn't installed. Installing it fixed the issue.

`unzip` fails silently (since it has it's stderr redirected, and it's not the last command executed to in the end the exit code looks OK from Bazel's perspective), so the directory ultimately used to build the jar in the end is empty. Thus the jar turns out empty.

https://github.com/bazelbuild/rules_scala/blob/master/thrift/thrift.bzl#L55

I don't have a PR since I'm not really sure where the fix should be applied:
1) Bazel switching to `bash -ce` instead of `bash -e`?
2) `thrift.bzl` adding `&&` at the end of each command?

```
thrift_library(
name = "thrift_test_src",
srcs = glob(["src/test/thrift/**/*.thrift"]),
deps = [
],
visibility = ["//visibility:public"],
)
```

```
~/my-repo$ bazel build :thrift_test_src -s --spawn_strategy standalone
INFO: Found 1 target...
>>>>> # //thing:thrift_test_src [action 'making thrift archive //thing:thrift_test_src']
(cd /home/user/.cache/bazel/_bazel_user/478b92944ef4677a88e99594ea89c7ae/execroot/my-repo && \
exec env - \
/bin/bash -c '
rm -rf bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp
mkdir -p bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp
external/local_jdk/bin/jar cMf bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp/tmp.jar $@
unzip -q -o bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp/tmp.jar -d bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp 2>/dev/null
rm -rf bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp/tmp.jar
find bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp -exec touch -t 198001010000 {} \;
external/local_jdk/bin/jar cMf bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar -C bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp .
rm -rf bazel-out/local-fastbuild/bin/thing/libthrift_test_src.jar_tmp' '' thing/src/test/thrift/microservice.thrift thing/src/test/thrift/second.thrift)
Target //thing:thrift_test_src up-to-date:
bazel-bin/thing/libthrift_test_src.jar
INFO: Elapsed time: 2.746s, Critical Path: 0.13s

$ jar tf ~/my-repo/bazel-bin/thing/libthrift_test_src.jar
..empty...
```

Contributor guide

Open the contributing guide

Research direction

Start with thrift/thrift.bzl at the linked line and inspect how the generated shell commands handle unzip errors. Reproduce the thrift_library build on Ubuntu without unzip, using the shown Bazel command and generated jar inspection. Done means the missing dependency no longer produces a successful build with an empty jar.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.