aspect-build / aspect-build/rules_lint

[Bug]: Clang-tidy silently swallows missing libtinfo5.so error

Open
#626 2 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Starlark
Stars
154
Forks
125
Avg merge
3d 21h
Merged PRs (30d)
20

Description

### What happened?

I wanted to reproduce a monorepo issue we saw when running the liniting aspect on first-party code in an external module. (I'll wrap that up to its own issue as I understand it better).

But at first it seemingly did succeed for my reproducer dummy files, but crashed when I ran it manually in the sandbox.
Reproducer: https://github.com/meroton/bazel-examples/tree/4dbaf4441df0b11e57bf7320af9541e81c89e143
This just downloads a prebuilt clang-tidy to use as a `native_binary` and then run the aspect with it on a bunch of empty files.

It seems that the wrapper code does not handle this uncommon error mode. As clang-tidy is most often packaged together with all of its dependencies and will work, but I think it would be best to have a catch-all for the weirdest unforeseen error cases.

```
11:40 ██ ~/git/bazel-examples $ sudo apt remove libtinfo5
...

11:47 ██ ~/git/bazel-examples $ bazel clean
INFO: Starting clean (this may take a while). Use --async if the clean takes more than several minutes.

11:47 ██ ~/git/bazel-examples $ bazel --quiet build --aspects @inner//rules_lint:lint.bzl%clang_tidy --output_groups rules_lint_human @inner//:lib
Aspect @@inner+//rules_lint:lint.bzl%clang_tidy of @@inner+//:lib up-to-date:
bazel-bin/external/inner+/lib.AspectRulesLintClangTidy.out
bazel-bin/external/inner+/lib.AspectRulesLintClangTidy.out.exit_code

11:48 ██ ~/git/bazel-examples $ cat bazel-bin/external/inner+/lib.AspectRulesLintClangTidy.out{,.exit_code}
bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/inner++_repo_rules+clang/clang-tidy: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
127

11:48 ██ ~/git/bazel-examples $ sudo apt install libtinfo5
...

11:48 ██ ~/git/bazel-examples $ bazel clean
INFO: Starting clean (this may take a while). Use --async if the clean takes more than several minutes.
11:48 ██ ~/git/bazel-examples $ bazel --quiet build --aspects @inner//rules_lint:lint.bzl%clang_tidy --output_groups rules_lint_human @inner//:lib
ERROR: /tmp/bazel-output-base/external/inner+/BUILD.bazel:3:11: Linting @@inner+//:lib with clang-tidy failed: (Exit 1): bash failed: error executing AspectRulesLintClangTidy command (from target @@inner+//:lib) /bin/bash -c 'bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/aspect_rules_lint+/lint/clang_tidy_wrapper $@' '' bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/inner++_repo_rules+clang/clang-tidy ... (remaining 4 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Error reading configuration from /tmp/bazel-output-base/sandbox/linux-sandbox/5/execroot/_main/../inner+: directory doesn't exist.
Error reading configuration from /tmp/bazel-output-base/sandbox/linux-sandbox/5/execroot/_main/../inner+: directory doesn't exist.
Error while processing /tmp/bazel-output-base/sandbox/linux-sandbox/5/execroot/_main/../inner+/source.c.
error: no input files [clang-diagnostic-error]
error: no such file or directory: '/tmp/bazel-output-base/sandbox/linux-sandbox/5/execroot/_main/../inner+/source.c' [clang-diagnostic-error]
error: unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error]
Found compiler error(s).
Aspect @@inner+//rules_lint:lint.bzl%clang_tidy of @@inner+//:lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: Build did NOT complete successfully

11:48 ██ ~/git/bazel-examples $ cat bazel-bin/external/inner+/lib.AspectRulesLintClangTidy.out{,.exit_code}
cat: bazel-bin/external/inner+/lib.AspectRulesLintClangTidy.out: No such file or directory
cat: bazel-bin/external/inner+/lib.AspectRulesLintClangTidy.out.exit_code: No such file or directory
```

### Version

Development (host) and target OS/architectures:

Output of `bazel --version`: 8.1.0, 8.4.1

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:

Language(s) and/or frameworks involved:
```
bazel_dep(name = "rules_cc", version = "0.2.8")
bazel_dep(name = "aspect_rules_lint", version = "1.9.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")

http_archive(
name = "clang",
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz",
```

### How to reproduce

```shell
Reproducer: https://github.com/meroton/bazel-examples/tree/4dbaf4441df0b11e57bf7320af9541e81c89e143
Run `bazel build --aspects @inner//rules_lint:lint.bzl%clang_tidy --output_groups rules_lint_human @inner//:lib`
With and without libtinfo5
```

### Any other information?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with lint/clang_tidy_wrapper, using the linked bazel-examples reproducer and the documented build command with and without libtinfo5. Compare the wrapper's output and exit handling for the missing shared-library error. Done means the failure is surfaced clearly instead of producing misleading successful aspect outputs.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.