Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseTools: Detect library class mismatch [REBASE&FF] #499

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BaseTools/Source/Python/AutoGen/AutoGenWorker.py
Javagedes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def run(self):
GlobalData.gEnableGenfdsMultiThread = self.data_pipe.Get("EnableGenfdsMultiThread")
GlobalData.gPlatformFinalPcds = self.data_pipe.Get("gPlatformFinalPcds")
GlobalData.file_lock = self.file_lock
GlobalData.gLogLibraryMismatch = False # MU_CHANGE
CommandTarget = self.data_pipe.Get("CommandTarget")
pcd_from_build_option = []
for pcd_tuple in self.data_pipe.Get("BuildOptPcd"):
Expand Down
2 changes: 1 addition & 1 deletion BaseTools/Source/Python/Common/GlobalData.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@
gSikpAutoGenCache = set()
# Common lock for the file access in multiple process AutoGens
file_lock = None

gLogLibraryMismatch = True # MU_CHANGE
42 changes: 42 additions & 0 deletions BaseTools/Source/Python/Workspace/DscBuildData.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
from collections import OrderedDict, defaultdict

LoggedLibraryWarnings = [] # MU_CHANGE

def _IsFieldValueAnArray (Value):
Value = Value.strip()
if Value.startswith(TAB_GUID) and Value.endswith(')'):
Expand Down Expand Up @@ -763,6 +765,14 @@ def Modules(self):
LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch)
LineNo = Record[-1]

# MU_CHANGE begin
# Validate that the Library instance implements the Library Class
if not self._ValidateLibraryClass(LibraryClass, LibraryPath) and self._ShouldLogLibrary(LineNo):
EdkLogger.warn("build",
f"{str(LibraryPath)} does not support LIBRARY_CLASS {LibraryClass}",
File=self.MetaFile)
# MU_CHANGE end

# check the file validation
ErrorCode, ErrorInfo = LibraryPath.Validate('.inf')
if ErrorCode != 0:
Expand Down Expand Up @@ -916,6 +926,15 @@ def LibraryClasses(self):
EdkLogger.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch, LibraryInstance, LibraryClass))
LibraryClassSet.add(LibraryClass)
LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch)

# MU_CHANGE begin
# Validate that the Library instance implements the Library Class
if not self._ValidateLibraryClass(LibraryClass, LibraryInstance) and self._ShouldLogLibrary(LineNo):
EdkLogger.warn("build",
f"{str(LibraryInstance)} does not support LIBRARY_CLASS {LibraryClass}",
File=self.MetaFile)
# MU_CHANGE end

# check the file validation
ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf')
if ErrorCode != 0:
Expand Down Expand Up @@ -1190,6 +1209,29 @@ def __ParsePcdFromCommandLine(self):
for item in delete_assign:
GlobalData.BuildOptionPcd.remove(item)

# MU_CHANGE begin
def _ValidateLibraryClass(self, LibraryClass: str, LibraryInstance: PathClass) -> bool:
if LibraryClass.upper().startswith('NULL'):
return True

ParsedLibraryInfo = self._Bdb[LibraryInstance, self._Arch, self._Target, self._Toolchain]

for LibraryClassObject in ParsedLibraryInfo.LibraryClass:
if LibraryClassObject.LibraryClass == LibraryClass:
return True
return False

def _ShouldLogLibrary(self, LineNo) -> bool:
if not GlobalData.gLogLibraryMismatch:
return False

if LineNo in LoggedLibraryWarnings:
return False

LoggedLibraryWarnings.append(LineNo)
return True
# MU_CHANGE end

@staticmethod
def HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''):
if FieldName:
Expand Down
20 changes: 0 additions & 20 deletions BaseTools/Source/Python/Workspace/WorkspaceCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,6 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
if LibraryClass.startswith("NULL"):
Module.LibraryClasses[LibraryClass] = Platform.Modules[str(Module)].LibraryClasses[LibraryClass]

# MU_CHANGE begin

# Compares the Library class being over written (var: LibraryClass) to the actual library class that is
# is doing the overridding.
#
# i.e. ExampleLib|Path/To/ExampleLibBase.inf:
# ensuring ExampleLib == LIBRARY_CLASS in the define section of ExampleLibBase.inf
else:
path = Platform.Modules[str(Module)].LibraryClasses[LibraryClass]
match = False
for LibraryClassObj in BuildDatabase[path, Arch, Target, Toolchain].LibraryClass:
if LibraryClass == LibraryClassObj.LibraryClass:
match = True

if not match:
EdkLogger.error("build", BUILD_ERROR,
"LIBRARY_CLASS for override: [%s] does not match the library class being overridden: [%s]" % (path, LibraryClass),
File=FileName)
# MU_CHANGE end

# EdkII module
LibraryConsumerList = [Module]
Constructor = []
Expand Down