Skip to content

Commit f6f5467

Browse files
committed
Fix source code analysis bug
1 parent 31497fe commit f6f5467

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/fosslight_android/_src_analysis.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import os
77
from fosslight_source.run_scancode import run_scan as source_analysis
8-
from fosslight_source.cli import create_report_file
8+
from fosslight_source.cli import create_report_file, merge_results
99
from ._common import CONST_NULL
1010
from fosslight_util.constant import LOGGER_NAME
1111

@@ -25,36 +25,36 @@ def find_item_to_analyze(bin_info, output_path, start_time="", path_to_exclude=[
2525
logger.debug(f"Find_item_to_analyze:{error}")
2626

2727
source_analysis_path = [path for path in path_list_to_analyze.keys() if path not in path_to_exclude]
28-
logger.info(f"|--Source analysis for {len(source_analysis_path)} paths.")
29-
for path in source_analysis_path:
30-
file_array = [len(files) for r, d, files in os.walk(path)]
31-
files = sum(file_array)
32-
logger.info(f"{path}, File Count:{files}")
28+
if source_analysis_path:
29+
logger.info(f"|--Source analysis for {len(source_analysis_path)} paths.")
30+
for path in source_analysis_path:
31+
file_array = [len(files) for r, d, files in os.walk(path)]
32+
files = sum(file_array)
33+
logger.debug(f"{path}, File Count:{files}")
3334

34-
output_dir = os.path.join(output_path, f"{ANALYSIS_OUTPUT_DIR}_{start_time}")
35+
output_dir = os.path.join(output_path, f"{ANALYSIS_OUTPUT_DIR}_{start_time}")
3536

36-
logger.info("------------------------------")
37-
logger.info("* START TO ANALYZE SOURCE *")
38-
idx = 0
39-
for source_path in source_analysis_path:
40-
try:
41-
idx += 1
42-
if os.path.isdir(source_path):
43-
logger.info(f"({idx}){source_path}")
44-
license = run_src_analysis(source_path, start_time, output_dir)
45-
path_list_to_analyze[source_path] = license
46-
except Exception as error:
47-
logger.debug(f"Failed to run src analysis:{error}")
37+
logger.info("********* START TO ANALYZE SOURCE **********")
38+
idx = 0
39+
for source_path in source_analysis_path:
40+
try:
41+
idx += 1
42+
if os.path.isdir(source_path):
43+
logger.info(f"({idx}){source_path}")
44+
license = run_src_analysis(source_path, start_time, output_dir)
45+
path_list_to_analyze[source_path] = license
46+
except Exception as error:
47+
logger.debug(f"Failed to run src analysis:{error}")
4848

49-
for analyzed_path, analyzed_license in path_list_to_analyze.items():
50-
try:
51-
for item in bin_info:
52-
source_path = item.source_code_path
53-
item_license = item.license
54-
if source_path == analyzed_path and item_license == CONST_NULL:
55-
item.set_license(analyzed_license)
56-
except Exception as error:
57-
logger.debug(f"Failed to update license from src analysis:{error}")
49+
for analyzed_path, analyzed_license in path_list_to_analyze.items():
50+
try:
51+
for item in bin_info:
52+
source_path = item.source_code_path
53+
item_license = item.license
54+
if source_path == analyzed_path and item_license == CONST_NULL:
55+
item.set_license(analyzed_license)
56+
except Exception as error:
57+
logger.debug(f"Failed to update license from src analysis:{error}")
5858

5959
return bin_info
6060

@@ -63,20 +63,22 @@ def run_src_analysis(scan_input_path, start_time="", output_dir=""):
6363
license = CONST_NULL
6464
if os.path.exists(scan_input_path):
6565
try:
66+
output_file_name = scan_input_path.replace("/", "_")
6667
success, result_log, result, matched_txt = source_analysis(os.path.abspath(scan_input_path),
67-
output_dir,
68+
output_file_name,
6869
False, -1, True, True, "",
6970
True)
71+
result = merge_results(result)
7072
if success:
71-
output_file_name = scan_input_path.replace("/", "_")
7273
license_list = []
7374
for scan_item in result:
7475
license_list.extend(scan_item.licenses)
7576
license_list = list(dict.fromkeys(license_list))
7677
license = ",".join(license_list)
7778
if result:
78-
create_report_file(start_time, result, matched_txt, "scancode", True,
79-
output_dir, output_file_name, ".xlsx")
79+
logger.debug(f"Create a report - source analysis :{output_dir}/{output_file_name}.xlsx")
80+
create_report_file(start_time, result, matched_txt, [], 'scancode',
81+
True, output_dir, [output_file_name], [".xlsx"], False, "", scan_input_path, "", ["excel"])
8082
else:
8183
logger.debug(f"Failed to analysis (scan) {scan_input_path}:{result_log}")
8284
except Exception as error:

0 commit comments

Comments
 (0)