From 4c3e410486a078d6492baeaebb406ce4d20e3164 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 22 Apr 2020 07:05:26 -0700 Subject: [PATCH] C++: Fix path checking cc_shared_library We were returning false when checking whether //foo:bar is under //:__subpackages__ RELNOTES:none PiperOrigin-RevId: 307808962 Change-Id: I080e4c239b75c188dae8af89f4b38aa935d92b0d --- examples/experimental_cc_shared_library.bzl | 9 ++++++--- examples/test_cc_shared_library/starlark_tests.bzl | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/experimental_cc_shared_library.bzl b/examples/experimental_cc_shared_library.bzl index 7b62d21..7d7fc37 100644 --- a/examples/experimental_cc_shared_library.bzl +++ b/examples/experimental_cc_shared_library.bzl @@ -242,9 +242,12 @@ def _same_package_or_above(label_a, label_b): package_b_tokenized = label_b.package.split("/") if len(package_b_tokenized) < len(package_a_tokenized): return False - for i in range(len(package_a_tokenized)): - if package_a_tokenized[i] != package_b_tokenized[i]: - 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 def _cc_shared_library_impl(ctx): diff --git a/examples/test_cc_shared_library/starlark_tests.bzl b/examples/test_cc_shared_library/starlark_tests.bzl index f301498..76a9e00 100644 --- a/examples/test_cc_shared_library/starlark_tests.bzl +++ b/examples/test_cc_shared_library/starlark_tests.bzl @@ -63,6 +63,8 @@ def _paths_test_impl(ctx): 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)