Skip to content

Commit 21904a9

Browse files
fmeumcopybara-github
authored andcommitted
Collect implementation_deps in graph node aspect
This is needed for implementation_deps of cc_library targets to be linked into cc_binary targets with dynamic_deps and cc_shared_library targets. Fixes #14731 Closes #14730. PiperOrigin-RevId: 479253298 Change-Id: I933f2e9fc3171378cc95a50c59a426489b8724c3
1 parent 801e01c commit 21904a9

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/GraphNodeAspect.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public AspectParameters apply(Rule rule) {
5050
: null;
5151
}
5252
};
53+
private static final ImmutableList<String> CC_DEPS_ATTRIBUTES =
54+
ImmutableList.of("deps", "implementation_deps");
5355

5456
@Override
5557
public AspectDefinition getDefinition(AspectParameters aspectParameters) {
@@ -67,9 +69,12 @@ public ConfiguredAspect create(
6769
RepositoryName toolsRepository)
6870
throws ActionConflictException, InterruptedException {
6971
ImmutableList.Builder<GraphNodeInfo> children = ImmutableList.builder();
70-
if (ruleContext.attributes().has("deps")) {
71-
children.addAll(
72-
AnalysisUtils.getProviders(ruleContext.getPrerequisites("deps"), GraphNodeInfo.class));
72+
for (String depsAttribute : CC_DEPS_ATTRIBUTES) {
73+
if (ruleContext.attributes().has(depsAttribute)) {
74+
children.addAll(
75+
AnalysisUtils.getProviders(
76+
ruleContext.getPrerequisites(depsAttribute), GraphNodeInfo.class));
77+
}
7378
}
7479
return new ConfiguredAspect.Builder(ruleContext)
7580
.addProvider(

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ cc_shared_library(
9090
"a_suffix",
9191
],
9292
static_deps = [
93+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:implementation_dep",
9394
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:qux",
9495
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:qux2",
9596
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:prebuilt",
@@ -110,6 +111,12 @@ cc_library(
110111
hdrs = ["preloaded_dep.h"],
111112
)
112113

114+
cc_library(
115+
name = "implementation_dep",
116+
srcs = ["implementation_dep.cc"],
117+
hdrs = ["implementation_dep.h"],
118+
)
119+
113120
cc_library(
114121
name = "foo",
115122
srcs = [
@@ -124,6 +131,7 @@ cc_library(
124131
"//src/conditions:linux": ["IS_LINUX"],
125132
"//conditions:default": [],
126133
}),
134+
implementation_deps = ["implementation_dep"],
127135
deps = [
128136
"preloaded_dep",
129137
"bar",

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/cc_shared_library_integration_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function test_shared_library_symbols() {
4848
check_symbol_absent "$symbols" "_Z3quxv"
4949
check_symbol_absent "$symbols" "_Z4bar3v"
5050
check_symbol_absent "$symbols" "_Z4bar4v"
51+
check_symbol_absent "$symbols" "_Z18implementation_depv"
5152
}
5253

5354
function test_shared_library_user_link_flags() {

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/foo.cc

+2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/baz.h"
1616
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib.h"
1717
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib2.h"
18+
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/implementation_dep.h"
1819
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/preloaded_dep.h"
1920
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux.h"
2021

2122
int foo() {
2223
bar();
2324
baz();
25+
implementation_dep();
2426
qux();
2527
#ifdef IS_LINUX
2628
direct_so_file_cc_lib();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/implementation_dep.h"
15+
16+
int implementation_dep() { return 43; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_
15+
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_
16+
17+
int implementation_dep();
18+
19+
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_

src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ EOF
7373
--experimental_link_static_libraries_once \
7474
--experimental_enable_target_export_check --experimental_cc_shared_library \
7575
--experimental_builtins_injection_override=+cc_binary \
76+
--experimental_cc_implementation_deps \
7677
//src/main/starlark/tests/builtins_bzl/cc/... || fail "expected success"
7778
}
7879

79-
run_suite "cc_* built starlark test"
80+
run_suite "cc_* built starlark test"

0 commit comments

Comments
 (0)