Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: clang-tidy aspect fails on CcInfo rules without srcs #406

Open
cramertj opened this issue Oct 8, 2024 · 0 comments
Open

[Bug]: clang-tidy aspect fails on CcInfo rules without srcs #406

cramertj opened this issue Oct 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@cramertj
Copy link

cramertj commented Oct 8, 2024

What happened?

if not CcInfo in target:
return []
files_to_lint = _filter_srcs(ctx.rule)

assumes that all CcInfo rules have a srcs label list:

def _filter_srcs(rule):
if "lint-genfiles" in rule.attr.tags:
return rule.files.srcs
else:
return [s for s in rule.files.srcs if _is_source(s)]

In my project (Pigweed) we have custom pwpb_proto_library rule which provides CcInfo but does not have a srcs list:

https://github.com/google/pigweed/blob/8bd77aba07ab3dce5220b23994cd3ecfbcefda10/pw_protobuf_compiler/pw_proto_library.bzl#L536-L549

This leads to the following error when running bazelisk lint //pw_rpc:echo_cc.pwpb:

➜  pigweed git:(af6a29e26) ✗ bazelisk lint //pw_rpc:echo_cc.pwpb
2024/10/08 14:55:38 Using unreleased version at commit 1ff5af18d045e8f30a2a0367470db4e8225a785c
2024/10/08 14:55:38 Using unreleased version at commit 1ff5af18d045e8f30a2a0367470db4e8225a785c
ERROR: /usr/local/google/home/cramertj/src/pigweed/pw_rpc/BUILD.bazel:486:17: in //tools/lint:linters.bzl%clang_tidy aspect on _pwpb_proto_library rule //pw_rpc:echo_cc.pwpb:
Traceback (most recent call last):
	File "/tmp/bazel_output_user_root/02fd49830a521506a99f19a1e23f8759/external/aspect_rules_lint+/lint/clang_tidy.bzl", line 312, column 33, in _clang_tidy_aspect_impl
		files_to_lint = _filter_srcs(ctx.rule)
	File "/tmp/bazel_output_user_root/02fd49830a521506a99f19a1e23f8759/external/aspect_rules_lint+/lint/clang_tidy.bzl", line 149, column 38, in _filter_srcs
		return [s for s in rule.files.srcs if _is_source(s)]
Error: No attribute 'srcs' in files. Make sure there is a label or label_list type attribute with this name
Available attributes: _action_listener, _config_dependencies, aspect_hints, compatible_with, deps, exec_compatible_with, package_metadata, protos, restricted_to, target_compatible_with, toolchains
Target //pw_rpc:echo_cc.pwpb failed to build
ERROR: Analysis of aspects '[//tools/lint:linters.bzl%clang_tidy, //tools/lint:linters.bzl%ruff] with parameters {} on //pw_rpc:echo_cc.pwpb' failed; build aborted: Analysis of target '//pw_rpc:echo_cc.pwpb' failed
INFO: Elapsed time: 0.236s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

Version

Output of bazel --version:
aspect 2024.40.2-a7ed65a (with local changes)

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
bazel_dep(name = "aspect_rules_lint", version = "1.0.2")

How to reproduce

Create a `rule` which provides `CcInfo` but does not have a `srcs` label field, then run the `clang-tidy` linter on that rule.

Any other information?

No response

@cramertj cramertj added the bug Something isn't working label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant