From 4784304fe09527398f624f7d2ce81885d7f9bd42 Mon Sep 17 00:00:00 2001 From: Ayan Sinha Mahapatra Date: Mon, 30 Dec 2024 18:43:59 +0530 Subject: [PATCH] Address feedback Signed-off-by: Ayan Sinha Mahapatra --- scanpipe/pipes/input.py | 6 +++++- scanpipe/pipes/symbolmap.py | 22 +++++++++++++++------- setup.cfg | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/scanpipe/pipes/input.py b/scanpipe/pipes/input.py index f57e7eafd..abb73e913 100644 --- a/scanpipe/pipes/input.py +++ b/scanpipe/pipes/input.py @@ -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 @@ -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 diff --git a/scanpipe/pipes/symbolmap.py b/scanpipe/pipes/symbolmap.py index 51ec10847..346a698f1 100644 --- a/scanpipe/pipes/symbolmap.py +++ b/scanpipe/pipes/symbolmap.py @@ -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 @@ -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: " @@ -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: diff --git a/setup.cfg b/setup.cfg index 81cf6660e..37766f4ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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