File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ Rulesets for running codechecker in a single Bazel job.
1919load (
2020 "compile_commands.bzl" ,
2121 "compile_commands_aspect" ,
22- "compile_commands_impl " ,
22+ "get_compile_commands_json_and_srcs " ,
2323 "platforms_transition" ,
2424)
2525load (
@@ -58,19 +58,7 @@ def _codechecker_impl(ctx):
5858 py_runtime_info = ctx .attr ._python_runtime [PyRuntimeInfo ]
5959 python_path = py_runtime_info .interpreter_path
6060
61- # Get compile_commands.json file and source files
62- compile_commands = None
63- source_files = None
64- for output in compile_commands_impl (ctx ):
65- if type (output ) == "DefaultInfo" :
66- compile_commands = output .files .to_list ()[0 ]
67- source_files = output .default_runfiles .files .to_list ()
68- if not compile_commands :
69- fail ("Failed to generate compile_commands.json file!" )
70- if not source_files :
71- fail ("Failed to collect source files!" )
72- if compile_commands != ctx .outputs .compile_commands :
73- fail ("Seems compile_commands.json file is incorrect!" )
61+ compile_commands , source_files = get_compile_commands_json_and_srcs (ctx )
7462
7563 # Convert flacc calls to clang in compile_commands.json
7664 # and save to codechecker_commands.json
Original file line number Diff line number Diff line change @@ -418,6 +418,29 @@ def compile_commands_impl(ctx):
418418 ),
419419 ]
420420
421+ def get_compile_commands_json_and_srcs (ctx ):
422+ """ Creates the compilation database for internal use.
423+
424+ Returns:
425+ compile_commands - location of the compilation database file
426+ source_files - files to analyze
427+ """
428+ # Get compile_commands.json file and source files
429+ compile_commands = None
430+ source_files = None
431+ for output in compile_commands_impl (ctx ):
432+ if type (output ) == "DefaultInfo" :
433+ compile_commands = output .files .to_list ()[0 ]
434+ source_files = output .default_runfiles .files .to_list ()
435+ if not compile_commands :
436+ fail ("Failed to generate compile_commands.json file!" )
437+ if not source_files :
438+ fail ("Failed to collect source files!" )
439+ if compile_commands != ctx .outputs .compile_commands :
440+ fail ("Seems compile_commands.json file is incorrect!" )
441+
442+ return compile_commands , source_files
443+
421444_compile_commands = rule (
422445 implementation = compile_commands_impl ,
423446 attrs = {
You can’t perform that action at this time.
0 commit comments