-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix: Add option to skip target without srcs #447
base: main
Are you sure you want to change the base?
Conversation
Add option 'skip_if_no_srcs' to lint_clang_tidy aspect Set to True to skip target if it provides CcInfo but has no source files. By default this will generate an error.
Thanks - is there ever a reason users ought to set |
I am unsure of other use-cases. That is why I added the option in case the old behavior is needed. |
@jsharpe can you think of any reason the aspect might need to visit a library with empty |
I don't think it would need to visit the target if it has an empty |
@@ -369,7 +371,7 @@ def _clang_tidy_aspect_impl(target, ctx): | |||
if not CcInfo in target: | |||
return [] | |||
|
|||
files_to_lint = _filter_srcs(ctx.rule) | |||
files_to_lint = _filter_srcs(ctx.rule, ctx.attr._skip_if_no_srcs) | |||
compilation_context = target[CcInfo].compilation_context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I look at it - compilation_context could be None - see https://bazel.build/rules/lib/providers/CcInfo#CcInfo; I suspect that this will happen precisely when there are no srcs present and no deps? And if so we might need to protect other places further down where we access compilation_context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johan-vcc does it fix the issue for you if you check for this being None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it out, then that check would need to be before it tries to access rule.files.srcs in _filter_srcs().
However, in my case the targets have compilation_context so that would not avoid the need to check srcs as well.
Description
Add option 'skip_if_no_srcs' to lint_clang_tidy aspect.
Set to True to skip target if it provides CcInfo but has no source files. By default this will generate an error.
See issue #406
Adding an option to skip these targets enables us to run
./lint.sh //package//...
even if some target has no source files, e.g. code generation targets.Changes are visible to end-users: yes
Add option 'skip_if_no_srcs' to lint_clang_tidy aspect.
Test plan
bazel build with lint_clang_tidy_aspect for a target that provides 'CcInfo' but does not have 'srcs' attribute.
With skip_if_no_srcs set to True:
Build completes with empty
target.AspectRulesLintClangTidy.out
file.Without new option / new option set to False: