summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python
diff options
context:
space:
mode:
authorkowsiks <kowsiks@ami.com>2026-03-31 14:41:36 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2026-07-17 13:54:11 +0300
commit2fc0e060efc25a2b9dd24bfc5844bf18e33b999e (patch)
tree2af0fac31130d5425082e4a825c0431f8f6ac66c /BaseTools/Source/Python
parent9fcb50d56cbec9e715024b5700cbbb318dcda742 (diff)
downloadedk2-2fc0e060efc25a2b9dd24bfc5844bf18e33b999e.tar.xz
BaseTools/build.py: Use full source file path for dependency generation
During Silent build,NMAKE suppresses the command echo entirely. As a result, the only output in ProcOut is the MSVC compiler’s output lines. Without the command echo, there is no full path in the output to identify which source file is currently being compiled. For unique basenames this is not an issue, but for namesake files (for example, AmdSev.c located in different directories), it is impossible to determine which file’s includes are being listed. This change improves dependency generation for MSVC builds by introducing explicit handling for source files with duplicate basenames (namesake sources). A new variable current_source_abs is added to consistently track the resolved absolute path of the active source file instead of repeatedly recomputing it from SourceFileAbsPathMap. To correctly resolve namesake files in silent builds (where compiler commands are not echoed), a namesake_queue is introduced, which preserves source ordering and sequentially maps basename occurrences to their corresponding full paths. Additionally, a cc_cmd_in_output flag is implemented to detect the presence of compiler command lines in the output stream; when present, source paths are derived directly from command-line arguments, otherwise the queue-based resolution is used. This ensures correct mapping of basenames to absolute paths across the silent builds, fixing incorrect dependency generation when multiple source files share the same name. Signed-off-by: Kowsik S <kowsiks@ami.com>
Diffstat (limited to 'BaseTools/Source/Python')
-rw-r--r--BaseTools/Source/Python/AutoGen/IncludesAutoGen.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py b/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py
index 5ec26eb98b..18ac5b8463 100644
--- a/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py
@@ -3,6 +3,7 @@
#
# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>
+# Copyright (c) 2026, American Megatrends International LLC. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
from Common.caching import cached_property
@@ -11,6 +12,7 @@ import Common.LongFilePathOs as os
from Common.BuildToolError import *
from Common.Misc import SaveFileOnChange, PathClass
from Common.Misc import TemplateString
+from collections import deque
import sys
gIsFileMap = {}
@@ -191,12 +193,28 @@ ${END}
return
ModuleDepDict = {}
current_source = ""
+ current_source_abs = ""
SourceFileAbsPathMap = self.SourceFileList
+ namesake_queue = {}
+ cc_cmd_in_output = False
+ if self.HasNamesakeSourceFile:
+ basename_to_paths = {}
+ for _, (_, input_file) in sorted(self.TargetFileList.items()):
+ basename = os.path.basename(input_file.File)
+ if not basename:
+ continue
+ if basename not in basename_to_paths:
+ basename_to_paths[basename] = []
+ basename_to_paths[basename].append(input_file.Path)
+ namesake_queue = {
+ k: deque(v) for k, v in basename_to_paths.items() if len(v) > 1
+ }
for line in DepList:
line = line.strip()
if self.HasNamesakeSourceFile:
for cc_cmd in self.CcPPCommandPathSet:
if cc_cmd in line:
+ cc_cmd_in_output = True
if '''"'''+cc_cmd+'''"''' in line:
cc_options = line[len(cc_cmd)+2:].split()
else:
@@ -214,13 +232,18 @@ ${END}
# SourceFileAbsPathMap = {os.path.basename(item):item for item in cc_options if not item.startswith("/") and os.path.exists(item)}
if line in SourceFileAbsPathMap:
current_source = line
- if current_source not in ModuleDepDict:
- ModuleDepDict[SourceFileAbsPathMap[current_source]] = []
+ if (self.HasNamesakeSourceFile and not cc_cmd_in_output
+ and line in namesake_queue and namesake_queue[line]):
+ current_source_abs = namesake_queue[line].popleft()
+ else:
+ current_source_abs = SourceFileAbsPathMap[current_source]
+ if current_source_abs not in ModuleDepDict:
+ ModuleDepDict[current_source_abs] = []
elif "Note: including file:" == line.lstrip()[:21]:
if not current_source:
EdkLogger.error("build",BUILD_ERROR, "Parse /showIncludes output failed. line: %s. \n" % line, RaiseError=False)
else:
- ModuleDepDict[SourceFileAbsPathMap[current_source]].append(line.lstrip()[22:].strip())
+ ModuleDepDict[current_source_abs].append(line.lstrip()[22:].strip())
for source_abs in ModuleDepDict:
if ModuleDepDict[source_abs]: