diff --git a/.bazelrc b/.bazelrc index bdc3930c974..241225ca28b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,8 +3,8 @@ build --tool_java_language_version=17 --tool_java_runtime_version=17 # Delete test data packages, needed for bazel integration tests. Update by running the following command: # bazel run @rules_bazel_integration_test//tools:update_deleted_packages -build --deleted_packages=aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/simple/main,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/main,clwb/tests/projects/llvm_toolchain/main -query --deleted_packages=aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/simple/main,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/main,clwb/tests/projects/llvm_toolchain/main +build --deleted_packages=aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/simple/main,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/main,clwb/tests/projects/llvm_toolchain/main,clwb/tests/projects/virtual_includes/lib/impl_deps +query --deleted_packages=aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/simple/main,clwb/tests/projects/virtual_includes/lib/strip_absolut,clwb/tests/projects/virtual_includes/lib/strip_relative,clwb/tests/projects/virtual_includes/main,clwb/tests/projects/llvm_toolchain/main,clwb/tests/projects/virtual_includes/lib/impl_deps common --enable_bzlmod common --enable_workspace # to load rules_scala from WORKSPACE.bzlmod diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index add312f671e..9e10580839d 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -48,6 +48,7 @@ DEPS = [ "_cc_toolchain", # From cc rules "_stl", # From cc rules "malloc", # From cc_binary rules + "implementation_deps", # From cc_library rules "_java_toolchain", # From java rules "deps", "jars", # from java_import rules @@ -514,6 +515,14 @@ def collect_cpp_info(target, ctx, semantics, ide_info, ide_info_file, output_gro compilation_context = target[CcInfo].compilation_context + # Merge current compilation context with context of implementation dependencies. + if hasattr(ctx.rule.attr, "implementation_deps"): + implementation_deps = ctx.rule.attr.implementation_deps + compilation_context = cc_common.merge_compilation_contexts( + compilation_contexts = + [compilation_context] + [impl[CcInfo].compilation_context for impl in implementation_deps], + ) + c_info = struct_omit_none( header = headers, source = sources, diff --git a/clwb/tests/integrationtests/com/google/idea/blaze/clwb/VirtualIncludesTest.java b/clwb/tests/integrationtests/com/google/idea/blaze/clwb/VirtualIncludesTest.java index 6015f683bc9..c403394f530 100644 --- a/clwb/tests/integrationtests/com/google/idea/blaze/clwb/VirtualIncludesTest.java +++ b/clwb/tests/integrationtests/com/google/idea/blaze/clwb/VirtualIncludesTest.java @@ -20,6 +20,16 @@ public void testClwb() { errors.assertNoErrors(); checkIncludes(); + checkImplDeps(); + } + + @Override + protected String projectViewText() { + // required for bazel 5 + return super.projectViewText() + """ +build_flags: + --experimental_cc_implementation_deps + """; } private @Nullable VirtualFile findHeader(String fileName, OCCompilerSettings settings) { @@ -50,5 +60,17 @@ private void checkIncludes() { assertThat(findProjectFile("lib/strip_relative/include/strip_relative.h")) .isEqualTo(findHeader("strip_relative.h", compilerSettings)); + + assertThat(findProjectFile("lib/impl_deps/impl.h")) + .isEqualTo(findHeader("lib/impl_deps/impl.h", compilerSettings)); + } + + private void checkImplDeps() { + final var compilerSettings = findFileCompilerSettings("lib/impl_deps/impl.cc"); + + final var headersSearchRoots = compilerSettings.getHeadersSearchRoots().getAllRoots(); + assertThat(headersSearchRoots).isNotEmpty(); + + assertContainsHeader("strip_relative.h", compilerSettings); } } diff --git a/clwb/tests/projects/virtual_includes/lib/impl_deps/BUILD b/clwb/tests/projects/virtual_includes/lib/impl_deps/BUILD new file mode 100644 index 00000000000..84b858f5bbb --- /dev/null +++ b/clwb/tests/projects/virtual_includes/lib/impl_deps/BUILD @@ -0,0 +1,9 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "lib", + srcs = ["impl.cc"], + hdrs = ["impl.h"], + implementation_deps = ["//lib/strip_relative:lib"], + visibility = ["//visibility:public"], +) diff --git a/clwb/tests/projects/virtual_includes/lib/impl_deps/impl.cc b/clwb/tests/projects/virtual_includes/lib/impl_deps/impl.cc new file mode 100644 index 00000000000..c12f2107936 --- /dev/null +++ b/clwb/tests/projects/virtual_includes/lib/impl_deps/impl.cc @@ -0,0 +1,6 @@ +#include "impl.h" +#include "strip_relative.h" + +void impl_deps_function() { + strip_relative_function(); +} diff --git a/clwb/tests/projects/virtual_includes/lib/impl_deps/impl.h b/clwb/tests/projects/virtual_includes/lib/impl_deps/impl.h new file mode 100644 index 00000000000..7f0077eda88 --- /dev/null +++ b/clwb/tests/projects/virtual_includes/lib/impl_deps/impl.h @@ -0,0 +1 @@ +void impl_deps_function(); diff --git a/clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD.bazel b/clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD similarity index 100% rename from clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD.bazel rename to clwb/tests/projects/virtual_includes/lib/strip_absolut/BUILD diff --git a/clwb/tests/projects/virtual_includes/main/BUILD b/clwb/tests/projects/virtual_includes/main/BUILD index 0cc9c388aa8..1aec84cdf17 100644 --- a/clwb/tests/projects/virtual_includes/main/BUILD +++ b/clwb/tests/projects/virtual_includes/main/BUILD @@ -3,10 +3,10 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") cc_binary( name = "hello-world", srcs = ["hello-world.cc"], - visibility = ["//visibility:public"], deps = [ "//lib/strip_absolut:lib", "//lib/strip_absolut:gen", "//lib/strip_relative:lib", + "//lib/impl_deps:lib", ] ) diff --git a/clwb/tests/projects/virtual_includes/main/hello-world.cc b/clwb/tests/projects/virtual_includes/main/hello-world.cc index c2429a20794..5e00ec6f380 100644 --- a/clwb/tests/projects/virtual_includes/main/hello-world.cc +++ b/clwb/tests/projects/virtual_includes/main/hello-world.cc @@ -1,10 +1,12 @@ #include "strip_absolut/strip_absolut.h" #include "strip_absolut/generated.h" #include "strip_relative.h" +#include "lib/impl_deps/impl.h" int main() { strip_absolut_function(); strip_relative_function(); + impl_deps_function(); return GENERATED_MACRO; }