예제 #1
0
def TrimEdkSourceCode(Source, Target):
    EdkLogger.verbose("\t%s -> %s" % (Source, Target))
    CreateDirectory(os.path.dirname(Target))

    try:
        f = open (Source,'rb')
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
    # read whole file
    Lines = f.read()
    f.close()

    NewLines = None
    for Re,Repl in gImportCodePatterns:
        if NewLines == None:
            NewLines = Re.sub(Repl, Lines)
        else:
            NewLines = Re.sub(Repl, NewLines)

    # save all lines if trimmed
    if Source == Target and NewLines == Lines:
        return

    try:
        f = open (Target,'wb')
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
    f.write(NewLines)
    f.close()
예제 #2
0
파일: Database.py 프로젝트: b-man/edk2
    def InitDatabase(self, NewDatabase = True):
        EdkLogger.verbose("\nInitialize ECC database started ...")
        #
        # Drop all old existing tables
        #
        if NewDatabase:
            if os.path.exists(self.DbPath):
                os.remove(self.DbPath)
        self.Conn = sqlite3.connect(self.DbPath, isolation_level = 'DEFERRED')
        self.Conn.execute("PRAGMA page_size=4096")
        self.Conn.execute("PRAGMA synchronous=OFF")
        # to avoid non-ascii charater conversion error
        self.Conn.text_factory = str
        self.Cur = self.Conn.cursor()

        self.TblDataModel = TableDataModel(self.Cur)
        self.TblFile = TableFile(self.Cur)
        self.TblFunction = TableFunction(self.Cur)
        self.TblIdentifier = TableIdentifier(self.Cur)
        self.TblPcd = TablePcd(self.Cur)
        self.TblReport = TableReport(self.Cur)
        self.TblInf = ModuleTable(self.Cur)
        self.TblDec = PackageTable(self.Cur)
        self.TblDsc = PlatformTable(self.Cur)
        self.TblFdf = TableFdf(self.Cur)

        #
        # Create new tables
        #
        if NewDatabase:
            self.TblDataModel.Create()
            self.TblFile.Create()
            self.TblFunction.Create()
            self.TblPcd.Create()
            self.TblReport.Create()
            self.TblInf.Create()
            self.TblDec.Create()
            self.TblDsc.Create()
            self.TblFdf.Create()

        #
        # Init each table's ID
        #
        self.TblDataModel.InitID()
        self.TblFile.InitID()
        self.TblFunction.InitID()
        self.TblPcd.InitID()
        self.TblReport.InitID()
        self.TblInf.InitID()
        self.TblDec.InitID()
        self.TblDsc.InitID()
        self.TblFdf.InitID()

        #
        # Initialize table DataModel
        #
        if NewDatabase:
            self.TblDataModel.InitTable()

        EdkLogger.verbose("Initialize ECC database ... DONE!")
예제 #3
0
파일: StrGather.py 프로젝트: ksoju/rainbow
def GetFileList(SourceFileList, IncludeList, SkipList):
    if IncludeList is None:
        EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, "Include path for unicode file is not defined")

    FileList = []
    if SkipList is None:
        SkipList = []

    for File in SourceFileList:
        for Dir in IncludeList:
            if not os.path.exists(Dir):
                continue
            File = os.path.join(Dir, File.Path)
            #
            # Ignore Dir
            #
            if os.path.isfile(File) != True:
                continue
            #
            # Ignore file listed in skip list
            #
            IsSkip = False
            for Skip in SkipList:
                if os.path.splitext(File)[1].upper() == Skip.upper():
                    EdkLogger.verbose("Skipped %s for string token uses search" % File)
                    IsSkip = True
                    break

            if not IsSkip:
                FileList.append(File)

            break

    return FileList
예제 #4
0
    def InitDatabase(self, NewDatabase=True):
        EdkLogger.verbose("\nInitialize ECC database started ...")
        #
        # Drop all old existing tables
        #
        if NewDatabase:
            if os.path.exists(self.DbPath):
                os.remove(self.DbPath)
        self.Conn = sqlite3.connect(self.DbPath, isolation_level='DEFERRED')
        self.Conn.execute("PRAGMA page_size=4096")
        self.Conn.execute("PRAGMA synchronous=OFF")
        # to avoid non-ascii character conversion error
        self.Conn.text_factory = str
        self.Cur = self.Conn.cursor()

        self.TblDataModel = TableDataModel(self.Cur)
        self.TblFile = TableFile(self.Cur)
        self.TblFunction = TableFunction(self.Cur)
        self.TblIdentifier = TableIdentifier(self.Cur)
        self.TblPcd = TablePcd(self.Cur)
        self.TblReport = TableReport(self.Cur)
        self.TblInf = ModuleTable(self.Cur)
        self.TblDec = PackageTable(self.Cur)
        self.TblDsc = PlatformTable(self.Cur)
        self.TblFdf = TableFdf(self.Cur)

        #
        # Create new tables
        #
        if NewDatabase:
            self.TblDataModel.Create()
            self.TblFile.Create()
            self.TblFunction.Create()
            self.TblPcd.Create()
            self.TblReport.Create()
            self.TblInf.Create()
            self.TblDec.Create()
            self.TblDsc.Create()
            self.TblFdf.Create()

        #
        # Init each table's ID
        #
        self.TblDataModel.InitID()
        self.TblFile.InitID()
        self.TblFunction.InitID()
        self.TblPcd.InitID()
        self.TblReport.InitID()
        self.TblInf.InitID()
        self.TblDec.InitID()
        self.TblDsc.InitID()
        self.TblFdf.InitID()

        #
        # Initialize table DataModel
        #
        if NewDatabase:
            self.TblDataModel.InitTable()

        EdkLogger.verbose("Initialize ECC database ... DONE!")
예제 #5
0
파일: StrGather.py 프로젝트: b-man/edk2
def GetFileList(SourceFileList, IncludeList, SkipList):
    if IncludeList is None:
        EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, "Include path for unicode file is not defined")

    FileList = []
    if SkipList is None:
        SkipList = []

    for File in SourceFileList:
        for Dir in IncludeList:
            if not os.path.exists(Dir):
                continue
            File = os.path.join(Dir, File.Path)
            #
            # Ignore Dir
            #
            if os.path.isfile(File) != True:
                continue
            #
            # Ignore file listed in skip list
            #
            IsSkip = False
            for Skip in SkipList:
                if os.path.splitext(File)[1].upper() == Skip.upper():
                    EdkLogger.verbose("Skipped %s for string token uses search" % File)
                    IsSkip = True
                    break

            if not IsSkip:
                FileList.append(File)

            break

    return FileList
