Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Dec 30, 2024
1 parent c156b08 commit 4784304
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 5 additions & 1 deletion scanpipe/pipes/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/scancode.io for support and download.

import os
import shutil
from pathlib import Path

Expand All @@ -42,11 +43,14 @@
def copy_input(input_location, dest_path):
"""Copy the ``input_location`` (file or directory) to the ``dest_path``."""
input_path = Path(input_location)
destination = Path(dest_path) / input_path.name
destination_dir = Path(dest_path)
destination = destination_dir / input_path.name

if input_path.is_dir():
shutil.copytree(input_location, destination)
else:
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)
shutil.copyfile(input_location, destination)

return destination
Expand Down
22 changes: 15 additions & 7 deletions scanpipe/pipes/symbolmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
each of them and match them to the symbols obtained from the source
"""

MATCHING_RATIO_RUST = 0.5
SMALL_FILE_SYMBOLS_THRESHOLD = 20
MATCHING_RATIO_RUST_SMALL_FILE = 0.4


def map_resources_with_symbols(
to_resource, from_resources, binary_symbols, map_type, logger=None
Expand Down Expand Up @@ -65,11 +69,11 @@ def map_resources_with_symbols(

# If there are any non-test files in the rust source files which
# are not mapped, we mark the binary as REQUIRES_REVIEW
if paths_not_mapped and any(
has_non_test_unmapped_files = any(
[True for path in paths_not_mapped if "/tests/" not in path]
):
to_resource.status = flag.REQUIRES_REVIEW
to_resource.save()
)
if paths_not_mapped and has_non_test_unmapped_files:
to_resource.update(status=flag.REQUIRES_REVIEW)
if logger:
logger(
f"WARNING: #{len(paths_not_mapped)} {map_type} paths NOT mapped for: "
Expand Down Expand Up @@ -111,10 +115,14 @@ def match_source_symbols_to_binary(source_symbols, binary_symbols):
"common_symbols_ratio": common_symbols_ratio,
}

if common_symbols_ratio > 0.5 or common_symbols_unique_ratio > 0.5:
if (
common_symbols_ratio > MATCHING_RATIO_RUST
or common_symbols_unique_ratio > MATCHING_RATIO_RUST
):
return True, stats
elif source_symbols_count > 20 and (
common_symbols_ratio > 0.4 or common_symbols_unique_ratio > 0.4
elif source_symbols_count > SMALL_FILE_SYMBOLS_THRESHOLD and (
common_symbols_ratio > MATCHING_RATIO_RUST_SMALL_FILE
or common_symbols_unique_ratio > MATCHING_RATIO_RUST_SMALL_FILE
):
return True, stats
else:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ install_requires =
fetchcode-container==1.2.3.210512; sys_platform == "linux"
# Inspectors
elf-inspector==0.0.1
go-inspector==0.5.0
rust-inspector==0.1.0
go-inspector==0.5.0; sys_platform == "linux"
rust-inspector==0.1.0; sys_platform == "linux"
python-inspector==0.12.1
source-inspector==0.5.1; sys_platform != "darwin" and platform_machine != "arm64"
aboutcode-toolkit==11.0.0
Expand Down

0 comments on commit 4784304

Please sign in to comment.