From 426188c4657a6bbe1d11d7f1f694c7a6a4148f10 Mon Sep 17 00:00:00 2001 From: plf Date: Tue, 8 Mar 2022 04:52:33 -0800 Subject: [PATCH] Fix runfiles in cc_shared_library https://github.com/bazelbuild/bazel/commit/5ad403bf98f0814f8c544dc8a47633861c1ed2e3 fixed a key part which was to actually add the precompiled libraries to the runfiles provider. There was a test but this used a cc_binary which gave the false sense of things working correctly since the cc_binary is able to get the runfiles from the CcInfo and add it itself. Changed test to use a py_test instead. RELNOTES:none PiperOrigin-RevId: 433179855 --- .../common/cc/experimental_cc_shared_library.bzl | 2 ++ .../test_cc_shared_library/BUILD.builtin_test | 8 +++++++- .../test_cc_shared_library/python_test.py | 13 +++++++++++++ .../test_cc_shared_library/starlark_tests.bzl | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/python_test.py diff --git a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl index 47ded926fe599f..1f65828c4ea105 100644 --- a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl @@ -505,6 +505,8 @@ def _cc_shared_library_impl(ctx): if precompiled_dynamic_library.resolved_symlink_dynamic_library != None: precompiled_only_dynamic_libraries_runfiles.append(precompiled_dynamic_library.resolved_symlink_dynamic_library) + runfiles = runfiles.merge(ctx.runfiles(files = precompiled_only_dynamic_libraries_runfiles)) + for export in ctx.attr.roots: exports[str(export.label)] = True diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test index b8e2e998404644..34e5515e7cc779 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test @@ -8,6 +8,12 @@ package( default_visibility = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:__subpackages__"], ) +py_test( + name = "python_test", + srcs = ["python_test.py"], + data = ["foo_so"], +) + cc_test( name = "cc_test", srcs = ["main.cc"], @@ -371,7 +377,7 @@ debug_files_test( runfiles_test( name = "runfiles_test", - target_under_test = ":binary", + target_under_test = ":python_test", is_linux = select({ "//src/conditions:linux": True, "//conditions:default": False}), diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/python_test.py b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/python_test.py new file mode 100644 index 00000000000000..47501fac663cc4 --- /dev/null +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/python_test.py @@ -0,0 +1,13 @@ +# Copyright 2022 The Bazel Authors. +# +# 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. diff --git a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl index e7362ef0e215ee..c86bb9fd72405c 100644 --- a/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl +++ b/src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl @@ -157,8 +157,8 @@ def _runfiles_test_impl(ctx): for runfile in target_under_test[DefaultInfo].default_runfiles.files.to_list(): actual_files.append(runfile.basename) expected = [ - "libfoo_so.so", - "libbar_so.so", + "renamed_so_file_copy.so", + "libdirect_so_file.so", ] for expected_file in expected: asserts.true(env, expected_file in actual_files, expected_file + " not found in actual files:\n" + "\n".join(actual_files))