Skip to content

Commit d7024a3

Browse files
Fix CLI parse status filter
The parse status file filter now correctly handles relative file paths in the compile_commands.json file. Additonally, a bug was fixed when the filter was used for nonexistent files.
1 parent 52ebc29 commit d7024a3

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

  • analyzer/codechecker_analyzer/cli

analyzer/codechecker_analyzer/cli/parse.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,25 @@ def print_status(report_dir: str,
407407
compile_cmd_path)
408408
sys.exit(1)
409409

410+
# Convert all relative compile_cmd.json file paths to absolute
411+
for c in compile_commands:
412+
if not os.path.isabs(c["file"]):
413+
c["file"] = os.path.abspath(
414+
os.path.join(c["directory"], c["file"]))
415+
410416
if files:
411-
files_filter = [os.path.abspath(fp) for fp in files]
417+
file_filter = [os.path.abspath(fp) for fp in files]
418+
419+
invalid_file_filter = [fp for fp in file_filter
420+
if not os.path.isfile(fp)]
421+
422+
if invalid_file_filter:
423+
LOG.error("File filter (--file) contains nonexistent files:")
424+
LOG.error(invalid_file_filter)
425+
sys.exit(1)
426+
412427
compile_commands = list(
413-
filter(lambda c: c["file"] in files_filter, compile_commands))
428+
filter(lambda c: c["file"] in file_filter, compile_commands))
414429

415430
if not compile_commands and not export:
416431
LOG.warning("File not found in the compilation database!")

0 commit comments

Comments
 (0)