Skip to content

Commit

Permalink
BaseTools/BuildReport: Improve compile_commands generation
Browse files Browse the repository at this point in the history
This produces output that matches CodeChecker log command

- Set directory to build output path
- Set build destination to the object created instead of the path
- Add recursive macro support
- Add lookup in module.Macros dictionary
- Add leading include flag to include list
- Add source file to compile commands

Signed-off-by: Jeff Brasen <[email protected]>
  • Loading branch information
jbrasen authored and mergify[bot] committed Jun 15, 2024
1 parent d8095b3 commit aa99d36
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions BaseTools/Source/Python/build/BuildReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2416,20 +2416,27 @@ def GenerateCompileInfo(self):
# Generate compile command for each c file
#
compile_command["file"] = source.Path
compile_command["directory"] = source.Dir
compile_command["directory"] = module.BuildDir
build_command = module.BuildRules[source.Ext].CommandList[0]
destination = os.path.join (module.OutputDir, os.path.join (source.SubDir, source.BaseName + ".obj"))
build_command_variables = re.findall(r"\$\((.*?)\)", build_command)
for var in build_command_variables:
while build_command_variables:
var = build_command_variables.pop()
var_tokens = var.split("_")
var_main = var_tokens[0]
if len(var_tokens) == 1:
if var == "INC":
var_value = inc_flag + f" {inc_flag}".join(module.IncludePathList)
elif var in module.Macros:
var_value = module.Macros[var]
elif len(var_tokens) == 1:
var_value = module.BuildOption[var_main]["PATH"]
else:
var_value = module.BuildOption[var_main][var_tokens[1]]
build_command = build_command.replace(f"$({var})", var_value)
include_files = f" {inc_flag}".join(module.IncludePathList)
build_command = build_command.replace("${src}", include_files)
build_command = build_command.replace("${dst}", module.OutputDir)
build_command = build_command.replace("${src}", source.Path)
build_command = build_command.replace("${dst}", destination)
build_command = build_command.replace("$@", destination)
build_command_variables.extend (re.findall(r"\$\((.*?)\)", var_value))

# Remove un defined macros
compile_command["command"] = re.sub(r"\$\(.*?\)", "", build_command)
Expand Down

0 comments on commit aa99d36

Please sign in to comment.