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
This commit is contained in:
Googler 2020-04-22 07:05:26 -07:00 committed by Copybara-Service
parent a74452e910
commit 4c3e410486
2 changed files with 8 additions and 3 deletions

View File

@ -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):

View File

@ -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)