Skip to content
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

CLion support for cc_library implementation deps #6919

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this information be obtained from CcInfo provider?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a way since bazel treats impl deps context different from the main context. CcInfo only exposes the main context as far as I can tell.

https://github.com/bazelbuild/bazel/blob/b85db78de3b25cb7f5c9cb0c7afe388f75e040e3/src/main/starlark/builtins_bzl/common/cc/cc_compilation_helper.bzl#L449

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way it looks nice

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();
}
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;
}
Loading