Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fix the prepare debug scripts #3614

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions scripts/debug_tools/prepare_all_cmd_for_ctu.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
import json
import os
import platform
import shutil
import subprocess

import prepare_compile_cmd
import prepare_compiler_info
import prepare_analyzer_cmd


def execute(cmd):
def execute(cmd, env):
print("Executing command: " + ' '.join(cmd))
try:
proc = subprocess.Popen(
cmd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
Expand Down Expand Up @@ -79,13 +81,21 @@ def get_triple_arch(analyze_command_file):
help="Path to the used clang plugin.")
args = parser.parse_args()

compile_cmd_debug = "compile_cmd_DEBUG.json"
# CodeChecker log outputs 'compile_cmd.json' by default.
# Let's canonicalize the name as 'compilation_database.json' instead.
try:
shutil.move("compile_cmd.json", "compilation_database.json")
print("renamed 'compile_cmd.json' to 'compilation_database.json'")
except FileNotFoundError:
pass

compile_cmd_debug = "compilation_database_DEBUG.json"
with open(compile_cmd_debug, 'w',
encoding="utf-8", errors="ignore") as f:
f.write(
json.dumps(
prepare_compile_cmd.prepare(
os.path.join(args.report_dir, "compile_cmd.json"),
os.path.join(args.report_dir, "compilation_database.json"),
steakhal marked this conversation as resolved.
Show resolved Hide resolved
args.sources_root),
indent=4))

Expand All @@ -99,12 +109,15 @@ def get_triple_arch(analyze_command_file):
args.sources_root),
indent=4))

# ctu-collect
# ctu-collect, using the provided clang
env = os.environ
env['PATH'] = f"{os.path.dirname(args.clang)}:{env['PATH']}"
env['CC_ANALYZERS_FROM_PATH'] = 'yes'
out = execute(["CodeChecker", "analyze", "--ctu-collect",
compile_cmd_debug,
"--compiler-info-file", compiler_info_debug,
"-o", "report_debug",
"--verbose", "debug"])
"--verbose", "debug"], env)

analyzer_command_debug = "analyzer-command_DEBUG"
target = get_triple_arch('./analyzer-command')
Expand Down
36 changes: 34 additions & 2 deletions scripts/debug_tools/prepare_compiler_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

import failure_lib as lib


def prepare(compiler_info_file, sources_root):
# Until CodeChecker 6.19.0 it should work.
# On failure, raises an exception.
def _try_prepare_as_old_format(compiler_info_file, sources_root):
json_data = lib.load_json_file(compiler_info_file)
sources_root_abs = os.path.abspath(sources_root)
new_json_data = dict()
Expand All @@ -35,6 +36,37 @@ def prepare(compiler_info_file, sources_root):
}
return new_json_data

# CodeChecker 6.19.0 and above it should parse according to the new format.
# More details: #3598 [analyzer] Proper handling of multi-target build
# On failure, raises an exception.
def _try_prepare_as_new_format(compiler_info_file, sources_root):
json_data = lib.load_json_file(compiler_info_file)
sources_root_abs = os.path.abspath(sources_root)
new_json_data = dict()

for compiler_id_string in json_data:
new_json_data[compiler_id_string] = dict()
include_paths = json_data[compiler_id_string]['compiler_includes']
changed_includes = [
lib.change_paths(p, lib.IncludePathModifier(sources_root_abs))
for p in include_paths
]

new_json_data[compiler_id_string] = {
'compiler_includes': changed_includes,
'target': json_data[compiler_id_string]['target'],
'compiler_standard':
json_data[compiler_id_string]['compiler_standard']
}
return new_json_data

def prepare(compiler_info_file, sources_root):
try:
return _try_prepare_as_new_format(compiler_info_file, sources_root)
except:
print(f"Failed to parse {compiler_info_file} in the 'new' "
f"compiler_info format; falling back to the old format...")
return _try_prepare_as_old_format(compiler_info_file, sources_root)

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Prepare compiler info '
Expand Down