From f93f505b7652baa9b805116352ee84196e173b33 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Fri, 24 Sep 2021 02:52:41 -0700 Subject: [PATCH] Supporting versioned dylib in has_versioned_shared_lib_extension (#2947) * Supporting versioned dylib in has_versioned_shared_lib_extension * buidifier --- go/private/common.bzl | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/go/private/common.bzl b/go/private/common.bzl index ceb215d8e8..687fd7f9fc 100644 --- a/go/private/common.bzl +++ b/go/private/common.bzl @@ -184,29 +184,20 @@ def has_simple_shared_lib_extension(path): return False def has_versioned_shared_lib_extension(path): - """Returns whether the path appears to be an .so file.""" - if not path[-1].isdigit(): + """Returns whether the path appears to be an versioned .so or .dylib file.""" + parts = path.split("/")[-1].split(".") + if not parts[-1].isdigit(): return False + for i in range(len(parts) - 1, 0, -1): + if not parts[i].isdigit(): + if parts[i] == "dylib" or parts[i] == "so": + return True - so_location = path.rfind(".so") - - # Version extensions are only allowed for .so files - if so_location == -1: - return False - last_dot = so_location - for i in range(so_location + 3, len(path)): - if path[i] == ".": - if i - last_dot > 1: - last_dot = i - else: - return False - elif not path[i].isdigit(): + # somehting like foo.bar.1.2 return False - if last_dot == len(path): - return False - - return True + # something like 1.2.3, or so.1.2, or dylib.1.2, or foo.1.2 + return False MINIMUM_BAZEL_VERSION = "4.0.0"