From 0923c6e3116bfc51f7703eed1f97babf6fe7b39d Mon Sep 17 00:00:00 2001 From: mr-tz Date: Wed, 22 Nov 2023 16:11:12 +0100 Subject: [PATCH 1/2] improve Rust identification --- floss/language/identify.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/floss/language/identify.py b/floss/language/identify.py index f0ad6ff76..b1d37d190 100644 --- a/floss/language/identify.py +++ b/floss/language/identify.py @@ -68,13 +68,19 @@ def get_if_rust_and_version(static_strings: Iterable[StaticString]) -> Tuple[boo for static_string_obj in static_strings: string = static_string_obj.string - matches = regex_hash.search(string) - if matches and matches["hash"] in rust_commit_hash.keys(): - version = rust_commit_hash[matches["hash"]] - return True, version + if regex_version.search(string): return True, string + matches = regex_hash.search(string) + if matches: + if matches["hash"] in rust_commit_hash.keys(): + version = rust_commit_hash[matches["hash"]] + return True, version + else: + logger.debug("hash %s not found in Rust commit hash database", matches["hash"]) + return True, VERSION_UNKNOWN_OR_NA + return False, VERSION_UNKNOWN_OR_NA From 68f26d9304231f9f35b50cf66eb7bc3063d5996f Mon Sep 17 00:00:00 2001 From: mr-tz Date: Thu, 23 Nov 2023 09:23:06 +0100 Subject: [PATCH 2/2] extract version from version string --- floss/language/identify.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/floss/language/identify.py b/floss/language/identify.py index b1d37d190..81ce1ea6c 100644 --- a/floss/language/identify.py +++ b/floss/language/identify.py @@ -64,13 +64,14 @@ def get_if_rust_and_version(static_strings: Iterable[StaticString]) -> Tuple[boo regex_hash = re.compile(r"rustc/(?P[a-z0-9]{40})[\\\/]library") # matches strings like "rustc/version/library" e.g. "rustc/1.54.0/library" - regex_version = re.compile(r"rustc/[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}") + regex_version = re.compile(r"rustc/(?P[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})") for static_string_obj in static_strings: string = static_string_obj.string - if regex_version.search(string): - return True, string + match = regex_version.search(string) + if match: + return True, match["version"] matches = regex_hash.search(string) if matches: