Skip to content

Commit

Permalink
[analyzer] Proper handling of multi-target build
Browse files Browse the repository at this point in the history
CodeChecker collects implicit compiler info, such as implicit include
paths, default target, etc. If a compilation_database.json contains
build actions with different target compilations (or different sysroot,
etc.) then the implicit infos of the first action will be applied to
all build actions.
With this patch every build action gets its own implicit info.
  • Loading branch information
bruntib committed Feb 24, 2022
1 parent 9004c10 commit ba974e1
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 184 deletions.
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def handle_reproducer(source_analyzer, rh, zip_file, actions_map):

for of in other_files:
mentioned_file = os.path.abspath(os.path.join(action.directory, of))
key = mentioned_file, action.target[action.lang]
key = mentioned_file, action.target
mentioned_file_action = actions_map.get(key)
if mentioned_file_action is not None:
buildactions.append({
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_actions_map(actions, manager):
result = manager.dict()

for act in actions:
key = act.source, act.target[act.lang]
key = act.source, act.target
if key in result:
LOG.debug("Multiple entires in compile database "
"with the same (source, target) pair: (%s, %s)",
Expand Down
13 changes: 5 additions & 8 deletions analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,24 @@ def construct_analyzer_cmd(self, result_handler):
analyzer_cmd.extend(['-x', compile_lang])

if not has_flag('--target', analyzer_cmd) and \
self.buildaction.target.get(compile_lang, "") != "":
analyzer_cmd.append("--target=" +
self.buildaction.target.get(compile_lang))
self.buildaction.target != "":
analyzer_cmd.append(f"--target={self.buildaction.target}")

if not has_flag('-arch', analyzer_cmd) and \
self.buildaction.arch != "":
analyzer_cmd.extend(["-arch ", self.buildaction.arch])

if not has_flag('-std', analyzer_cmd) and \
self.buildaction.compiler_standard.get(compile_lang, "") \
!= "":
analyzer_cmd.append(
self.buildaction.compiler_standard[compile_lang])
self.buildaction.compiler_standard != "":
analyzer_cmd.append(self.buildaction.compiler_standard)

analyzer_cmd.extend(config.analyzer_extra_arguments)

analyzer_cmd.extend(self.buildaction.analyzer_options)

analyzer_cmd.extend(prepend_all(
'-isystem',
self.buildaction.compiler_includes[compile_lang]))
self.buildaction.compiler_includes))

analyzer_cmd.append(self.source_file)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ def get_compile_command(action, config, source='', output=''):

cmd = [config.analyzer_binary]

compile_lang = action.lang
if not has_flag('--target', cmd) and action.target != "":
cmd.append(f"--target={action.target}")

if not has_flag('--target', cmd) and \
action.target[compile_lang] != "":
cmd.append("--target=" + action.target[compile_lang])

cmd.extend(prepend_all('-isystem', action.compiler_includes[compile_lang]))
cmd.extend(prepend_all('-isystem', action.compiler_includes))
cmd.append('-c')
if not has_flag('-x', cmd):
cmd.extend(['-x', action.lang])
Expand All @@ -40,7 +37,7 @@ def get_compile_command(action, config, source='', output=''):
cmd.append(source)

if not has_flag('-std', cmd) and not has_flag('--std', cmd):
cmd.append(action.compiler_standard.get(compile_lang, ""))
cmd.append(action.compiler_standard)
return cmd


Expand Down
14 changes: 5 additions & 9 deletions analyzer/codechecker_analyzer/analyzers/clangsa/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,19 @@ def build_stat_coll_cmd(action, config, source):
return [], False

for coll_check in collector_checkers:
cmd.extend(['-Xclang',
'-analyzer-checker=' + coll_check])
cmd.extend(['-Xclang', f'-analyzer-checker={coll_check}'])

compile_lang = action.lang
if not has_flag('-x', cmd):
cmd.extend(['-x', compile_lang])

if not has_flag('--target', cmd) and \
action.target.get(compile_lang, "") != "":
cmd.append("--target=" + action.target[compile_lang])
if not has_flag('--target', cmd) and action.target != "":
cmd.append(f"--target={action.target}")

if not has_flag('-std', cmd) and not has_flag('--std', cmd):
cmd.append(action.compiler_standard.get(compile_lang, ""))
cmd.append(action.compiler_standard)

cmd.extend(prepend_all(
'-isystem',
action.compiler_includes.get(compile_lang, [])))
cmd.extend(prepend_all('-isystem', action.compiler_includes))

if source:
cmd.append(source)
Expand Down
11 changes: 4 additions & 7 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,8 @@ def construct_analyzer_cmd(self, result_handler):
analyzer_cmd.extend(['-x', compile_lang])

if not has_flag('--target', analyzer_cmd) and \
self.buildaction.target.get(compile_lang, "") != "":
analyzer_cmd.append(
"--target=" + self.buildaction.target.get(compile_lang,
""))
self.buildaction.target != "":
analyzer_cmd.append(f"--target={self.buildaction.target}")

if not has_flag('-arch', analyzer_cmd) and \
self.buildaction.arch != "":
Expand All @@ -255,12 +253,11 @@ def construct_analyzer_cmd(self, result_handler):

analyzer_cmd.extend(prepend_all(
'-isystem',
self.buildaction.compiler_includes[compile_lang]))
self.buildaction.compiler_includes))

if not has_flag('-std', analyzer_cmd) and not \
has_flag('--std', analyzer_cmd):
analyzer_cmd.append(
self.buildaction.compiler_standard.get(compile_lang, ""))
analyzer_cmd.append(self.buildaction.compiler_standard)

analyzer_cmd.extend(compiler_warnings)

Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/buildlog/build_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __hash__(self):
hash_content = []
hash_content.extend(self.analyzer_options)
hash_content.append(str(self.analyzer_type))
hash_content.append(self.target[self.lang])
hash_content.append(self.target)
hash_content.append(self.source)
return hash(''.join(hash_content))

Expand Down
Loading

0 comments on commit ba974e1

Please sign in to comment.