예제 #6
0
    def InsertOneFile(self, File):
        # Insert a record for file
        FileID = self.TblFile.Insert(File.Name,
                                     File.ExtName,
                                     File.Path,
                                     File.FullPath,
                                     Model=File.Model,
                                     TimeStamp=File.TimeStamp)
        IdTable = TableIdentifier(self.Cur)
        IdTable.Table = "Identifier%s" % FileID
        IdTable.Create()

        # Insert function of file
        for Function in File.FunctionList:
            FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
                                    Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
                                    Function.BodyStartLine, Function.BodyStartColumn, FileID, \
                                    Function.FunNameStartLine, Function.FunNameStartColumn)

            # Insert Identifier of function
            for Identifier in Function.IdentifierList:
                IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                        FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
        # Insert Identifier of file
        for Identifier in File.IdentifierList:
            IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                    FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)

        EdkLogger.verbose("Insert information from file %s ... DONE!" %
                          File.FullPath)
예제 #7
0
 def InitTable(self):
     EdkLogger.verbose("\nInitialize table DataModel started ...")
     for Item in DataClass.MODEL_LIST:
         CrossIndex = Item[1]
         Name = Item[0]
         Description = Item[0]
         self.Insert(CrossIndex, Name, Description)
     EdkLogger.verbose("Initialize table DataModel ... DONE!")
예제 #8
0
 def InitTable(self):
     EdkLogger.verbose("\nInitialize table DataModel started ...")
     for Item in DataClass.MODEL_LIST:
         CrossIndex = Item[1]
         Name = Item[0]
         Description = Item[0]
         self.Insert(CrossIndex, Name, Description)
     EdkLogger.verbose("Initialize table DataModel ... DONE!")
예제 #9
0
def DataRestore(File):
    Data = None
    Fd = None
    try:
        Fd = open(File, 'rb')
        Data = cPickle.load(Fd)
    except Exception, e:
        EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e)))
        Data = None
예제 #10
0
 def CheckModuleExists(self, Guid, Version, ReturnCode=DEPEX_CHECK_SUCCESS):
     EdkLogger.verbose("\nCheck module exists in workspace started ...")
     ModuleList = []
     ModuleList = self.IpiDb.GetModInPackage(Guid, Version)
     ModuleList.extend(self.IpiDb.GetStandaloneModule(Guid, Version))
     EdkLogger.verbose("Check module exists in workspace ... DONE!")
     if len(ModuleList) > 0:
         return True
     else:
         ReturnCode = DEPEX_CHECK_MODULE_NOT_FOUND
         return False
예제 #11
0
 def InitTable(self):
     EdkLogger.verbose("\nInitialize table DataModel started ...")
     Count = self.GetCount()
     if Count is not None and Count != 0:
         return
     for Item in DataClass.MODEL_LIST:
         CrossIndex = Item[1]
         Name = Item[0]
         Description = Item[0]
         self.Insert(CrossIndex, Name, Description)
     EdkLogger.verbose("Initialize table DataModel ... DONE!")
예제 #12
0
    def CheckPackageExists(self, Guid, Version, ReturnCode=DEPEX_CHECK_SUCCESS):
        EdkLogger.verbose("\nCheck package exists in workspace started ...")
        PkgList = []
        PkgList = self.IpiDb.GetPackage(Guid, Version)
        if len(PkgList) > 0:
            return True
        else:
            ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
            return False

        EdkLogger.verbose("Check package exists in workspace ... DONE!")
예제 #13
0
    def CheckDpExists(self, Guid, Version, ReturnCode=DEPEX_CHECK_SUCCESS):
        EdkLogger.verbose("\nCheck DP exists in workspace started ...")
        DpList = []
        DpList = self.IpiDb.GetDp(Guid, Version)
        if len(DpList) > 0:
            return True
        else:
            ReturnCode = DEPEX_CHECK_DP_NOT_FOUND
            return False

        EdkLogger.verbose("Check DP exists in workspace ... DONE!")
예제 #14
0
    def UpdateIdentifierBelongsToFunction_disabled(self):
        EdkLogger.verbose(
            "Update 'BelongsToFunction' for Identifiers started ...")

        SqlCommand = """select ID, BelongsToFile, StartLine, EndLine, Model from Identifier"""
        EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
        self.Cur.execute(SqlCommand)
        Records = self.Cur.fetchall()
        for Record in Records:
            IdentifierID = Record[0]
            BelongsToFile = Record[1]
            StartLine = Record[2]
            EndLine = Record[3]
            Model = Record[4]

            #
            # Check whether an identifier belongs to a function
            #
            EdkLogger.debug(4, "For common identifiers ... ")
            SqlCommand = """select ID from Function
                        where StartLine < %s and EndLine > %s
                        and BelongsToFile = %s""" % (StartLine, EndLine,
                                                     BelongsToFile)
            EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
            self.Cur.execute(SqlCommand)
            IDs = self.Cur.fetchall()
            for ID in IDs:
                SqlCommand = """Update Identifier set BelongsToFunction = %s where ID = %s""" % (
                    ID[0], IdentifierID)
                EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
                self.Cur.execute(SqlCommand)

            #
            # Check whether the identifier is a function header
            #
            EdkLogger.debug(4, "For function headers ... ")
            if Model == DataClass.MODEL_IDENTIFIER_COMMENT:
                SqlCommand = """select ID from Function
                        where StartLine = %s + 1
                        and BelongsToFile = %s""" % (EndLine, BelongsToFile)
                EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
                self.Cur.execute(SqlCommand)
                IDs = self.Cur.fetchall()
                for ID in IDs:
                    SqlCommand = """Update Identifier set BelongsToFunction = %s, Model = %s where ID = %s""" % (
                        ID[0], DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER,
                        IdentifierID)
                    EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
                    self.Cur.execute(SqlCommand)

        EdkLogger.verbose(
            "Update 'BelongsToFunction' for Identifiers ... DONE")
