From a6ef0b341a8ffe8ab27e5ace79d8eaae158c422b Mon Sep 17 00:00:00 2001 From: Adrian Imboden Date: Fri, 14 Jul 2023 02:49:34 -0700 Subject: [PATCH] add externalInclude information to compilation_context Hi bazel team I use an aspect to run clangtidy on the codebase. It is based on https://github.com/erenon/bazel_clang_tidy. To check my codebase with `-Werror`, I use the "new" feature `external_include_path` requested by https://github.com/bazelbuild/bazel/issues/12009, introduced by commit https://github.com/bazelbuild/bazel/commit/08936aecb96f2937c61bdedfebcf1c5a41a0786d. Now my clangtidy rules did not work anymore of course. As you can see in https://github.com/erenon/bazel_clang_tidy/blob/master/clang_tidy/clang_tidy.bzl, all the different include paths are being passed to the clang-tidy executable. I now also needed to pass the new external_includes to `clang-tidy`. This PR adds `external_includes` to the `compilation_context` object. I looked at the style of the other `includes` and hope it is in line with your expectations. Closes #18094. PiperOrigin-RevId: 548070112 Change-Id: I212420d2f888c3af088c4afbf8202c848d19722e --- .../build/lib/rules/cpp/CcCompilationContext.java | 11 +++++++++++ .../starlarkbuildapi/cpp/CcCompilationContextApi.java | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java index db411a4160ff7f..242ed29f1e4bc0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java @@ -228,6 +228,17 @@ public Depset getStarlarkIncludeDirs() { .collect(ImmutableList.toImmutableList()))); } + @Override + public Depset getStarlarkExternalIncludeDirs() { + return Depset.of( + String.class, + NestedSetBuilder.wrap( + Order.STABLE_ORDER, + getExternalIncludeDirs().stream() + .map(PathFragment::getSafePathString) + .collect(ImmutableList.toImmutableList()))); + } + @Override public Depset getStarlarkQuoteIncludeDirs() { return Depset.of( diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcCompilationContextApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcCompilationContextApi.java index 93a866e216c37b..aeb12368c5fb4c 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcCompilationContextApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcCompilationContextApi.java @@ -84,6 +84,14 @@ public interface CcCompilationContextApi extends Starlark structField = true) Depset getStarlarkIncludeDirs(); + @StarlarkMethod( + name = "external_includes", + doc = + "Returns the set of search paths (as strings) for external header files referenced by" + + " angle bracket. Usually passed with -isystem.", + structField = true) + Depset getStarlarkExternalIncludeDirs(); + @StarlarkMethod( name = "quote_includes", doc =