Skip to content

Commit

Permalink
Merge pull request #912 from mr-tz/improve-rust-identify
Browse files Browse the repository at this point in the history
improve Rust identification
  • Loading branch information
mr-tz authored Nov 24, 2023
2 parents 5fbf992 + 68f26d9 commit 143f082
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions floss/language/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,23 @@ def get_if_rust_and_version(static_strings: Iterable[StaticString]) -> Tuple[boo
regex_hash = re.compile(r"rustc/(?P<hash>[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<version>[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})")

for static_string_obj in static_strings:
string = static_string_obj.string

match = regex_version.search(string)
if match:
return True, match["version"]

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

Expand Down

0 comments on commit 143f082

Please sign in to comment.