예제 #15
0
    def InsertOneFile(self, File):
        #
        # Insert a record for file
        #
        FileID = self.TblFile.Insert(File.Name,
                                     File.ExtName,
                                     File.Path,
                                     File.FullPath,
                                     Model=File.Model,
                                     TimeStamp=File.TimeStamp)

        if File.Model == DataClass.MODEL_FILE_C or File.Model == DataClass.MODEL_FILE_H:
            IdTable = TableIdentifier(self.Cur)
            IdTable.Table = "Identifier%s" % FileID
            IdTable.Create()
            #
            # Insert function of file
            #
            for Function in File.FunctionList:
                FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
                                        Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
                                        Function.BodyStartLine, Function.BodyStartColumn, FileID, \
                                        Function.FunNameStartLine, Function.FunNameStartColumn)
                #
                # Insert Identifier of function
                #
                for Identifier in Function.IdentifierList:
                    IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                            FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
                #
                # Insert Pcd of function
                #
                for Pcd in Function.PcdList:
                    PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
                                       FileID, FunctionID, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)
            #
            # Insert Identifier of file
            #
            for Identifier in File.IdentifierList:
                IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                        FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
            #
            # Insert Pcd of file
            #
            for Pcd in File.PcdList:
                PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
                                   FileID, -1, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)

        EdkLogger.verbose("Insert information from file %s ... DONE!" %
                          File.FullPath)
예제 #16
0
파일: Database.py 프로젝트: b-man/edk2
    def UpdateIdentifierBelongsToFunction_disabled(self):
        EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")

        SqlCommand = """select ID, BelongsToFile, StartLine, EndLine, Model from Identifier"""
        EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
        self.Cur.execute(SqlCommand)
        Records = self.Cur.fetchall()
        for Record in Records:
            IdentifierID = Record[0]
            BelongsToFile = Record[1]
            StartLine = Record[2]
            EndLine = Record[3]
            Model = Record[4]

            #
            # Check whether an identifier belongs to a function
            #
            EdkLogger.debug(4, "For common identifiers ... ")
            SqlCommand = """select ID from Function
                        where StartLine < %s and EndLine > %s
                        and BelongsToFile = %s""" % (StartLine, EndLine, BelongsToFile)
            EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
            self.Cur.execute(SqlCommand)
            IDs = self.Cur.fetchall()
            for ID in IDs:
                SqlCommand = """Update Identifier set BelongsToFunction = %s where ID = %s""" % (ID[0], IdentifierID)
                EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
                self.Cur.execute(SqlCommand)

            #
            # Check whether the identifier is a function header
            #
            EdkLogger.debug(4, "For function headers ... ")
            if Model == DataClass.MODEL_IDENTIFIER_COMMENT:
                SqlCommand = """select ID from Function
                        where StartLine = %s + 1
                        and BelongsToFile = %s""" % (EndLine, BelongsToFile)
                EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
                self.Cur.execute(SqlCommand)
                IDs = self.Cur.fetchall()
                for ID in IDs:
                    SqlCommand = """Update Identifier set BelongsToFunction = %s, Model = %s where ID = %s""" % (ID[0], DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, IdentifierID)
                    EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
                    self.Cur.execute(SqlCommand)

        EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")
예제 #17
0
파일: Table.py 프로젝트: lersek/edk2
    def Query(self):
        EdkLogger.verbose("\nQuery table %s started ..." % self.Table)
        SqlCommand = """select * from %s""" % self.Table
        self.Cur.execute(SqlCommand)
        for Rs in self.Cur:
            EdkLogger.verbose(str(Rs))

        TotalCount = self.GetCount()
        EdkLogger.verbose("*** Total %s records in table %s ***" % (TotalCount, self.Table) )
        EdkLogger.verbose("Query tabel %s DONE!" % self.Table)
예제 #18
0
    def Query(self):
        EdkLogger.verbose("\nQuery tabel %s started ..." % self.Table)
        SqlCommand = """select * from %s""" % self.Table
        self.Cur.execute(SqlCommand)
        for Rs in self.Cur:
            EdkLogger.verbose(str(Rs))

        TotalCount = self.GetCount()
        EdkLogger.verbose("*** Total %s records in table %s ***" % (TotalCount, self.Table) )
        EdkLogger.verbose("Query tabel %s DONE!" % self.Table)
예제 #19
0
파일: Database.py 프로젝트: b-man/edk2
    def InsertOneFile(self, File):
        #
        # Insert a record for file
        #
        FileID = self.TblFile.Insert(File.Name, File.ExtName, File.Path, File.FullPath, Model = File.Model, TimeStamp = File.TimeStamp)

        if File.Model == DataClass.MODEL_FILE_C or File.Model == DataClass.MODEL_FILE_H:
            IdTable = TableIdentifier(self.Cur)
            IdTable.Table = "Identifier%s" % FileID
            IdTable.Create()
            #
            # Insert function of file
            #
            for Function in File.FunctionList:
                FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
                                        Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
                                        Function.BodyStartLine, Function.BodyStartColumn, FileID, \
                                        Function.FunNameStartLine, Function.FunNameStartColumn)
                #
                # Insert Identifier of function
                #
                for Identifier in Function.IdentifierList:
                    IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                            FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
                #
                # Insert Pcd of function
                #
                for Pcd in Function.PcdList:
                    PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
                                       FileID, FunctionID, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)
            #
            # Insert Identifier of file
            #
            for Identifier in File.IdentifierList:
                IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                        FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
            #
            # Insert Pcd of file
            #
            for Pcd in File.PcdList:
                PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
                                   FileID, -1, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)

        EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath)
예제 #20
0
파일: Database.py 프로젝트: ksoju/rainbow
    def UpdateIdentifierBelongsToFunction(self):
        EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")

        SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""
        Records = self.TblFunction.Exec(SqlCommand)
        Data1 = []
        Data2 = []
        for Record in Records:
            FunctionID = Record[0]
            BelongsToFile = Record[1]
            StartLine = Record[2]
            EndLine = Record[3]

            SqlCommand = """Update Identifier%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \
                        (BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine)
            self.TblIdentifier.Exec(SqlCommand)

            SqlCommand = """Update Identifier%s set BelongsToFunction = %s, Model = %s where BelongsToFile = %s and Model = %s and EndLine = %s""" % \
                         (BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1)
            self.TblIdentifier.Exec(SqlCommand)
예제 #21
0
파일: Database.py 프로젝트: etiago/vbox
    def UpdateIdentifierBelongsToFunction(self):
        EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")

        SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""
        Records = self.TblFunction.Exec(SqlCommand)
        Data1 = []
        Data2 = []
        for Record in Records:
            FunctionID = Record[0]
            BelongsToFile = Record[1]
            StartLine = Record[2]
            EndLine = Record[3]

            SqlCommand = """Update Identifier%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \
                        (BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine)
            self.TblIdentifier.Exec(SqlCommand)

            SqlCommand = """Update Identifier%s set BelongsToFunction = %s, Model = %s where BelongsToFile = %s and Model = %s and EndLine = %s""" % \
                         (BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1)
            self.TblIdentifier.Exec(SqlCommand)
