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

Collect implementation_deps in graph node aspect #14730

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.packages.NativeAspectClass;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import java.util.List;
import javax.annotation.Nullable;

/**
Expand All @@ -50,6 +51,8 @@ public AspectParameters apply(Rule rule) {
: null;
}
};
private static final List<String> CC_DEPS_ATTRIBUTES = ImmutableList.of("deps",
"implementation_deps");

@Override
public AspectDefinition getDefinition(AspectParameters aspectParameters) {
Expand All @@ -67,9 +70,12 @@ public ConfiguredAspect create(
RepositoryName toolsRepository)
throws ActionConflictException, InterruptedException {
ImmutableList.Builder<GraphNodeInfo> children = ImmutableList.builder();
if (ruleContext.attributes().has("deps")) {
children.addAll(
AnalysisUtils.getProviders(ruleContext.getPrerequisites("deps"), GraphNodeInfo.class));
for (String depsAttribute : CC_DEPS_ATTRIBUTES) {
if (ruleContext.attributes().has(depsAttribute)) {
children.addAll(
AnalysisUtils.getProviders(ruleContext.getPrerequisites(depsAttribute),
GraphNodeInfo.class));
}
}
return new ConfiguredAspect.Builder(ruleContext)
.addProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ cc_shared_library(
"a_suffix",
],
static_deps = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:implementation_dep",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:qux",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:qux2",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:prebuilt",
Expand All @@ -110,6 +111,12 @@ cc_library(
hdrs = ["preloaded_dep.h"],
)

cc_library(
name = "implementation_dep",
srcs = ["implementation_dep.cc"],
hdrs = ["implementation_dep.h"],
)

cc_library(
name = "foo",
srcs = [
Expand All @@ -124,6 +131,7 @@ cc_library(
"//src/conditions:linux": ["IS_LINUX"],
"//conditions:default": [],
}),
implementation_deps = ["implementation_dep"],
deps = [
"preloaded_dep",
"bar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function test_shared_library_symbols() {
check_symbol_absent "$symbols" "_Z3quxv"
check_symbol_absent "$symbols" "_Z4bar3v"
check_symbol_absent "$symbols" "_Z4bar4v"
check_symbol_absent "$symbols" "_Z18implementation_depv"
}

function test_shared_library_user_link_flags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/baz.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib2.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/implementation_dep.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/preloaded_dep.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux.h"

int foo() {
bar();
baz();
implementation_dep();
qux();
#ifdef IS_LINUX
direct_so_file_cc_lib();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/implementation_dep.h"

int implementation_dep() { return 43; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_

int implementation_dep();

#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_
1 change: 1 addition & 0 deletions src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ EOF
--experimental_link_static_libraries_once \
--experimental_enable_target_export_check --experimental_cc_shared_library \
--experimental_builtins_injection_override=+cc_binary \
--experimental_cc_implementation_deps \
//src/main/starlark/tests/builtins_bzl/cc/... || fail "expected success"
}

Expand Down