def _parse_dec_for_package(self, path_to_package): ''' find DEC for package and parse it''' # find DEC file path = None try: allEntries = os.listdir(path_to_package) for entry in allEntries: if entry.lower().endswith(".dec"): path = os.path.join(path_to_package, entry) except Exception: self.logger.error( "Exception: Unable to find DEC for package:{0}".format( path_to_package)) return None if path is None: self.logger.error( "Unable to find DEC for package:{0}".format(path_to_package)) return None wsr_dec_path = self.edk2_path_obj.GetEdk2RelativePathFromAbsolutePath( path) if path is None or wsr_dec_path == "" or not os.path.isfile(path): self.logger.error( "Unable to convert path for DEC for package: {0}".format( path_to_package)) return None # parse it dec = DecParser() dec.SetBaseAbsPath(self.edk2_path_obj.WorkspacePath).SetPackagePaths( self.edk2_path_obj.PackagePathList) dec.ParseFile(wsr_dec_path) return dec
def parse_guids_from_dec(stream, filename: str) -> list: """ find all guids in a dec file contents contained with stream stream: lines of dec file content filename: abspath to dec file """ results = [] dec = DecParser() dec.ParseStream(stream) for p in dec.Protocols: results.append(GuidListEntry(p.name, str(p.guid).upper(), filename)) for p in dec.PPIs: results.append(GuidListEntry(p.name, str(p.guid).upper(), filename)) for p in dec.Guids: results.append(GuidListEntry(p.name, str(p.guid).upper(), filename)) try: results.append( GuidListEntry(dec.Dict["PACKAGE_NAME"], dec.Dict["PACKAGE_GUID"], filename)) except: logging.warning("Failed to find Package Guid from dec file: " + filename) return results
def test_valid_input(self): a = DecParser() st = io.StringIO(TestDecParser.SAMPLE_DEC_FILE) a.ParseStream(st) self.assertEqual(a.Dict["PACKAGE_NAME"], "TestDecParserPkg") self.assertEqual(a.Dict["PACKAGE_GUID"], "57e8a49e-1b3f-41a0-a552-55ad831c15a8") self.assertEqual(len(a.Guids), 3) self.assertEqual(len(a.Protocols), 1) self.assertEqual(len(a.PPIs), 2)
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None): overall_status = 0 LibraryClassIgnore = [] abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename) abs_dec_path = self.__GetPkgDec(abs_pkg_path) wsr_dec_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(abs_dec_path) if abs_dec_path is None or wsr_dec_path is "" or not os.path.isfile(abs_dec_path): tc.SetSkipped() tc.LogStdError("No DEC file {0} in package {1}".format(abs_dec_path, abs_pkg_path)) return -1 # Get all include folders dec = DecParser() dec.SetBaseAbsPath(Edk2pathObj.WorkspacePath).SetPackagePaths(Edk2pathObj.PackagePathList) dec.ParseFile(wsr_dec_path) AllHeaderFiles = [] for includepath in dec.IncludePaths: ## Get all header files in the library folder AbsLibraryIncludePath = os.path.join(abs_pkg_path, includepath, "Library") if(not os.path.isdir(AbsLibraryIncludePath)): continue hfiles = self.WalkDirectoryForExtension([".h"], AbsLibraryIncludePath) hfiles = [os.path.relpath(x,abs_pkg_path) for x in hfiles] # make package root relative path hfiles = [x.replace("\\", "/") for x in hfiles] # make package relative path AllHeaderFiles.extend(hfiles) if len(AllHeaderFiles) == 0: tc.SetSkipped() tc.LogStdError(f"No Library include folder in any Include path") return -1 # Remove ignored paths if "IgnoreHeaderFile" in pkgconfig: for a in pkgconfig["IgnoreHeaderFile"]: try: tc.LogStdOut("Ignoring Library Header File {0}".format(a)) AllHeaderFiles.remove(a) except: tc.LogStdError("LibraryClassCheck.IgnoreHeaderFile -> {0} not found. Invalid Header File".format(a)) logging.info("LibraryClassCheck.IgnoreHeaderFile -> {0} not found. Invalid Header File".format(a)) if "IgnoreLibraryClass" in pkgconfig: LibraryClassIgnore = pkgconfig["IgnoreLibraryClass"] ## Attempt to find library classes for lcd in dec.LibraryClasses: ## Check for correct file path separator if "\\" in lcd.path: tc.LogStdError("LibraryClassCheck.DecFilePathSeparator -> {0} invalid.".format(lcd.path)) logging.error("LibraryClassCheck.DecFilePathSeparator -> {0} invalid.".format(lcd.path)) overall_status += 1 continue if lcd.name in LibraryClassIgnore: tc.LogStdOut("Ignoring Library Class Name {0}".format(lcd.name)) LibraryClassIgnore.remove(lcd.name) continue logging.debug(f"Looking for Library Class {lcd.path}") try: AllHeaderFiles.remove(lcd.path) except ValueError: tc.LogStdError(f"Library {lcd.name} with path {lcd.path} not found in package filesystem") logging.error(f"Library {lcd.name} with path {lcd.path} not found in package filesystem") overall_status += 1 ## any remaining AllHeaderFiles are not described in DEC for h in AllHeaderFiles: tc.LogStdError(f"Library Header File {h} not declared in package DEC {wsr_dec_path}") logging.error(f"Library Header File {h} not declared in package DEC {wsr_dec_path}") overall_status += 1 ## Warn about any invalid library class names in the ignore list for r in LibraryClassIgnore: tc.LogStdError("LibraryClassCheck.IgnoreLibraryClass -> {0} not found. Library Class not found".format(r)) logging.info("LibraryClassCheck.IgnoreLibraryClass -> {0} not found. Library Class not found".format(r)) # If XML object exists, add result if overall_status is not 0: tc.SetFailed("LibraryClassCheck {0} Failed. Errors {1}".format(wsr_dec_path, overall_status), "CHECK_FAILED") else: tc.SetSuccess() return overall_status