mirror of https://github.com/bazelbuild/rules_cc
Remove unnecessary tests from rules_cc
They are now part of the bazelbuild/bazel repository. Copies buildifier changes contributed by Keith in https://github.com/bazelbuild/rules_cc/pull/128 RELNOTES:none PiperOrigin-RevId: 435312636 Change-Id: I4d5d2f58d90026c0cdfb5c0a90709de7c28c6ccd
This commit is contained in:
parent
c460f83acb
commit
3eaa3c7f88
|
@ -44,21 +44,3 @@ tasks:
|
|||
<<: *common
|
||||
windows:
|
||||
<<: *common
|
||||
examples:
|
||||
platform: ubuntu1804
|
||||
bazel: last_green
|
||||
build_targets:
|
||||
- "//examples/test_cc_shared_library/..."
|
||||
- "//examples/test_cc_shared_library/diamond_inheritance/..."
|
||||
build_flags:
|
||||
- "--experimental_cc_shared_library"
|
||||
- "--experimental_link_static_libraries_once"
|
||||
- "--experimental_enable_target_export_check"
|
||||
test_flags:
|
||||
- "--test_timeout=120"
|
||||
- "--experimental_cc_shared_library"
|
||||
- "--experimental_link_static_libraries_once"
|
||||
- "--experimental_enable_target_export_check"
|
||||
test_targets:
|
||||
- "//examples/test_cc_shared_library/..."
|
||||
- "//examples/test_cc_shared_library/diamond_inheritance/..."
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
module(
|
||||
name = "rules_cc",
|
||||
version = "0.0.1",
|
||||
compatibility_level = 1,
|
||||
toolchains_to_register = ["@local_config_cc_toolchains//:all"],
|
||||
version = "0.0.1",
|
||||
)
|
||||
|
||||
bazel_dep(name = "bazel_skylib", version = "1.0.3")
|
||||
bazel_dep(name = "platforms", version = "0.0.4")
|
||||
|
||||
cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure")
|
||||
|
||||
use_repo(cc_configure, "local_config_cc_toolchains")
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
load("//cc/private/toolchain:cc_configure.bzl", "cc_autoconf", "cc_autoconf_toolchains")
|
||||
|
||||
def _cc_configure_impl(ctx):
|
||||
def _cc_configure_impl(_):
|
||||
cc_autoconf_toolchains(name = "local_config_cc_toolchains")
|
||||
cc_autoconf(name = "local_config_cc")
|
||||
|
||||
|
|
|
@ -28,16 +28,6 @@ load(
|
|||
"write_builtin_include_directory_paths",
|
||||
)
|
||||
|
||||
def _field(name, value):
|
||||
"""Returns properly indented top level crosstool field."""
|
||||
if type(value) == "list":
|
||||
return "\n".join([" " + name + ": '" + v + "'" for v in value])
|
||||
elif type(value) == "string":
|
||||
return " " + name + ": '" + value + "'"
|
||||
else:
|
||||
auto_configure_fail("Unexpected field type: " + type(value))
|
||||
return ""
|
||||
|
||||
def _uniq(iterable):
|
||||
"""Remove duplicates from a list."""
|
||||
|
||||
|
@ -65,15 +55,6 @@ def _prepare_include_path(repo_ctx, path):
|
|||
return escape_string(path[len(repo_root):])
|
||||
return escape_string(path)
|
||||
|
||||
def _get_value(it):
|
||||
"""Convert `it` in serialized protobuf format."""
|
||||
if type(it) == "int":
|
||||
return str(it)
|
||||
elif type(it) == "bool":
|
||||
return "true" if it else "false"
|
||||
else:
|
||||
return "\"%s\"" % it
|
||||
|
||||
def _find_tool(repository_ctx, tool, overriden_tools):
|
||||
"""Find a tool for repository, taking overriden tools into account."""
|
||||
if tool in overriden_tools:
|
||||
|
|
|
@ -950,7 +950,6 @@ def _impl(ctx):
|
|||
],
|
||||
)
|
||||
|
||||
dynamic_library_linker_tool_path = tool_paths
|
||||
dynamic_library_linker_tool_feature = feature(
|
||||
name = "dynamic_library_linker_tool",
|
||||
flag_sets = [
|
||||
|
@ -1114,6 +1113,8 @@ def _impl(ctx):
|
|||
strip_debug_symbols_feature,
|
||||
coverage_feature,
|
||||
supports_pic_feature,
|
||||
gcc_coverage_map_format_feature,
|
||||
llvm_coverage_map_format_feature,
|
||||
] + (
|
||||
[
|
||||
supports_start_end_lib_feature,
|
||||
|
@ -1150,6 +1151,8 @@ def _impl(ctx):
|
|||
user_compile_flags_feature,
|
||||
sysroot_feature,
|
||||
unfiltered_compile_flags_feature,
|
||||
gcc_coverage_map_format_feature,
|
||||
llvm_coverage_map_format_feature,
|
||||
]
|
||||
|
||||
return cc_common.create_cc_toolchain_config_info(
|
||||
|
|
|
@ -1276,6 +1276,7 @@ def _impl(ctx):
|
|||
copy_dynamic_libraries_to_binary_feature,
|
||||
gcc_env_feature,
|
||||
supports_pic_feature,
|
||||
supports_start_end_lib_feature,
|
||||
default_compile_flags_feature,
|
||||
default_link_flags_feature,
|
||||
fdo_optimize_feature,
|
||||
|
|
|
@ -46,32 +46,3 @@ def cc_shared_library_permissions(**kwargs):
|
|||
|
||||
def cc_shared_library(**kwargs):
|
||||
native.cc_shared_library(**kwargs)
|
||||
|
||||
# TODO(bazel-team): Everything below this line can be deleted when tests have
|
||||
# been moved under bazel repo
|
||||
def _check_if_target_under_path(value, pattern):
|
||||
if pattern.workspace_name != value.workspace_name:
|
||||
return False
|
||||
if pattern.name == "__pkg__":
|
||||
return pattern.package == value.package
|
||||
if pattern.name == "__subpackages__":
|
||||
return _same_package_or_above(pattern, value)
|
||||
|
||||
return pattern.package == value.package and pattern.name == value.name
|
||||
|
||||
def _same_package_or_above(label_a, label_b):
|
||||
if label_a.workspace_name != label_b.workspace_name:
|
||||
return False
|
||||
package_a_tokenized = label_a.package.split("/")
|
||||
package_b_tokenized = label_b.package.split("/")
|
||||
if len(package_b_tokenized) < len(package_a_tokenized):
|
||||
return False
|
||||
|
||||
if package_a_tokenized[0] != "":
|
||||
for i in range(len(package_a_tokenized)):
|
||||
if package_a_tokenized[i] != package_b_tokenized[i]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
for_testing_dont_use_check_if_target_under_path = _check_if_target_under_path
|
||||
|
|
|
@ -1,236 +0,0 @@
|
|||
load("//third_party/bazel_skylib:bzl_library.bzl", "bzl_library")
|
||||
load("//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
|
||||
load("//third_party/bazel_rules/rules_cc/examples:experimental_cc_shared_library.bzl", "LINKABLE_MORE_THAN_ONCE")
|
||||
load(":starlark_tests.bzl", "additional_inputs_test", "build_failure_test", "linking_suffix_test", "paths_test")
|
||||
|
||||
package(
|
||||
default_visibility = ["//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:__subpackages__"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "cc_test",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = ["foo_so"],
|
||||
deps = ["foo"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "binary",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = ["foo_so"],
|
||||
deps = ["foo"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "binary_with_bar_so_twice",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = [
|
||||
"foo_so",
|
||||
"bar_so",
|
||||
],
|
||||
deps = ["foo"],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "foo_so",
|
||||
additional_linker_inputs = [
|
||||
":foo.lds",
|
||||
":additional_script.txt",
|
||||
],
|
||||
dynamic_deps = ["bar_so"],
|
||||
preloaded_deps = ["preloaded_dep"],
|
||||
roots = [
|
||||
"baz",
|
||||
"foo",
|
||||
"a_suffix",
|
||||
],
|
||||
static_deps = [
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:qux",
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:qux2",
|
||||
],
|
||||
user_link_flags = [
|
||||
"-Wl,-rpath,kittens",
|
||||
"-Wl,--version-script=$(location :foo.lds)",
|
||||
"-Wl,--script=$(location :additional_script.txt)",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "preloaded_dep",
|
||||
srcs = ["preloaded_dep.cc"],
|
||||
hdrs = ["preloaded_dep.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "foo",
|
||||
srcs = ["foo.cc"],
|
||||
hdrs = ["foo.h"],
|
||||
deps = [
|
||||
"preloaded_dep",
|
||||
"bar",
|
||||
"baz",
|
||||
# Not exported.
|
||||
"qux",
|
||||
"qux2",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "a_suffix",
|
||||
srcs = ["a_suffix.cc"],
|
||||
hdrs = ["a_suffix.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "baz",
|
||||
srcs = ["baz.cc"],
|
||||
hdrs = ["baz.h"],
|
||||
deps = ["bar3"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "qux",
|
||||
srcs = ["qux.cc"],
|
||||
hdrs = ["qux.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "qux2",
|
||||
srcs = ["qux2.cc"],
|
||||
hdrs = ["qux2.h"],
|
||||
tags = [LINKABLE_MORE_THAN_ONCE],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "bar_so",
|
||||
additional_linker_inputs = [
|
||||
":bar.lds",
|
||||
],
|
||||
exports_filter = [
|
||||
"bar3", # Exported transitive dependency
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library3:bar",
|
||||
],
|
||||
permissions = [
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library3:permissions",
|
||||
],
|
||||
roots = [
|
||||
"bar",
|
||||
"bar2",
|
||||
"@test_repo//:bar",
|
||||
],
|
||||
static_deps = [
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:barX",
|
||||
"@test_repo//:bar",
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:qux2",
|
||||
],
|
||||
user_link_flags = [
|
||||
"-Wl,--version-script=$(location :bar.lds)",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "barX",
|
||||
srcs = ["bar.cc"],
|
||||
hdrs = ["bar.h"],
|
||||
deps = [
|
||||
"@test_repo//:bar",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bar",
|
||||
srcs = ["bar.cc"],
|
||||
hdrs = ["bar.h"],
|
||||
deps = [
|
||||
"barX",
|
||||
"qux2",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bar2",
|
||||
srcs = ["bar2.cc"],
|
||||
hdrs = ["bar2.h"],
|
||||
deps = ["bar3"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bar3",
|
||||
srcs = ["bar3.cc"],
|
||||
hdrs = ["bar3.h"],
|
||||
deps = [
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library3:bar",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "cc_shared_library_integration_test",
|
||||
srcs = ["cc_shared_library_integration_test.sh"],
|
||||
data = [
|
||||
":bar_so",
|
||||
":binary",
|
||||
":cc_test",
|
||||
":foo_so",
|
||||
],
|
||||
)
|
||||
|
||||
linking_suffix_test(
|
||||
name = "linking_action_test",
|
||||
target_under_test = ":foo_so",
|
||||
)
|
||||
|
||||
additional_inputs_test(
|
||||
name = "additional_inputs_test",
|
||||
target_under_test = ":foo_so",
|
||||
)
|
||||
|
||||
build_failure_test(
|
||||
name = "link_once_repeated_test",
|
||||
message = "already linked statically in " +
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:foo_so but not exported.",
|
||||
target_under_test = "//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library/failing_targets:should_fail_binary",
|
||||
)
|
||||
|
||||
paths_test(
|
||||
name = "path_matching_test",
|
||||
)
|
||||
|
||||
build_failure_test(
|
||||
name = "export_without_permissions_test",
|
||||
message = "doesn't have the necessary permissions",
|
||||
target_under_test = "//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library/failing_targets:permissions_fail_so",
|
||||
)
|
||||
|
||||
build_failure_test(
|
||||
name = "forbidden_target_permissions_test",
|
||||
message = "can only list targets that are in the same package or a sub-package",
|
||||
target_under_test = "//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library/failing_targets:permissions_fail",
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "test_cc_shared_library_starlark_tests_bzl",
|
||||
srcs = ["starlark_tests.bzl"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
cc_shared_library_permissions(
|
||||
name = "permissions",
|
||||
targets = [
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:a_suffix",
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:qux",
|
||||
"//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library:qux2",
|
||||
],
|
||||
visibility = ["//third_party/bazel_rules/rules_cc/examples/test_cc_shared_library/diamond_inheritance:__pkg__"],
|
||||
)
|
||||
|
||||
build_failure_test(
|
||||
name = "two_dynamic_deps_same_export_in_so_test",
|
||||
message = "Two shared libraries in dependencies export the same symbols",
|
||||
target_under_test = "//examples/test_cc_shared_library/failing_targets:two_dynamic_deps_same_export_in_so",
|
||||
)
|
||||
|
||||
build_failure_test(
|
||||
name = "two_dynamic_deps_same_export_in_binary_test",
|
||||
message = "Two shared libraries in dependencies export the same symbols",
|
||||
target_under_test = "//examples/test_cc_shared_library/failing_targets:two_dynamic_deps_same_export_in_binary",
|
||||
)
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/a_suffix.h"
|
||||
|
||||
int a_suffix() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_A_SUFFIX_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_A_SUFFIX_H_
|
||||
|
||||
int a_suffix();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_A_SUFFIX_H_
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/bar.h"
|
||||
|
||||
int bar() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_H_
|
||||
|
||||
int bar();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_H_
|
|
@ -1,5 +0,0 @@
|
|||
VERS_1.1 {
|
||||
global:
|
||||
_Z3barv;
|
||||
local: *;
|
||||
};
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/bar2.h"
|
||||
|
||||
int bar2() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_2_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_2_H_
|
||||
|
||||
int bar2();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_2_H_
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/bar3.h"
|
||||
|
||||
int bar3() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_3_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_3_H_
|
||||
|
||||
int bar3();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAR_3_H_
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/baz.h"
|
||||
|
||||
int baz() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_BAZ_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_BAZ_H_
|
||||
|
||||
int baz();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_BAZ_H_
|
|
@ -1,75 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2019 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.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
function check_symbol_present() {
|
||||
message="Should have seen '$2' but didn't."
|
||||
echo "$1" | (grep -q "$2" || (echo "$message" && exit 1))
|
||||
}
|
||||
|
||||
function check_symbol_absent() {
|
||||
message="Shouldn't have seen '$2' but did."
|
||||
if [ "$(echo $1 | grep -c $2)" -gt 0 ]; then
|
||||
echo "$message"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function test_shared_library_symbols() {
|
||||
foo_so=$(find . -name libfoo_so.so)
|
||||
symbols=$(nm -D $foo_so)
|
||||
check_symbol_present "$symbols" "U _Z3barv"
|
||||
check_symbol_present "$symbols" "T _Z3bazv"
|
||||
check_symbol_present "$symbols" "T _Z3foov"
|
||||
# Check that the preloaded dep symbol is not present
|
||||
check_symbol_present "$symbols" "U _Z13preloaded_depv"
|
||||
|
||||
check_symbol_absent "$symbols" "_Z3quxv"
|
||||
check_symbol_absent "$symbols" "_Z4bar3v"
|
||||
check_symbol_absent "$symbols" "_Z4bar4v"
|
||||
}
|
||||
|
||||
function test_shared_library_user_link_flags() {
|
||||
foo_so=$(find . -name libfoo_so.so)
|
||||
objdump -x $foo_so | grep RUNPATH | grep "kittens" > /dev/null \
|
||||
|| (echo "Expected to have RUNPATH contain 'kittens' (set by user_link_flags)" \
|
||||
&& exit 1)
|
||||
}
|
||||
|
||||
function do_test_binary() {
|
||||
symbols=$(nm -D $1)
|
||||
check_symbol_present "$symbols" "U _Z3foov"
|
||||
$1 | (grep -q "hello 42" || (echo "Expected 'hello 42'" && exit 1))
|
||||
}
|
||||
|
||||
function test_binary() {
|
||||
binary=$(find . -name binary)
|
||||
do_test_binary $binary
|
||||
check_symbol_present "$symbols" "T _Z13preloaded_depv"
|
||||
}
|
||||
|
||||
function test_cc_test() {
|
||||
cc_test=$(find . -name cc_test)
|
||||
do_test_binary $cc_test
|
||||
check_symbol_absent "$symbols" "_Z13preloaded_depv"
|
||||
ldd $cc_test | (grep -q "preloaded_Udep.so" || (echo "Expected '"preloaded_Udep.so"'" && exit 1))
|
||||
}
|
||||
|
||||
test_shared_library_user_link_flags
|
||||
test_shared_library_symbols
|
||||
test_binary
|
||||
test_cc_test
|
|
@ -1,39 +0,0 @@
|
|||
load("//cc:defs.bzl", "cc_binary")
|
||||
|
||||
cc_shared_library(
|
||||
name = "baz_so",
|
||||
permissions = [
|
||||
"//examples/test_cc_shared_library:permissions",
|
||||
],
|
||||
roots = ["//examples/test_cc_shared_library:a_suffix"],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "qux_so",
|
||||
dynamic_deps = [":baz_so"],
|
||||
permissions = [
|
||||
"//examples/test_cc_shared_library:permissions",
|
||||
],
|
||||
roots = ["//examples/test_cc_shared_library:qux"],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "qux2_so",
|
||||
dynamic_deps = [":baz_so"],
|
||||
permissions = [
|
||||
"//examples/test_cc_shared_library:permissions",
|
||||
],
|
||||
roots = ["//examples/test_cc_shared_library:qux2"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "diamond_inheritance",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = [
|
||||
":qux_so",
|
||||
":qux2_so",
|
||||
],
|
||||
deps = [
|
||||
"//examples/test_cc_shared_library:a_suffix",
|
||||
],
|
||||
)
|
|
@ -1,8 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "examples/test_cc_shared_library/a_suffix.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "hello " << a_suffix() << std::endl;
|
||||
return 0;
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
load("//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
load("//examples:experimental_cc_shared_library.bzl", "cc_shared_library", "cc_shared_library_permissions")
|
||||
|
||||
package(
|
||||
default_visibility = ["//examples/test_cc_shared_library:__pkg__"],
|
||||
)
|
||||
|
||||
TAGS = [
|
||||
"manual",
|
||||
"nobuilder",
|
||||
]
|
||||
|
||||
cc_binary(
|
||||
name = "should_fail_binary",
|
||||
dynamic_deps = ["//examples/test_cc_shared_library:foo_so"],
|
||||
tags = TAGS,
|
||||
deps = [
|
||||
"//examples/test_cc_shared_library:foo",
|
||||
"//examples/test_cc_shared_library:qux",
|
||||
],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "permissions_fail_so",
|
||||
roots = [
|
||||
"//examples/test_cc_shared_library3:bar",
|
||||
],
|
||||
tags = TAGS,
|
||||
)
|
||||
|
||||
cc_shared_library_permissions(
|
||||
name = "permissions_fail",
|
||||
tags = TAGS,
|
||||
targets = [
|
||||
"//examples/test_cc_shared_library:foo",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "a",
|
||||
srcs = ["a.cc"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "b",
|
||||
srcs = ["b.cc"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "c",
|
||||
srcs = ["c.cc"],
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "two_dynamic_deps_same_export_in_so",
|
||||
dynamic_deps = [
|
||||
":b_so",
|
||||
":b2_so",
|
||||
],
|
||||
roots = [
|
||||
":a",
|
||||
],
|
||||
tags = TAGS,
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "two_dynamic_deps_same_export_in_binary",
|
||||
srcs = ["main.cc"],
|
||||
dynamic_deps = [
|
||||
":b_so",
|
||||
":b2_so",
|
||||
],
|
||||
tags = TAGS,
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "b_so",
|
||||
roots = [
|
||||
":b",
|
||||
],
|
||||
tags = TAGS,
|
||||
)
|
||||
|
||||
cc_shared_library(
|
||||
name = "b2_so",
|
||||
roots = [
|
||||
":b",
|
||||
],
|
||||
tags = TAGS,
|
||||
)
|
|
@ -1,12 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/bar.h"
|
||||
#include "examples/test_cc_shared_library/baz.h"
|
||||
#include "examples/test_cc_shared_library/preloaded_dep.h"
|
||||
#include "examples/test_cc_shared_library/qux.h"
|
||||
|
||||
int foo() {
|
||||
bar();
|
||||
baz();
|
||||
qux();
|
||||
preloaded_dep();
|
||||
return 42;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_FOO_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_FOO_H_
|
||||
|
||||
int foo();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_FOO_H_
|
|
@ -1,6 +0,0 @@
|
|||
VERS_1.1 {
|
||||
global:
|
||||
_Z3foov;
|
||||
_Z3bazv;
|
||||
local: *;
|
||||
};
|
|
@ -1,8 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "examples/test_cc_shared_library/foo.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "hello " << foo() << std::endl;
|
||||
return 0;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/bar.h"
|
||||
|
||||
int foo() {
|
||||
bar();
|
||||
return 42;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/preloaded_dep.h"
|
||||
|
||||
int preloaded_dep() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_PRELOADED_DEP_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_PRELOADED_DEP_H_
|
||||
|
||||
int preloaded_dep();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_PRELOADED_DEP_H_
|
|
@ -1 +0,0 @@
|
|||
int quux() { return 42; }
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/qux.h"
|
||||
|
||||
int qux() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX_H_
|
||||
|
||||
int qux();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX_H_
|
|
@ -1,3 +0,0 @@
|
|||
#include "examples/test_cc_shared_library/qux2.h"
|
||||
|
||||
int qux2() { return 42; }
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX2_H_
|
||||
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX2_H_
|
||||
|
||||
int qux2();
|
||||
|
||||
#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_QUX2_H_
|
|
@ -1,74 +0,0 @@
|
|||
"""Starlark tests for cc_shared_library"""
|
||||
|
||||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest")
|
||||
load("//examples:experimental_cc_shared_library.bzl", "for_testing_dont_use_check_if_target_under_path")
|
||||
|
||||
def _linking_suffix_test_impl(ctx):
|
||||
env = analysistest.begin(ctx)
|
||||
|
||||
target_under_test = analysistest.target_under_test(env)
|
||||
actions = analysistest.target_actions(env)
|
||||
|
||||
for arg in reversed(actions[1].argv):
|
||||
if (arg.find(".a") != -1 or arg.find("-l") != -1) and "/" in arg:
|
||||
asserts.equals(env, "liba_suffix.a", arg[arg.rindex("/") + 1:])
|
||||
break
|
||||
|
||||
return analysistest.end(env)
|
||||
|
||||
linking_suffix_test = analysistest.make(_linking_suffix_test_impl)
|
||||
|
||||
def _additional_inputs_test_impl(ctx):
|
||||
env = analysistest.begin(ctx)
|
||||
|
||||
target_under_test = analysistest.target_under_test(env)
|
||||
actions = analysistest.target_actions(env)
|
||||
|
||||
found = False
|
||||
for arg in actions[1].argv:
|
||||
if arg.find("-Wl,--script=") != -1:
|
||||
asserts.equals(env, "examples/test_cc_shared_library/additional_script.txt", arg[13:])
|
||||
found = True
|
||||
break
|
||||
asserts.true(env, found, "Should have seen option --script=")
|
||||
|
||||
return analysistest.end(env)
|
||||
|
||||
additional_inputs_test = analysistest.make(_additional_inputs_test_impl)
|
||||
|
||||
def _build_failure_test_impl(ctx):
|
||||
env = analysistest.begin(ctx)
|
||||
|
||||
asserts.expect_failure(env, ctx.attr.message)
|
||||
|
||||
return analysistest.end(env)
|
||||
|
||||
build_failure_test = analysistest.make(
|
||||
_build_failure_test_impl,
|
||||
expect_failure = True,
|
||||
attrs = {"message": attr.string()},
|
||||
)
|
||||
|
||||
def _paths_test_impl(ctx):
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("//foo"), Label("//bar")))
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//foo"), Label("@bar//bar")))
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("//bar"), Label("@foo//bar")))
|
||||
asserts.true(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar"), Label("@foo//bar")))
|
||||
asserts.true(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar:bar"), Label("@foo//bar")))
|
||||
asserts.true(env, for_testing_dont_use_check_if_target_under_path(Label("//bar:bar"), Label("//bar")))
|
||||
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar/baz"), Label("@foo//bar")))
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar/baz"), Label("@foo//bar:__pkg__")))
|
||||
asserts.true(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar/baz"), Label("@foo//bar:__subpackages__")))
|
||||
asserts.true(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar:qux"), Label("@foo//bar:__pkg__")))
|
||||
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("@foo//bar"), Label("@foo//bar/baz:__subpackages__")))
|
||||
asserts.false(env, for_testing_dont_use_check_if_target_under_path(Label("//bar"), Label("//bar/baz:__pkg__")))
|
||||
|
||||
asserts.true(env, for_testing_dont_use_check_if_target_under_path(Label("//foo/bar:baz"), Label("//:__subpackages__")))
|
||||
|
||||
return unittest.end(env)
|
||||
|
||||
paths_test = unittest.make(_paths_test_impl)
|
|
@ -1,8 +0,0 @@
|
|||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "bar",
|
||||
srcs = ["bar.cc"],
|
||||
hdrs = ["bar.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
|
@ -1 +0,0 @@
|
|||
workspace(name = "test_repo")
|
|
@ -1,17 +0,0 @@
|
|||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("//examples:experimental_cc_shared_library.bzl", "cc_shared_library_permissions")
|
||||
|
||||
cc_library(
|
||||
name = "bar",
|
||||
srcs = ["bar.cc"],
|
||||
hdrs = ["bar.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_shared_library_permissions(
|
||||
name = "permissions",
|
||||
targets = [
|
||||
"//examples/test_cc_shared_library3:bar",
|
||||
],
|
||||
visibility = ["//examples/test_cc_shared_library:__pkg__"],
|
||||
)
|
Loading…
Reference in New Issue