From c9bd8f3630d189b2ae51f760ffd2ba8ffb109321 Mon Sep 17 00:00:00 2001 From: Martin Medler Date: Sun, 24 Sep 2023 10:46:12 +0200 Subject: [PATCH] Change rationale for manually looking for CcInfo We have to skip targets not providing CcInfo not just because of incompatible targets in old Bazel versions, but also due to bug: https://github.com/bazelbuild/bazel/issues/19609 Given incompatible targets for aspects have been fixed in recent Bazel versions and the bug above has just been discovered, it makes no sense to keep mentioning incompatible targets as when above bug is fixed and we can remove this manual check for CcInfo incompatible targets are no longer relevant either way. --- src/aspect/dwyu.bzl | 11 ++++++----- src/aspect/factory.bzl | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/aspect/dwyu.bzl b/src/aspect/dwyu.bzl index 32db0681..63a5bbbe 100644 --- a/src/aspect/dwyu.bzl +++ b/src/aspect/dwyu.bzl @@ -135,15 +135,16 @@ def dwyu_aspect_impl(target, ctx): Returns: OutputGroup containing the generated report file """ - if not ctx.rule.kind in ["cc_binary", "cc_library", "cc_test"]: - return [] - # Skip incompatible targets - # Ideally we should check for the existence of "IncompatiblePlatformProvider". - # However, this provider is not available in Starlark + # DWYU is only able to work on targets providing CcInfo. Other targets shall be skipped. + # We can't use 'required_providers = [CcInfo],' in the aspect definition due to bug: + # https://github.com/bazelbuild/bazel/issues/19609 if not CcInfo in target: return [] + if not ctx.rule.kind in ["cc_binary", "cc_library", "cc_test"]: + return [] + # Skip targets which explicitly opt-out if "no-dwyu" in ctx.rule.attr.tags: return [] diff --git a/src/aspect/factory.bzl b/src/aspect/factory.bzl index 7952de04..fe669f0b 100644 --- a/src/aspect/factory.bzl +++ b/src/aspect/factory.bzl @@ -12,7 +12,7 @@ def dwyu_aspect_factory( Args: config: Configuration file for the tool comparing the include statements to the dependencies. - recursive: If true, execute the aspect on all trannsitive dependencies. + recursive: If true, execute the aspect on all transitive dependencies. If false, analyze only the target the aspect is being executed on. use_implementation_deps: If true, ensure cc_library dependencies which are used only in private files are listed in implementation_deps. Only available for Bazel >= 5.0.0 and if flag