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

Fix _is_shared_library_extension_valid #14021

Closed
wants to merge 1 commit into from
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
28 changes: 15 additions & 13 deletions src/main/starlark/builtins_bzl/common/cc/cc_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ def _is_shared_library_extension_valid(shared_library_name):
shared_library_name.endswith(".dylib")):
return True

# validate against the regex "^.+\.so(\.\d\w*)+$" for versioned .so files
parts = shared_library_name.split(".")
extension = parts[1]
if extension != "so":
return False
version_parts = parts[2:]
for part in version_parts:
if not part[0].isdigit():
return False
for c in part[1:].elems():
if not (c.isalnum() or c == "_"):
return False
return True
# validate agains the regex "^.+\\.((so)|(dylib))(\\.\\d\\w*)+$",
# must match VERSIONED_SHARED_LIBRARY.
for ext in (".so.", ".dylib."):
name,_,version = shared_library_name.rpartition(ext)
if name and version:
version_parts = version.split(".")
for part in version_parts:
if not part[0].isdigit():
return False
for c in part[1:].elems():
if not (c.isalnum() or c == "_"):
return False
return True

return False

def _perform_error_checks(
system_provided,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,33 @@ public void testCcImportWithVersionedSharedLibrary() throws Exception {
.containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so.1ab2.1_a2");
}

@Test
public void testCcImportWithVersionedSharedLibraryWithDotInTheName() throws Exception {
useConfiguration("--cpu=k8");
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
"foo",
starlarkImplementationLoadStatement,
"cc_import(name = 'foo', shared_library = 'libfoo.qux.so.1ab2.1_a2')");
Artifact dynamicLibrary =
target
.get(CcInfo.PROVIDER)
.getCcLinkingContext()
.getLibraries()
.getSingleton()
.getResolvedSymlinkDynamicLibrary();
Iterable<Artifact> dynamicLibrariesForRuntime =
target
.get(CcInfo.PROVIDER)
.getCcLinkingContext()
.getDynamicLibrariesForRuntime(/* linkingStatically= */ false);
assertThat(artifactsToStrings(ImmutableList.of(dynamicLibrary)))
.containsExactly("src a/libfoo.qux.so.1ab2.1_a2");
assertThat(artifactsToStrings(dynamicLibrariesForRuntime))
.containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.qux.so.1ab2.1_a2");
}

@Test
public void testCcImportWithInvalidVersionedSharedLibrary() throws Exception {
checkError(
Expand All @@ -229,6 +256,19 @@ public void testCcImportWithInvalidVersionedSharedLibrary() throws Exception {
")");
}

@Test
public void testCcImportWithInvalidSharedLibraryNoExtension() throws Exception {
checkError(
"a",
"foo",
"does not produce any cc_import shared_library files " + "(expected",
starlarkImplementationLoadStatement,
"cc_import(",
" name = 'foo',",
" shared_library = 'libfoo',",
")");
}

@Test
public void testCcImportWithInterfaceSharedLibrary() throws Exception {
useConfiguration("--cpu=k8");
Expand Down