Skip to content

Commit

Permalink
CLion support for cc_library implementation deps (#6919)
Browse files Browse the repository at this point in the history
Adds support for the implementation_deps field from cc_library. Closes #5149
  • Loading branch information
LeFrosch authored Oct 25, 2024
1 parent 2ebf847 commit 1f14091
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
9 changes: 9 additions & 0 deletions clwb/tests/projects/virtual_includes/lib/impl_deps/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
6 changes: 6 additions & 0 deletions clwb/tests/projects/virtual_includes/lib/impl_deps/impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "impl.h"
#include "strip_relative.h"

void impl_deps_function() {
strip_relative_function();
}
1 change: 1 addition & 0 deletions clwb/tests/projects/virtual_includes/lib/impl_deps/impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void impl_deps_function();
2 changes: 1 addition & 1 deletion clwb/tests/projects/virtual_includes/main/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)
2 changes: 2 additions & 0 deletions clwb/tests/projects/virtual_includes/main/hello-world.cc
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 1f14091

Please sign in to comment.