예제 #22
0
    def GetDp(self, Guid, Version):
        
        if Version == None or len(Version.strip()) == 0:
            Version = 'N/A'
            EdkLogger.verbose("\nGetting list of DP install information started ...")
            (DpGuid, DpVersion) = (Guid, Version)
            SqlCommand = """select * from %s where DpGuid ='%s'""" % (self.DpTable, DpGuid)
            self.Cur.execute(SqlCommand)
        
        else:
            EdkLogger.verbose("\nGetting DP install information started ...")
            (DpGuid, DpVersion) = (Guid, Version)
            SqlCommand = """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.DpTable, DpGuid, DpVersion)
            self.Cur.execute(SqlCommand)

        DpList = []
        for DpInfo in self.Cur:
            DpGuid = DpInfo[0]
            DpVersion = DpInfo[1]
            InstallTime = DpInfo[2]
            PkgFileName = DpInfo[3]
            DpList.append((DpGuid, DpVersion, InstallTime, PkgFileName))
        
        EdkLogger.verbose("Getting DP install information ... DONE!")
        return DpList
예제 #23
0
    def CheckModuleDepexSatisfied(self, ModuleObj, DpObj=None, ReturnCode=DEPEX_CHECK_SUCCESS):
        EdkLogger.verbose("\nCheck module depex met by workspace started ...")
        for Dep in ModuleObj.PackageDependencies:
            Exist = self.CheckPackageExists(Dep.PackageGuid, Dep.PackageVersion, ReturnCode)
            if not Exist:
                if DpObj == None:
                    ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
                    return False
                for GuidVerPair in DpObj.PackageSurfaceArea.keys():
                    if Dep.PackageGuid == GuidVerPair[0]:
                        if Dep.PackageVersion == None or len(Dep.PackageVersion) == 0:
                            break
                        if Dep.PackageVersion == GuidVerPair[1]:
                            break
                        else:
                            ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
                            return False
                else:
                    ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
                    return False
        return True

        EdkLogger.verbose("Check module depex met by workspace ... DONE!")
예제 #24
0
파일: Database.py 프로젝트: etiago/vbox
    def InsertOneFile(self, File):
        # Insert a record for file
        FileID = self.TblFile.Insert(File.Name, File.ExtName, File.Path, File.FullPath, Model = File.Model, TimeStamp = File.TimeStamp)
        IdTable = TableIdentifier(self.Cur)
        IdTable.Table = "Identifier%s" % FileID
        IdTable.Create()

        # Insert function of file
        for Function in File.FunctionList:
            FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
                                    Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
                                    Function.BodyStartLine, Function.BodyStartColumn, FileID, \
                                    Function.FunNameStartLine, Function.FunNameStartColumn)

            # Insert Identifier of function
            for Identifier in Function.IdentifierList:
                IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                        FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
        # Insert Identifier of file
        for Identifier in File.IdentifierList:
            IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
                                    FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)

        EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath)
예제 #25
0
파일: Database.py 프로젝트: b-man/edk2
#       EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
#       self.Cur.executemany(SqlCommand, Data2)
#
#       EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")


##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
    EdkLogger.Initialize()
    #EdkLogger.SetLevel(EdkLogger.VERBOSE)
    EdkLogger.SetLevel(EdkLogger.DEBUG_0)
    EdkLogger.verbose("Start at " + time.strftime('%H:%M:%S', time.localtime()))

    Db = Database(DATABASE_PATH)
    Db.InitDatabase()
    Db.QueryTable(Db.TblDataModel)

    identifier1 = DataClass.IdentifierClass(-1, '', '', "i''1", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 32,  43,  54,  43)
    identifier2 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 15,  43,  20,  43)
    identifier3 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 55,  43,  58,  43)
    identifier4 = DataClass.IdentifierClass(-1, '', '', "i1'", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 77,  43,  88,  43)
    fun1 = DataClass.FunctionClass(-1, '', '', 'fun1', '', 21, 2, 60,  45, 1, 23, 0, [], [])
    file = DataClass.FileClass(-1, 'F1', 'c', 'C:\\', 'C:\\F1.exe', DataClass.MODEL_FILE_C, '2007-12-28', [fun1], [identifier1, identifier2, identifier3, identifier4], [])
    Db.InsertOneFile(file)
    Db.UpdateIdentifierBelongsToFunction()

    Db.QueryTable(Db.TblFile)
예제 #26
0
 def Drop(self):
     SqlCommand = """drop table IF EXISTS %s""" % self.Table
     self.Cur.execute(SqlCommand)
     EdkLogger.verbose("Drop tabel %s ... DONE!" % self.Table)
 def VerboseLogger (msg):
     EdkLogger.verbose(msg)
예제 #28
0
def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
    CreateDirectory(os.path.dirname(Target))
    try:
        with open(Source, "r") as File:
            Lines = File.readlines()
    except IOError:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
    except:
        EdkLogger.error("Trim", AUTOGEN_ERROR, "TrimPreprocessedFile: Error while processing file", File=Source)

    PreprocessedFile = ""
    InjectedFile = ""
    LineIndexOfOriginalFile = None
    NewLines = []
    LineControlDirectiveFound = False
    for Index in range(len(Lines)):
        Line = Lines[Index]
        #
        # Find out the name of files injected by preprocessor from the lines
        # with Line Control directive
        #
        MatchList = gLineControlDirective.findall(Line)
        if MatchList != []:
            MatchList = MatchList[0]
            if len(MatchList) == 2:
                LineNumber = int(MatchList[0], 0)
                InjectedFile = MatchList[1]
                InjectedFile = os.path.normpath(InjectedFile)
                InjectedFile = os.path.normcase(InjectedFile)
                # The first injected file must be the preprocessed file itself
                if PreprocessedFile == "":
                    PreprocessedFile = InjectedFile
            LineControlDirectiveFound = True
            continue
        elif PreprocessedFile == "" or InjectedFile != PreprocessedFile:
            continue

        if LineIndexOfOriginalFile is None:
            #
            # Any non-empty lines must be from original preprocessed file.
            # And this must be the first one.
            #
            LineIndexOfOriginalFile = Index
            EdkLogger.verbose("Found original file content starting from line %d"
                              % (LineIndexOfOriginalFile + 1))

        if TrimLong:
            Line = gLongNumberPattern.sub(r"\1", Line)
        # convert HEX number format if indicated
        if ConvertHex:
            Line = gHexNumberPattern.sub(r"0\2h", Line)
        else:
            Line = gHexNumberPattern.sub(r"\1\2", Line)

        # convert Decimal number format
        Line = gDecNumberPattern.sub(r"\1", Line)

        if LineNumber is not None:
            EdkLogger.verbose("Got line directive: line=%d" % LineNumber)
            # in case preprocessor removed some lines, like blank or comment lines
            if LineNumber <= len(NewLines):
                # possible?
                NewLines[LineNumber - 1] = Line
            else:
                if LineNumber > (len(NewLines) + 1):
                    for LineIndex in range(len(NewLines), LineNumber-1):
                        NewLines.append(TAB_LINE_BREAK)
                NewLines.append(Line)
            LineNumber = None
            EdkLogger.verbose("Now we have lines: %d" % len(NewLines))
        else:
            NewLines.append(Line)

    # in case there's no line directive or linemarker found
    if (not LineControlDirectiveFound) and NewLines == []:
        MulPatternFlag = False
        SinglePatternFlag = False
        Brace = 0
        for Index in range(len(Lines)):
            Line = Lines[Index]
            if MulPatternFlag == False and gTypedef_MulPattern.search(Line) is None:
                if SinglePatternFlag == False and gTypedef_SinglePattern.search(Line) is None:
                    # remove "#pragram pack" directive
                    if gPragmaPattern.search(Line) is None:
                        NewLines.append(Line)
                    continue
                elif SinglePatternFlag == False:
                    SinglePatternFlag = True
                if Line.find(";") >= 0:
                    SinglePatternFlag = False
            elif MulPatternFlag == False:
                # found "typedef struct, typedef union, union, struct", keep its position and set a flag
                MulPatternFlag = True

            # match { and } to find the end of typedef definition
            if Line.find("{") >= 0:
                Brace += 1
            elif Line.find("}") >= 0:
                Brace -= 1

            # "typedef struct, typedef union, union, struct" must end with a ";"
            if Brace == 0 and Line.find(";") >= 0:
                MulPatternFlag = False

    # save to file
    try:
        with open(Target, 'w') as File:
            File.writelines(NewLines)
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
예제 #29
0
 def Create(self, SqlCommand):
     self.Cur.execute(SqlCommand)
     self.ID = 0
     EdkLogger.verbose(SqlCommand + " ... DONE!")
예제 #30
0
 def InitDatabase(self):
     EdkLogger.verbose("\nInitialize IPI database started ...")
     
     #
     # Create new table
     #
     SqlCommand = """create table IF NOT EXISTS %s (DpGuid TEXT NOT NULL,
                                                    DpVersion TEXT NOT NULL,
                                                    InstallTime REAL NOT NULL,
                                                    PkgFileName TEXT,
                                                    PRIMARY KEY (DpGuid, DpVersion)
                                                   )""" % self.DpTable
     self.Cur.execute(SqlCommand)
     
     SqlCommand = """create table IF NOT EXISTS %s (FilePath TEXT NOT NULL,
                                                    DpGuid TEXT,
                                                    DpVersion TEXT,
                                                    PRIMARY KEY (FilePath)
                                                   )""" % self.DpFileListTable
     self.Cur.execute(SqlCommand)
     
     SqlCommand = """create table IF NOT EXISTS %s (PackageGuid TEXT NOT NULL,
                                                    PackageVersion TEXT NOT NULL,
                                                    InstallTime REAL NOT NULL,
                                                    DpGuid TEXT,
                                                    DpVersion TEXT,
                                                    InstallPath TEXT NOT NULL,
                                                    PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)
                                                   )""" % self.PkgTable
     self.Cur.execute(SqlCommand)
     
     SqlCommand = """create table IF NOT EXISTS %s (ModuleGuid TEXT NOT NULL,
                                                    ModuleVersion TEXT NOT NULL,
                                                    InstallTime REAL NOT NULL,
                                                    PackageGuid TEXT,
                                                    PackageVersion TEXT,
                                                    InstallPath TEXT NOT NULL,
                                                    PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)
                                                   )""" % self.ModInPkgTable
     self.Cur.execute(SqlCommand)
     
     SqlCommand = """create table IF NOT EXISTS %s (ModuleGuid TEXT NOT NULL,
                                                    ModuleVersion TEXT NOT NULL,
                                                    InstallTime REAL NOT NULL,
                                                    DpGuid TEXT,
                                                    DpVersion TEXT,
                                                    InstallPath TEXT NOT NULL,
                                                    PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)
                                                   )""" % self.StandaloneModTable
     self.Cur.execute(SqlCommand)
     
     SqlCommand = """create table IF NOT EXISTS %s (ModuleGuid TEXT NOT NULL,
                                                    ModuleVersion TEXT NOT NULL,
                                                    InstallPath TEXT NOT NULL,
                                                    DepexGuid TEXT,
                                                    DepexVersion TEXT
                                                   )""" % self.ModDepexTable
     self.Cur.execute(SqlCommand)
     
     self.Conn.commit()
     
     EdkLogger.verbose("Initialize IPI database ... DONE!")
예제 #31
0
 def Query(self):
     SqlCommand = """select * from %s""" % self.Table
     self.Cur.execute(SqlCommand)
     for Rs in self.Cur:
         EdkLogger.verbose(str(Rs))
     TotalCount = self.GetId()
예제 #32
0
파일: Database.py 프로젝트: etiago/vbox
    def InitDatabase(self, NewDatabase = True):
        EdkLogger.verbose("\nInitialize EOT database started ...")
        #
        # Drop all old existing tables
        #
        if NewDatabase:
            if os.path.exists(self.DbPath):
                os.remove(self.DbPath)
        self.Conn = sqlite3.connect(self.DbPath, isolation_level = 'DEFERRED')
        self.Conn.execute("PRAGMA page_size=8192")
        self.Conn.execute("PRAGMA synchronous=OFF")
        # to avoid non-ascii charater conversion error
        self.Conn.text_factory = str
        self.Cur = self.Conn.cursor()

        self.TblDataModel = TableDataModel(self.Cur)
        self.TblFile = TableFile(self.Cur)
        self.TblFunction = TableFunction(self.Cur)
        self.TblIdentifier = TableIdentifier(self.Cur)
        self.TblReport = TableEotReport(self.Cur)
        self.TblInf = TableInf(self.Cur)
        self.TblDec = TableDec(self.Cur)
        self.TblDsc = TableDsc(self.Cur)
        self.TblFdf = TableFdf(self.Cur)
        self.TblQuery = TableQuery(self.Cur)
        self.TblQuery2 = TableQuery(self.Cur)
        self.TblQuery2.Table = 'Query2'

        # Create new tables
        if NewDatabase:
            self.TblDataModel.Create()
            self.TblFile.Create()
            self.TblFunction.Create()
            self.TblReport.Create()
            self.TblInf.Create()
            self.TblDec.Create()
            self.TblDsc.Create()
            self.TblFdf.Create()
            self.TblQuery.Create()
            self.TblQuery2.Create()

        # Init each table's ID
        self.TblDataModel.InitID()
        self.TblFile.InitID()
        self.TblFunction.InitID()
        self.TblReport.InitID()
        self.TblInf.InitID()
        self.TblDec.InitID()
        self.TblDsc.InitID()
        self.TblFdf.InitID()
        self.TblQuery.Drop()
        self.TblQuery.Create()
        self.TblQuery.InitID()
        self.TblQuery2.Drop()
        self.TblQuery2.Create()
        self.TblQuery2.InitID()

        # Initialize table DataModel
        if NewDatabase:
            self.TblDataModel.InitTable()

        EdkLogger.verbose("Initialize EOT database ... DONE!")
예제 #33
0
#       SqlCommand = """Update ? set BelongsToFunction = ?, Model = ? where BelongsToFile = ? and Model = ? and EndLine = ?"""
#       EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
#       self.Cur.executemany(SqlCommand, Data2)
#
#       EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")

##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
    EdkLogger.Initialize()
    #EdkLogger.SetLevel(EdkLogger.VERBOSE)
    EdkLogger.SetLevel(EdkLogger.DEBUG_0)
    EdkLogger.verbose("Start at " +
                      time.strftime('%H:%M:%S', time.localtime()))

    Db = Database(DATABASE_PATH)
    Db.InitDatabase()
    Db.QueryTable(Db.TblDataModel)

    identifier1 = DataClass.IdentifierClass(-1, '', '', "i''1", 'aaa',
                                            DataClass.MODEL_IDENTIFIER_COMMENT,
                                            1, -1, 32, 43, 54, 43)
    identifier2 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa',
                                            DataClass.MODEL_IDENTIFIER_COMMENT,
                                            1, -1, 15, 43, 20, 43)
    identifier3 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa',
                                            DataClass.MODEL_IDENTIFIER_COMMENT,
                                            1, -1, 55, 43, 58, 43)
    identifier4 = DataClass.IdentifierClass(-1, '', '', "i1'", 'aaa',
예제 #34
0
    def InitDatabase(self, NewDatabase=True):
        EdkLogger.verbose("\nInitialize EOT database started ...")
        #
        # Drop all old existing tables
        #
        if NewDatabase:
            if os.path.exists(self.DbPath):
                os.remove(self.DbPath)
        self.Conn = sqlite3.connect(self.DbPath, isolation_level='DEFERRED')
        self.Conn.execute("PRAGMA page_size=8192")
        self.Conn.execute("PRAGMA synchronous=OFF")
        # to avoid non-ascii charater conversion error
        self.Conn.text_factory = str
        self.Cur = self.Conn.cursor()

        self.TblDataModel = TableDataModel(self.Cur)
        self.TblFile = TableFile(self.Cur)
        self.TblFunction = TableFunction(self.Cur)
        self.TblIdentifier = TableIdentifier(self.Cur)
        self.TblReport = TableEotReport(self.Cur)
        self.TblInf = TableInf(self.Cur)
        self.TblDec = TableDec(self.Cur)
        self.TblDsc = TableDsc(self.Cur)
        self.TblFdf = TableFdf(self.Cur)
        self.TblQuery = TableQuery(self.Cur)
        self.TblQuery2 = TableQuery(self.Cur)
        self.TblQuery2.Table = 'Query2'

        # Create new tables
        if NewDatabase:
            self.TblDataModel.Create()
            self.TblFile.Create()
            self.TblFunction.Create()
            self.TblReport.Create()
            self.TblInf.Create()
            self.TblDec.Create()
            self.TblDsc.Create()
            self.TblFdf.Create()
            self.TblQuery.Create()
            self.TblQuery2.Create()

        # Init each table's ID
        self.TblDataModel.InitID()
        self.TblFile.InitID()
        self.TblFunction.InitID()
        self.TblReport.InitID()
        self.TblInf.InitID()
        self.TblDec.InitID()
        self.TblDsc.InitID()
        self.TblFdf.InitID()
        self.TblQuery.Drop()
        self.TblQuery.Create()
        self.TblQuery.InitID()
        self.TblQuery2.Drop()
        self.TblQuery2.Create()
        self.TblQuery2.InitID()

        # Initialize table DataModel
        if NewDatabase:
            self.TblDataModel.InitTable()

        EdkLogger.verbose("Initialize EOT database ... DONE!")
예제 #35
0
파일: Table.py 프로젝트: lersek/edk2
 def Create(self, SqlCommand):
     self.Cur.execute(SqlCommand)
     self.ID = 0
     EdkLogger.verbose(SqlCommand + " ... DONE!")
예제 #36
0
def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
    CreateDirectory(os.path.dirname(Target))
    try:
        f = open (Source, 'r')
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)

    # read whole file
    Lines = f.readlines()
    f.close()

    PreprocessedFile = ""
    InjectedFile = ""
    LineIndexOfOriginalFile = None
    NewLines = []
    LineControlDirectiveFound = False
    for Index in range(len(Lines)):
        Line = Lines[Index]
        #
        # Find out the name of files injected by preprocessor from the lines
        # with Line Control directive
        #
        MatchList = gLineControlDirective.findall(Line)
        if MatchList != []:
            MatchList = MatchList[0]
            if len(MatchList) == 2:
                LineNumber = int(MatchList[0], 0)
                InjectedFile = MatchList[1]
                # The first injetcted file must be the preprocessed file itself
                if PreprocessedFile == "":
                    PreprocessedFile = InjectedFile
            LineControlDirectiveFound = True
            continue
        elif PreprocessedFile == "" or InjectedFile != PreprocessedFile:
            continue

        if LineIndexOfOriginalFile == None:
            #
            # Any non-empty lines must be from original preprocessed file.
            # And this must be the first one.
            #
            LineIndexOfOriginalFile = Index
            EdkLogger.verbose("Found original file content starting from line %d"
                              % (LineIndexOfOriginalFile + 1))

        if TrimLong:
            Line = gLongNumberPattern.sub(r"\1", Line)
        # convert HEX number format if indicated
        if ConvertHex:
            Line = gHexNumberPattern.sub(r"0\2h", Line)
        else:
            Line = gHexNumberPattern.sub(r"\1\2", Line)

        # convert Decimal number format
        Line = gDecNumberPattern.sub(r"\1", Line)

        if LineNumber != None:
            EdkLogger.verbose("Got line directive: line=%d" % LineNumber)
            # in case preprocessor removed some lines, like blank or comment lines
            if LineNumber <= len(NewLines):
                # possible?
                NewLines[LineNumber - 1] = Line
            else:
                if LineNumber > (len(NewLines) + 1):
                    for LineIndex in range(len(NewLines), LineNumber-1):
                        NewLines.append(os.linesep)
                NewLines.append(Line)
            LineNumber = None
            EdkLogger.verbose("Now we have lines: %d" % len(NewLines))
        else:
            NewLines.append(Line)

    # in case there's no line directive or linemarker found
    if (not LineControlDirectiveFound) and NewLines == []:
        NewLines = Lines

    # save to file
    try:
        f = open (Target, 'wb')
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
    f.writelines(NewLines)
    f.close()
예제 #37
0
def GetModuleLibInstances(Module,
                          Platform,
                          BuildDatabase,
                          Arch,
                          Target,
                          Toolchain,
                          FileName='',
                          EdkLogger=None):
    if Module.LibInstances:
        return Module.LibInstances
    ModuleType = Module.ModuleType

    # add forced library instances (specified under LibraryClasses sections)
    #
    # If a module has a MODULE_TYPE of USER_DEFINED,
    # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
    #
    if Module.ModuleType != SUP_MODULE_USER_DEFINED:
        for LibraryClass in Platform.LibraryClasses.GetKeys():
            if LibraryClass.startswith("NULL") and Platform.LibraryClasses[
                    LibraryClass, Module.ModuleType]:
                Module.LibraryClasses[LibraryClass] = Platform.LibraryClasses[
                    LibraryClass, Module.ModuleType]

    # add forced library instances (specified in module overrides)
    for LibraryClass in Platform.Modules[str(Module)].LibraryClasses:
        if LibraryClass.startswith("NULL"):
            Module.LibraryClasses[LibraryClass] = Platform.Modules[str(
                Module)].LibraryClasses[LibraryClass]

    # EdkII module
    LibraryConsumerList = [Module]
    Constructor = []
    ConsumedByList = OrderedListDict()
    LibraryInstance = OrderedDict()

    if not Module.LibraryClass:
        EdkLogger.verbose("")
        EdkLogger.verbose("Library instances of module [%s] [%s]:" %
                          (str(Module), Arch))

    while len(LibraryConsumerList) > 0:
        M = LibraryConsumerList.pop()
        for LibraryClassName in M.LibraryClasses:
            if LibraryClassName not in LibraryInstance:
                # override library instance for this module
                LibraryPath = Platform.Modules[str(Module)].LibraryClasses.get(
                    LibraryClassName, Platform.LibraryClasses[LibraryClassName,
                                                              ModuleType])
                if LibraryPath is None:
                    LibraryPath = M.LibraryClasses.get(LibraryClassName)
                    if LibraryPath is None:
                        if not Module.LibraryClass:
                            EdkLogger.error(
                                "build",
                                RESOURCE_NOT_AVAILABLE,
                                "Instance of library class [%s] is not found" %
                                LibraryClassName,
                                File=FileName,
                                ExtraData=
                                "in [%s] [%s]\n\tconsumed by module [%s]" %
                                (str(M), Arch, str(Module)))
                        else:
                            return []

                LibraryModule = BuildDatabase[LibraryPath, Arch, Target,
                                              Toolchain]
                # for those forced library instance (NULL library), add a fake library class
                if LibraryClassName.startswith("NULL"):
                    LibraryModule.LibraryClass.append(
                        LibraryClassObject(LibraryClassName, [ModuleType]))
                elif LibraryModule.LibraryClass is None \
                     or len(LibraryModule.LibraryClass) == 0 \
                     or (ModuleType != SUP_MODULE_USER_DEFINED and ModuleType != SUP_MODULE_HOST_APPLICATION
                         and ModuleType not in LibraryModule.LibraryClass[0].SupModList):
                    # only USER_DEFINED can link against any library instance despite of its SupModList
                    if not Module.LibraryClass:
                        EdkLogger.error("build", OPTION_MISSING,
                                        "Module type [%s] is not supported by library instance [%s]" \
                                        % (ModuleType, LibraryPath), File=FileName,
                                        ExtraData="consumed by [%s]" % str(Module))
                    else:
                        return []

                LibraryInstance[LibraryClassName] = LibraryModule
                LibraryConsumerList.append(LibraryModule)
                if not Module.LibraryClass:
                    EdkLogger.verbose("\t" + str(LibraryClassName) + " : " +
                                      str(LibraryModule))
            else:
                LibraryModule = LibraryInstance[LibraryClassName]

            if LibraryModule is None:
                continue

            if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:
                Constructor.append(LibraryModule)

            # don't add current module itself to consumer list
            if M != Module:
                if M in ConsumedByList[LibraryModule]:
                    continue
                ConsumedByList[LibraryModule].append(M)
    #
    # Initialize the sorted output list to the empty set
    #
    SortedLibraryList = []
    #
    # Q <- Set of all nodes with no incoming edges
    #
    LibraryList = []  #LibraryInstance.values()
    Q = []
    for LibraryClassName in LibraryInstance:
        M = LibraryInstance[LibraryClassName]
        LibraryList.append(M)
        if not ConsumedByList[M]:
            Q.append(M)

    #
    # start the  DAG algorithm
    #
    while True:
        EdgeRemoved = True
        while Q == [] and EdgeRemoved:
            EdgeRemoved = False
            # for each node Item with a Constructor
            for Item in LibraryList:
                if Item not in Constructor:
                    continue
                # for each Node without a constructor with an edge e from Item to Node
                for Node in ConsumedByList[Item]:
                    if Node in Constructor:
                        continue
                    # remove edge e from the graph if Node has no constructor
                    ConsumedByList[Item].remove(Node)
                    EdgeRemoved = True
                    if not ConsumedByList[Item]:
                        # insert Item into Q
                        Q.insert(0, Item)
                        break
                if Q != []:
                    break
        # DAG is done if there's no more incoming edge for all nodes
        if Q == []:
            break

        # remove node from Q
        Node = Q.pop()
        # output Node
        SortedLibraryList.append(Node)

        # for each node Item with an edge e from Node to Item do
        for Item in LibraryList:
            if Node not in ConsumedByList[Item]:
                continue
            # remove edge e from the graph
            ConsumedByList[Item].remove(Node)

            if ConsumedByList[Item]:
                continue
            # insert Item into Q, if Item has no other incoming edges
            Q.insert(0, Item)

    #
    # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
    #
    for Item in LibraryList:
        if ConsumedByList[Item] and Item in Constructor and len(
                Constructor) > 1:
            if not Module.LibraryClass:
                ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join(
                    str(L) for L in ConsumedByList[Item])
                EdkLogger.error("build",
                                BUILD_ERROR,
                                'Library [%s] with constructors has a cycle' %
                                str(Item),
                                ExtraData=ErrorMessage,
                                File=FileName)
            else:
                return []
        if Item not in SortedLibraryList:
            SortedLibraryList.append(Item)

    #
    # Build the list of constructor and destructor names
    # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
    #
    SortedLibraryList.reverse()
    Module.LibInstances = SortedLibraryList
    SortedLibraryList = [
        lib.SetReferenceModule(Module) for lib in SortedLibraryList
    ]
    return SortedLibraryList
예제 #38
0
                InjectedFile = os.path.normcase(InjectedFile)
                # The first injected file must be the preprocessed file itself
                if PreprocessedFile == "":
                    PreprocessedFile = InjectedFile
            LineControlDirectiveFound = True
            continue
        elif PreprocessedFile == "" or InjectedFile != PreprocessedFile:
            continue

        if LineIndexOfOriginalFile is None:
            #
            # Any non-empty lines must be from original preprocessed file.
            # And this must be the first one.
            #
            LineIndexOfOriginalFile = Index
            EdkLogger.verbose("Found original file content starting from line %d"
                              % (LineIndexOfOriginalFile + 1))

        if TrimLong:
            Line = gLongNumberPattern.sub(r"\1", Line)
        # convert HEX number format if indicated
        if ConvertHex:
            Line = gHexNumberPattern.sub(r"0\2h", Line)
        else:
            Line = gHexNumberPattern.sub(r"\1\2", Line)

        # convert Decimal number format
        Line = gDecNumberPattern.sub(r"\1", Line)

        if LineNumber is not None:
            EdkLogger.verbose("Got line directive: line=%d" % LineNumber)
            # in case preprocessor removed some lines, like blank or comment lines
예제 #39
0
 def Query(self):
     SqlCommand = """select * from %s""" % self.Table
     self.Cur.execute(SqlCommand)
     for Rs in self.Cur:
         EdkLogger.verbose(str(Rs))
     TotalCount = self.GetId()
예제 #40
0
파일: Table.py 프로젝트: lersek/edk2
 def Drop(self):
     SqlCommand = """drop table IF EXISTS %s""" % self.Table
     self.Cur.execute(SqlCommand)
     EdkLogger.verbose("Drop tabel %s ... DONE!" % self.Table)
예제 #41
0
 def VerboseLogger(msg):
     EdkLogger.verbose(msg)
예제 #42
0
파일: Trim.py 프로젝트: kraxel/edk2
def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
    CreateDirectory(os.path.dirname(Target))
    try:
        f = open (Source, 'r')
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)

    # read whole file
    Lines = f.readlines()
    f.close()

    PreprocessedFile = ""
    InjectedFile = ""
    LineIndexOfOriginalFile = None
    NewLines = []
    LineControlDirectiveFound = False
    for Index in range(len(Lines)):
        Line = Lines[Index]
        #
        # Find out the name of files injected by preprocessor from the lines
        # with Line Control directive
        #
        MatchList = gLineControlDirective.findall(Line)
        if MatchList != []:
            MatchList = MatchList[0]
            if len(MatchList) == 2:
                LineNumber = int(MatchList[0], 0)
                InjectedFile = MatchList[1]
                # The first injetcted file must be the preprocessed file itself
                if PreprocessedFile == "":
                    PreprocessedFile = InjectedFile
            LineControlDirectiveFound = True
            continue
        elif PreprocessedFile == "" or InjectedFile != PreprocessedFile:
            continue

        if LineIndexOfOriginalFile is None:
            #
            # Any non-empty lines must be from original preprocessed file.
            # And this must be the first one.
            #
            LineIndexOfOriginalFile = Index
            EdkLogger.verbose("Found original file content starting from line %d"
                              % (LineIndexOfOriginalFile + 1))

        if TrimLong:
            Line = gLongNumberPattern.sub(r"\1", Line)
        # convert HEX number format if indicated
        if ConvertHex:
            Line = gHexNumberPattern.sub(r"0\2h", Line)
        else:
            Line = gHexNumberPattern.sub(r"\1\2", Line)

        # convert Decimal number format
        Line = gDecNumberPattern.sub(r"\1", Line)

        if LineNumber is not None:
            EdkLogger.verbose("Got line directive: line=%d" % LineNumber)
            # in case preprocessor removed some lines, like blank or comment lines
            if LineNumber <= len(NewLines):
                # possible?
                NewLines[LineNumber - 1] = Line
            else:
                if LineNumber > (len(NewLines) + 1):
                    for LineIndex in range(len(NewLines), LineNumber-1):
                        NewLines.append(os.linesep)
                NewLines.append(Line)
            LineNumber = None
            EdkLogger.verbose("Now we have lines: %d" % len(NewLines))
        else:
            NewLines.append(Line)

    # in case there's no line directive or linemarker found
    if (not LineControlDirectiveFound) and NewLines == []:
        MulPatternFlag = False
        SinglePatternFlag = False
        Brace = 0
        for Index in range(len(Lines)):
            Line = Lines[Index]
            if MulPatternFlag == False and gTypedef_MulPattern.search(Line) is None:
                if SinglePatternFlag == False and gTypedef_SinglePattern.search(Line) is None:
                    # remove "#pragram pack" directive
                    if gPragmaPattern.search(Line) is None:
                        NewLines.append(Line)
                    continue
                elif SinglePatternFlag == False:
                    SinglePatternFlag = True
                if Line.find(";") >= 0:
                    SinglePatternFlag = False
            elif MulPatternFlag == False:
                # found "typedef struct, typedef union, union, struct", keep its position and set a flag
                MulPatternFlag = True

            # match { and } to find the end of typedef definition
            if Line.find("{") >= 0:
                Brace += 1
            elif Line.find("}") >= 0:
                Brace -= 1

            # "typedef struct, typedef union, union, struct" must end with a ";"
            if Brace == 0 and Line.find(";") >= 0:
                MulPatternFlag = False

    # save to file
    try:
        f = open (Target, 'wb')
    except:
        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
    f.writelines(NewLines)
    f.close()