public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH] BaseTools/BuildReport: Improve compile_commands generation
@ 2024-02-08  8:11 Jeff Brasen via groups.io
  0 siblings, 0 replies; only message in thread
From: Jeff Brasen via groups.io @ 2024-02-08  8:11 UTC (permalink / raw)
  To: devel
  Cc: guillermo.a.palomino.sosa, bob.c.feng, gaoliming, rebecca,
	yuwei.chen, Jeff Brasen

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 <jbrasen@nvidia.com>
---
 BaseTools/Source/Python/build/BuildReport.py | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py
index 26dfe53fff..497bbbd646 100644
--- a/BaseTools/Source/Python/build/BuildReport.py
+++ b/BaseTools/Source/Python/build/BuildReport.py
@@ -2416,20 +2416,27 @@ class BuildReport(object):
                                 # 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)
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115267): https://edk2.groups.io/g/devel/message/115267
Mute This Topic: https://groups.io/mt/104241385/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-08 16:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-08  8:11 [edk2-devel] [PATCH] BaseTools/BuildReport: Improve compile_commands generation Jeff Brasen via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox