Skip to content

Commit

Permalink
[fix] Fix the prepare debug scripts
Browse files Browse the repository at this point in the history
There are multiple changes in this commit:
- Expect 'compilation_database.json' instead of 'compile_cmd.json' in
  failed zips.
- Uplift the 'compiler_info.json' preparation to the 'new' format.
- Use the expected compiler for '--ctu-collect'.

Since these were broken for quite a while, and these debug scripts are
not for production use, I'm not willing to create tests for this change.
  • Loading branch information
Balazs Benics committed Mar 2, 2022
1 parent f2beb60 commit b33f994
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
14 changes: 9 additions & 5 deletions scripts/debug_tools/prepare_all_cmd_for_ctu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
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 +80,13 @@ 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"
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"),
args.sources_root),
indent=4))

Expand All @@ -99,12 +100,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
29 changes: 15 additions & 14 deletions scripts/debug_tools/prepare_compiler_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ def prepare(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 in json_data:
new_json_data[compiler] = dict()
for language in json_data[compiler]:
lines = json_data[compiler][language]['compiler_includes']
changed_lines = []
for line in lines:
changed_lines.append(lib.change_paths(
line, lib.IncludePathModifier(sources_root_abs)))
new_json_data[compiler][language] = {
'compiler_includes': changed_lines,
'target': json_data[compiler][language]['target'],
'compiler_standard':
json_data[compiler][language]['compiler_standard']
}

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


Expand Down

0 comments on commit b33f994

Please sign in to comment.