[Feature]: Verify library INF implements specified library class from the DSC
What does the feature solve?
This feature will resolve hard to detect linking errors due to libraries not being properly linked to components due to a quiet mismatch of library classes
Describe the solution
A check can take place inside of BaseTools/Source/Workspace/DscBuildData.py that, when parsing library class lines in a DSC's [LibraryClasses.*] section or library override of the [Components.*] section, will verify that the library instance actually implements the library by checking which LIBRARY_CLASS definitions exist in the INF [Defines] section.
That is to say, for the following example: TestLib|Path/To/BaseTestLib.inf, that BaseTestLib.inf has LIBRARY_CLASS = TestLib defined in the [Defines] section.
The following commit shows a possible implementation that has been verified to catch invalid linking in the two scenarios above: https://github.com/tianocore/edk2/compare/master...Javagedes:edk2:verify-library-class
Attached is a diff: diff.txt
@mdkinney @makubacki @YuweiChen1110
Have you considered any alternatives?
No response
Additional context
No response
@YuweiChen1110, can you please advise on next steps?
It is valuable to add this feature. The feature's quality is under testing. After testing, will reply with the result. And then we can submit the formal PR in edk2-basetools repo and send out the patch with email for edk2 repo.
Hi @YuweiChen1110, I found an issue in the diff I previously sent you. In larger builds the same DSC is parsed multiple times, thus each mismatch is reported multiple times also, which is not preferred. I spent some time getting a fix to only report each mismatch once. Below is the diff. Here is also a link to the two commits: https://github.com/microsoft/mu_basecore/compare/release/202302...Javagedes:mu_basecore:library-check
Thanks for the contribution and clarify!
When I tested this feature in my local build env, I encountered some errors and currently finding the root cause. Will update this issue with the error info after collection.
Thanks for your patience.
What issue are you seeing? I can debug tomorrow
Hi, the situation I encountered is shown below. It seems like not this feature's issue but with adding this feature a previously existing but undiscovered bug is exposed.
The situation is: a PCD in INF file is not defined in DEC file. The expected behavior of build system should be: raise the error "PCD [%s.%s] in [%s] is not found in dependent packages:"
However in some strange case, when we do not add this feature, the error will not be raised, after we add this feature, the error is raised correctly. It is very strange, and I am checking on the root cause.
From my side, we need to fix the bug firstly then merge this feature. Or it will block build system current use.
Will update the PR with debugging status.