Changed the uses of EdkLogger
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 26 Sep 2007 02:05:23 +0000 (02:05 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 26 Sep 2007 02:05:23 +0000 (02:05 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@756 7335b38e-4728-0410-8992-fb3ffe349368

16 files changed:
Source/Python/AutoGen/AutoGen.py
Source/Python/AutoGen/BuildEngine.py
Source/Python/AutoGen/BuildInfo.py
Source/Python/AutoGen/GenC.py
Source/Python/AutoGen/GenDepex.py
Source/Python/AutoGen/GenMake.py
Source/Python/AutoGen/StrGather.py
Source/Python/AutoGen/UniClassObject.py
Source/Python/Common/BuildToolError.py
Source/Python/Common/DscClassObject.py
Source/Python/Common/EdkIIWorkspaceBuild.py
Source/Python/Common/EdkLogger.py
Source/Python/Common/Misc.py
Source/Python/Common/String.py
Source/Python/Common/TargetTxtClassObject.py
Source/Python/Common/ToolDefClassObject.py

index 8e75db9..6b20eab 100755 (executable)
@@ -38,22 +38,23 @@ from Common.Misc import *
 from Common.String import *\r
 \r
 ## PlatformBuildClassObject database\r
-gPlatformDatabase = {}      # {arch : {dsc file path : PlatformBuildClassObject}}\r
+#gPlatformDatabase = {}      # {arch : {dsc file path : PlatformBuildClassObject}}\r
 \r
 ## ModuleBuildClassObject database\r
-gModuleDatabase = {}        # {arch : {inf file path : ModuleBuildClassObject}}\r
+#gModuleDatabase = {}        # {arch : {inf file path : ModuleBuildClassObject}}\r
 \r
 ## PackageBuildClassObject database\r
-gPackageDatabase = {}       # {arch : {dec file path : PackageBuildClassObject}}\r
+#gPackageDatabase = {}       # {arch : {dec file path : PackageBuildClassObject}}\r
 \r
 ## AutoGen object database\r
-gAutoGenDatabase = {}       # (module/package/platform obj, BuildTarget, ToolChain, Arch) : build info\r
+#gModuleAutoGenDatabase = {}         # (module file, BuildTarget, ToolChain, Arch) : ModuleAutoGen object\r
+#gPlatformAutoGenDatabase = {}       # (platform file, BuildTarget, ToolChain) : PlatformAutoGen object\r
 \r
 ## Shortcut global of WorkspaceBuild object representing current workspace\r
-gWorkspace = None\r
+#gWorkspace = None\r
 \r
 ## Shortcut global of current workspace directory\r
-gWorkspaceDir = ""\r
+#gWorkspaceDir = ""\r
 \r
 ## Regular expression for splitting Dependency Expression stirng into tokens\r
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
@@ -99,27 +100,331 @@ gAutoGenCodeFileName = "AutoGen.c"
 gAutoGenHeaderFileName = "AutoGen.h"\r
 gAutoGenDepexFileName = "%(module_name)s.depex"\r
 \r
-## Find the package containing the module\r
-#\r
-# Find out the package which contains the given module, according to the path\r
-# of the module and the package.\r
-#\r
-# @param  Module            The module to be found for\r
-# @param  PackageDatabase   Database containing all packages found\r
-#\r
-# @retval package           Package object if found\r
-# @retval None              None if not found\r
-#\r
-def FindModuleOwnerPackage(Module, PackageDatabase):\r
-    for PackagePath in PackageDatabase:\r
-        PackageDir = path.dirname(PackagePath)\r
+class PlatformAutoGen:\r
+    _Database = {}    # (platform file, BuildTarget, ToolChain) : PlatformAutoGen object\r
+\r
+    def Init(self, Workspace, PlatformFile, Target, Toolchain, ArchList):\r
+        self.PlatformFile = str(PlatformFile)\r
+        self.Workspace = Workspace\r
+        self.WorkspaceDir = Workspace.WorkspaceDir\r
+        self.ToolChain = Toolchain\r
+        #self.ToolChainFamily = "MSFT"\r
+        self.BuildTarget = Target\r
+        self.ArchList = ArchList\r
+\r
+        EdkLogger.verbose("\nAutoGen platform [%s] [%s]" % (self.PlatformFile, " ".join(self.ArchList)))\r
+\r
+        self.ModuleDatabase = {}\r
+        for a in Workspace.Build:\r
+            self.ModuleDatabase[a] = Workspace.Build[a].ModuleDatabase\r
+\r
+        self.PackageDatabase = {}\r
+        for a in Workspace.Build:\r
+            self.PackageDatabase[a] = Workspace.Build[a].PackageDatabase\r
+\r
+        self.PlatformDatabase = {}\r
+        for a in Workspace.Build:\r
+            self.PlatformDatabase[a] = Workspace.Build[a].PlatformDatabase\r
+\r
+        self.IsMakeFileCreated = False\r
+        self.IsCodeFileCreated = False\r
+\r
         #\r
-        # if package's path is the first part of module's path, bingo!\r
+        # autogen for platform\r
         #\r
-        if str(Module).find(PackageDir) == 0:\r
-            return PackageDatabase[PackagePath]\r
-    # nothing found\r
-    return None\r
+        self.BuildInfo = {}     # arch : PlatformBuildInfo Object\r
+        self.Platform = {}\r
+\r
+        for Arch in self.ArchList:\r
+            if Arch not in self.PlatformDatabase or self.PlatformFile not in self.PlatformDatabase[Arch]:\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR,\r
+                                "[%s] is not the active platform, or [%s] is not supported by the active platform!"\r
+                                % (PlatformFile, Arch))\r
+            Platform = self.PlatformDatabase[Arch][PlatformFile]\r
+            self.Platform[Arch] = Platform\r
+            self.BuildInfo[Arch] = self.CollectBuildInfo(Platform, Arch)\r
+        self._Database[self.PlatformFile, self.BuildTarget, self.ToolChain] = self\r
+\r
+    def __hash__(self):\r
+        return hash(self.PlatformFile)\r
+\r
+    def __str__(self):\r
+        return self.PlatformFile\r
+\r
+    @staticmethod\r
+    def GetAutoGen(Workspace, Platform, Target, Toolchain, ArchList):\r
+        Key = (Platform, Target, Toolchain)\r
+        if Key not in PlatformAutoGen._Database:\r
+            if ArchList == None or ArchList == []:\r
+                return None\r
+            AutoGenObject = PlatformAutoGen()\r
+            AutoGenObject.Init(Workspace, Platform, Target, Toolchain, ArchList)\r
+        return PlatformAutoGen._Database[Key]\r
+\r
+    def CollectBuildInfo(self, Platform, Arch):\r
+        Info = PlatformBuildInfo(Platform)\r
+\r
+        Info.Arch = Arch\r
+        Info.ToolChain = self.ToolChain\r
+        Info.BuildTarget = self.BuildTarget\r
+\r
+        Info.WorkspaceDir = self.WorkspaceDir\r
+        Info.SourceDir = path.dirname(Platform.DescFilePath)\r
+        Info.OutputDir = Platform.OutputDirectory\r
+        Info.BuildDir = path.join(Info.OutputDir, self.BuildTarget + "_" + self.ToolChain)\r
+        Info.MakeFileDir = Info.BuildDir\r
+\r
+        if self.Workspace.Fdf != "":\r
+            Info.FdfFile= path.join(self.WorkspaceDir, self.Workspace.Fdf)\r
+\r
+        Info.DynamicPcdList = self.GetDynamicPcdList(Platform, Arch)\r
+        Info.PcdTokenNumber = self.GeneratePcdTokenNumber(Platform, Info.DynamicPcdList)\r
+        Info.PackageList = self.PackageDatabase[Arch].values()\r
+\r
+        self.GetToolDefinition(Info)\r
+        Info.BuildRule = self.GetBuildRule()\r
+        Info.FdTargetList = self.Workspace.FdTargetList\r
+        Info.FvTargetList = self.Workspace.FvTargetList\r
+\r
+        return Info\r
+\r
+    def GetMakeFileDir(self):\r
+        return os.path.join(self.WorkspaceDir, self.BuildInfo[self.ArchList[0]].MakeFileDir)\r
+\r
+    def GetBuildRule(self):\r
+        return BuildRule(self.Workspace.WorkspaceFile(gBuildRuleFile))\r
+\r
+    def GetToolDefinition(self, Info):\r
+        ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
+        ToolCodeList = self.Workspace.ToolDef.ToolsDefTxtDatabase["COMMAND_TYPE"]\r
+        for Tool in ToolCodeList:\r
+            KeyBaseString = "%s_%s_%s_%s" % (Info.BuildTarget, Info.ToolChain, Info.Arch, Tool)\r
+\r
+            Key = "%s_PATH" % KeyBaseString\r
+            if Key not in ToolDefinition:\r
+                continue\r
+            Path = ToolDefinition[Key]\r
+\r
+            Key = "%s_FAMILY" % KeyBaseString\r
+            if Key in ToolDefinition:\r
+                Family = ToolDefinition[Key]\r
+            else:\r
+                Family = ""\r
+\r
+            Key = "%s_FLAGS" % KeyBaseString\r
+            if Key in ToolDefinition:\r
+                Option = ToolDefinition[Key]\r
+            else:\r
+                Option = ""\r
+\r
+            Key = "%s_DLL" % KeyBaseString\r
+            if Key in ToolDefinition:\r
+                Dll = ToolDefinition[Key]\r
+                os.environ["PATH"] = Dll + os.pathsep + os.environ["PATH"]\r
+            else:\r
+                Dll = ""\r
+\r
+            Key = KeyBaseString + "_OUTPUT"\r
+            if Key in ToolDefinition:\r
+                OutputFlag = ToolDefinition[Key]\r
+            elif (Family, Tool, "OUTPUT") in gOutputFlag:\r
+                OutputFlag = gOutputFlag[Family, Tool, "OUTPUT"]\r
+                if OutputFlag[0] == '"' and OutputFlag[-1] == '"':\r
+                    OutputFlag = OutputFlag[1:-1]\r
+            else:\r
+                OutputFlag = gDefaultOutputFlag\r
+\r
+            InputFlag = gIncludeFlag[Family]\r
+\r
+            Info.ToolPath[Tool] = Path\r
+            Info.ToolDllPath[Tool] = Dll\r
+            Info.ToolChainFamily[Tool] = Family\r
+            Info.ToolOption[Tool] = Option\r
+            Info.OutputFlag[Tool] = OutputFlag\r
+            Info.IncludeFlag[Tool] = InputFlag\r
+\r
+        # use family of CC as default toolchain family\r
+        #self.ToolChainFamily = Info.ToolChainFamily["CC"]\r
+        BuildOptions = Info.Platform.BuildOptions\r
+\r
+        for Key in BuildOptions:\r
+            Family = Key[0]\r
+            Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
+            if Tool not in Info.ToolPath:\r
+                continue\r
+            if Family != None and Family != "" and Family != Info.ToolChainFamily[Tool]:\r
+                continue\r
+            if Target == "*" or Target == Info.BuildTarget:\r
+                if Tag == "*" or Tag == Info.ToolChain:\r
+                    if Arch == "*" or Arch == Info.Arch:\r
+                        Info.BuildOption[Tool] = BuildOptions[Key]\r
+        for Tool in Info.ToolOption:\r
+            if Tool not in Info.BuildOption:\r
+                Info.BuildOption[Tool] = ""\r
+\r
+    def GetDynamicPcdList(self, Platform, Arch):\r
+        PcdList = []\r
+        NotFoundPcdList = set()\r
+        NoDatumTypePcdList = set()\r
+        PcdConsumerList = set()\r
+        for F in Platform.Modules:\r
+            M = self.ModuleDatabase[Arch][F]\r
+            for Key in M.Pcds:\r
+                PcdFromModule = M.Pcds[Key]\r
+                if not PcdFromModule.IsOverrided:\r
+                    NotFoundPcdList.add(" | ".join(Key))\r
+                    PcdConsumerList.add(str(M))\r
+                    continue\r
+\r
+                if Key not in Platform.Pcds:\r
+                    PcdFromPlatform = PcdFromModule\r
+                else:\r
+                    PcdFromPlatform = Platform.Pcds[Key]\r
+\r
+                if PcdFromModule.DatumType == "VOID*" and PcdFromPlatform.MaxDatumSize == None:\r
+                    NoDatumTypePcdList.add(" | ".join(Key))\r
+                    PcdConsumerList.add(str(M))\r
+\r
+                if PcdFromPlatform.Type in GenC.gDynamicPcd + GenC.gDynamicExPcd:\r
+                    if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
+                        PcdFromPlatform.Phase = "PEI"\r
+                    if PcdFromPlatform not in PcdList:\r
+                        PcdFromPlatform.DatumType = PcdFromModule.DatumType\r
+                        PcdList.append(PcdFromPlatform)\r
+\r
+        if len(NotFoundPcdList) > 0 or len(NoDatumTypePcdList) > 0:\r
+            NotFoundPcdListString = "\n\t\t".join(NotFoundPcdList)\r
+            NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
+            ModuleListString = "\n\t\t".join(PcdConsumerList)\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "PCD setting error",\r
+                            ExtraData="\n\tPCD(s) not found in platform:\n\t\t%s"\r
+                                      "\n\tPCD(s) without MaxDatumSize:\n\t\t%s"\r
+                                      "\n\tUsed by:\n\t\t%s\n"\r
+                                      % (NotFoundPcdListString, NoDatumTypePcdListString, ModuleListString))\r
+        return PcdList\r
+\r
+    def GeneratePcdTokenNumber(self, Platform, DynamicPcdList):\r
+        PcdTokenNumber = sdict()\r
+        TokenNumber = 1\r
+        for Pcd in DynamicPcdList:\r
+            if Pcd.Phase == "PEI":\r
+                EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
+                PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                TokenNumber += 1\r
+\r
+        for Pcd in DynamicPcdList:\r
+            if Pcd.Phase == "DXE":\r
+                EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
+                PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                TokenNumber += 1\r
+\r
+        PlatformPcds = Platform.Pcds\r
+        for Key in PlatformPcds:\r
+            Pcd = PlatformPcds[Key]\r
+            if Key not in PcdTokenNumber:\r
+                PcdTokenNumber[Key] = TokenNumber\r
+                TokenNumber += 1\r
+        return PcdTokenNumber\r
+\r
+    def CreateMakeFile(self, CreateModuleMakeFile=False):\r
+        if CreateModuleMakeFile:\r
+            for Arch in self.BuildInfo:\r
+                Info = self.BuildInfo[Arch]\r
+                for ModuleFile in Info.Platform.Libraries:\r
+                    AutoGenObject = ModuleAutoGen.GetAutoGen(self.Workspace, Info.Platform, ModuleFile,\r
+                                                             Info.BuildTarget, Info.ToolChain, Info.Arch)\r
+                    if AutoGenObject not in Info.LibraryAutoGenList:\r
+                        Info.LibraryAutoGenList.append(AutoGenObject)\r
+                    AutoGenObject.CreateMakeFile(False)\r
+\r
+                for ModuleFile in Info.Platform.Modules:\r
+                    AutoGenObject = ModuleAutoGen.GetAutoGen(self.Workspace, Info.Platform, ModuleFile,\r
+                                                             Info.BuildTarget, Info.ToolChain, Info.Arch)\r
+                    if AutoGenObject not in Info.ModuleAutoGenList:\r
+                        Info.ModuleAutoGenList.append(AutoGenObject)\r
+                    AutoGenObject.CreateMakeFile(False)\r
+\r
+        if self.IsMakeFileCreated:\r
+            return\r
+\r
+        Makefile = GenMake.Makefile(self.BuildInfo)\r
+        if Makefile.Generate():\r
+            EdkLogger.verbose("Generated makefile for platform [%s] [%s]\n" %\r
+                           (self.PlatformFile, " ".join(self.ArchList)))\r
+        else:\r
+            EdkLogger.verbose("Skipped the generation of makefile for platform [%s] [%s]\n" %\r
+                           (self.PlatformFile, " ".join(self.ArchList)))\r
+        self.IsMakeFileCreated = True\r
+\r
+    def CreateCodeFile(self, CreateModuleCodeFile=False):\r
+        if self.IsCodeFileCreated or not CreateModuleCodeFile:\r
+            return\r
+\r
+        for Arch in self.BuildInfo:\r
+            Info = self.BuildInfo[Arch]\r
+            for ModuleFile in Info.Platform.Libraries:\r
+                AutoGenObject = ModuleAutoGen.GetAutoGen(self.Workspace, Info.Platform, ModuleFile,\r
+                                                         Info.BuildTarget, Info.ToolChain, Info.Arch)\r
+                if AutoGenObject not in Info.LibraryAutoGenList:\r
+                    Info.LibraryAutoGenList.append(AutoGenObject)\r
+                AutoGenObject.CreateCodeFile()\r
+\r
+            for ModuleFile in Info.Platform.Modules:\r
+                AutoGenObject = ModuleAutoGen.GetAutoGen(self.Workspace, Info.Platform, ModuleFile,\r
+                                                         Info.BuildTarget, Info.ToolChain, Info.Arch)\r
+                if AutoGenObject not in Info.ModuleAutoGenList:\r
+                    Info.ModuleAutoGenList.append(AutoGenObject)\r
+                AutoGenObject.CreateCodeFile()\r
+\r
+        self.IsCodeFileCreated = True\r
+\r
+    def CheckModule(self, Module, Arch):\r
+        if Arch not in self.Workspace.SupArchList:\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "[%s] is not supported by active platform [%s] [%s]!"\r
+                                                      % (Arch, self.PlatformFile, self.Workspace.SupArchList))\r
+        if Arch not in self.ArchList:\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "[%s] is not supported by current build configuration!" % Arch)\r
+        if str(Module) not in self.ModuleDatabase[Arch]:\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "[%s] [%s] is not supported by active platform [%s]!"\r
+                                                      % (Module, Arch, self.PlatformFile))\r
+\r
+    ## Find the package containing the module\r
+    #\r
+    # Find out the package which contains the given module, according to the path\r
+    # of the module and the package.\r
+    #\r
+    # @param  Module            The module to be found for\r
+    #\r
+    # @retval package           Package object if found\r
+    # @retval None              None if not found\r
+    #\r
+    def GetModuleOwnerPackage(self, Module):\r
+        for Arch in self.PackageDatabase:\r
+            Pdb = self.PackageDatabase[Arch]\r
+            for PackagePath in Pdb:\r
+                PackageDir = path.dirname(PackagePath)\r
+                #\r
+                # if package's path is the first part of module's path, bingo!\r
+                #\r
+                if str(Module).find(PackageDir) == 0:\r
+                    return Pdb[PackagePath]\r
+        # nothing found\r
+        return None\r
+\r
+    def GetPlatformObject(self, PlatformFile, Arch):\r
+        if Arch not in self.PlatformDatabase or PlatformFile not in self.PlatformDatabase[Arch]:\r
+            return None\r
+        return self.PlatformDatabase[Arch][PlatformFile]\r
+\r
+    def GetPackageObject(self, PackageFile, Arch):\r
+        if Arch not in self.PackageDatabase or PackageFile not in self.PackageDatabase[Arch]:\r
+            return None\r
+        return self.PackageDatabase[Arch][PackageFile]\r
+\r
+    def GetModuleObject(self, ModuleFile, Arch):\r
+        if Arch not in self.ModuleDatabase or ModuleFile not in self.ModuleDatabase[Arch]:\r
+            return None\r
+        return self.ModuleDatabase[Arch][ModuleFile]\r
 \r
 ## AutoGen class\r
 #\r
@@ -128,111 +433,75 @@ def FindModuleOwnerPackage(Module, PackageDatabase):
 # to the [depex] section in module's inf file. The result of parsing unicode file\r
 # has been incorporated either.\r
 #\r
-class AutoGen(object):\r
-\r
-    def __init__(self, ModuleFile, PlatformFile, Workspace, Target, Toolchain, Arch):\r
-        global gModuleDatabase, gPackageDatabase, gPlatformDatabase, gAutoGenDatabase, gWorkspace, gWorkspaceDir, gBuildRuleDatabase\r
-\r
-        if ModuleFile != None:\r
-            ModuleFile = NormPath(str(ModuleFile))\r
-        if PlatformFile != None:\r
-            PlatformFile = NormPath(str(PlatformFile))\r
-\r
-        if gWorkspace == None:\r
-            gWorkspace = Workspace\r
-        if gWorkspaceDir == "":\r
-            gWorkspaceDir = Workspace.WorkspaceDir\r
-\r
-        if gModuleDatabase == {}:\r
-            for a in Workspace.Build:\r
-                gModuleDatabase[a] = gWorkspace.Build[a].ModuleDatabase\r
-        if gPackageDatabase == {}:\r
-            for a in Workspace.Build:\r
-                gPackageDatabase[a] = gWorkspace.Build[a].PackageDatabase\r
-        if gPlatformDatabase == {}:\r
-            for a in Workspace.Build:\r
-                gPlatformDatabase[a] = gWorkspace.Build[a].PlatformDatabase\r
+class ModuleAutoGen(object):\r
+    _Database = {}\r
+\r
+    def Init(self, Workspace, PlatformFile, ModuleFile, Target, Toolchain, Arch):\r
+        self.ModuleFile = str(ModuleFile)\r
+        self.PlatformFile = str(PlatformFile)\r
+\r
+        self.Workspace = Workspace\r
+        self.WorkspaceDir = Workspace.WorkspaceDir\r
 \r
         self.ToolChain = Toolchain\r
         self.ToolChainFamily = "MSFT"\r
         self.BuildTarget = Target\r
-        self.IsMakefileCreated = False\r
-        self.IsAutoGenCodeCreated = False\r
-\r
-        Key = (self.BuildTarget, self.ToolChain, str(PlatformFile))\r
-        if ModuleFile == None:\r
-            #\r
-            # autogen for platform\r
-            #\r
-            self.PlatformBuildInfo = {}     # arch : PlatformBuildInfo Object\r
-            self.Platform = {}\r
-            self.IsPlatformAutoGen = True\r
-            if type(Arch) == type([]):\r
-                self.Arch = Arch\r
-            else:\r
-                self.Arch = [Arch]\r
-            EdkLogger.verbose("")\r
-            EdkLogger.verbose("\nAutoGen platform [%s] %s" % (PlatformFile, self.Arch))\r
-\r
-            self.Platform = {}\r
-            self.BuildInfo = {}\r
-            for a in self.Arch:\r
-                if a not in gPlatformDatabase or str(PlatformFile) not in gPlatformDatabase[a]:\r
-                    raise AutoGenError(msg="[%s] is not the active platform, or %s is not supported by the active platform!" % (PlatformFile, a))\r
-                p = gPlatformDatabase[a][str(PlatformFile)]\r
-                self.Platform[a] = p\r
-                self.BuildInfo[a] = self.GetPlatformBuildInfo(p, self.BuildTarget, self.ToolChain, a)\r
-            gAutoGenDatabase[Key] = self\r
-            return\r
-        elif Key not in gAutoGenDatabase:\r
-            gAutoGenDatabase[Key] = AutoGen(None, PlatformFile, Workspace, Target, Toolchain, Arch)\r
+        self.Arch = Arch\r
+\r
+        self.IsMakeFileCreated = False\r
+        self.IsCodeFileCreated = False\r
+\r
+        self.PlatformAutoGen = PlatformAutoGen.GetAutoGen(Workspace, PlatformFile, Target, Toolchain, None)\r
+        if self.PlatformAutoGen == None:\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Please create platform AutoGen first!")\r
+        try:\r
+            self.PlatformAutoGen.CheckModule(ModuleFile, self.Arch)\r
+        except:\r
+            return False\r
 \r
         #\r
         # autogen for module\r
         #\r
-        self.IsPlatformAutoGen = False\r
-        if type(Arch) == type([]):\r
-            if len(Arch) > 1:\r
-                raise AutoGenError(msg="Cannot AutoGen a module for more than one platform object at a time!")\r
-            self.Arch = Arch[0]\r
-        else:\r
-            self.Arch = Arch\r
-        EdkLogger.verbose("")\r
-        EdkLogger.verbose("AutoGen module [%s] [%s]" % (ModuleFile, self.Arch))\r
-\r
-        if self.Arch not in gPlatformDatabase or str(PlatformFile) not in gPlatformDatabase[Arch]:\r
-            raise AutoGenError(msg="[%s] is not the active platform, or %s is not supported by the platform!" % (PlatformFile, self.Arch))\r
-        if self.Arch not in gModuleDatabase or str(ModuleFile) not in gModuleDatabase[self.Arch]:\r
-            raise AutoGenError(msg="[%s] architecture %s is not supported by active platform [%s]!" % (ModuleFile, self.Arch, PlatformFile))\r
+        EdkLogger.verbose("\nAutoGen module [%s] [%s]" % (ModuleFile, self.Arch))\r
 \r
-        self.Platform = gPlatformDatabase[Arch][str(PlatformFile)]\r
-        if str(ModuleFile) not in self.Platform.Modules and str(ModuleFile) not in self.Platform.Libraries:\r
-            raise AutoGenError(msg="Cannot find module %s for architecture [%s] in the active platform:\n\t%s\n" % (ModuleFile, self.Arch, self.Platform))\r
-        self.Module = gModuleDatabase[Arch][str(ModuleFile)]\r
+        self.Platform = self.PlatformAutoGen.GetPlatformObject(self.PlatformFile, self.Arch)\r
+        self.Module = self.PlatformAutoGen.GetModuleObject(self.ModuleFile, self.Arch)\r
 \r
-        self.Package = FindModuleOwnerPackage(self.Module, gPackageDatabase[Arch])\r
+        self.Package = self.PlatformAutoGen.GetModuleOwnerPackage(self.Module)\r
 \r
         self.AutoGenC = TemplateString()\r
         self.AutoGenH = TemplateString()\r
 \r
-        self.BuildInfo = None\r
-        self.GetModuleBuildInfo()\r
-        gAutoGenDatabase[self.BuildTarget, self.ToolChain, self.Arch, self.Module] = self\r
+        self.BuildInfo = self.GetModuleBuildInfo()\r
 \r
-    def GetModuleBuildInfo(self):\r
-        Key = (self.BuildTarget, self.ToolChain, self.Arch, self.Module)\r
-        if Key in gAutoGenDatabase:\r
-            self.BuildInfo = gAutoGenDatabase[Key].BuildInfo\r
-            self.IsAutoGenCodeCreated = gAutoGenDatabase[Key].IsAutoGenCodeCreated\r
-            self.IsMakefileCreated = gAutoGenDatabase[Key].IsMakefileCreated\r
-            return gAutoGenDatabase[Key].BuildInfo\r
+        self._Database[self.Module, self.BuildTarget, self.ToolChain, self.Arch] = self\r
 \r
+        return True\r
+\r
+    def __hash__(self):\r
+        return hash(self.ModuleFile)\r
+\r
+    def __str__(self):\r
+        return self.ModuleFile\r
+\r
+    @staticmethod\r
+    def GetAutoGen(Workspace, Platform, Module, Target, Toolchain, Arch):\r
+        Key = (Module, Target, Toolchain, Arch)\r
+        if Key not in ModuleAutoGen._Database:\r
+            if Arch == None or Arch == "":\r
+                return None\r
+            AutoGenObject = ModuleAutoGen()\r
+            if AutoGenObject.Init(Workspace, Platform, Module, Target, Toolchain, Arch) == False:\r
+                return None\r
+        return ModuleAutoGen._Database[Key]\r
+\r
+    def GetModuleBuildInfo(self):\r
         Info = ModuleBuildInfo(self.Module)\r
         self.BuildInfo = Info\r
-        Info.PlatformInfo = self.GetPlatformBuildInfo(self.Platform, self.BuildTarget, self.ToolChain, self.Arch)\r
+        Info.PlatformInfo = self.PlatformAutoGen.BuildInfo[self.Arch]\r
 \r
         # basic information\r
-        Info.WorkspaceDir = gWorkspaceDir\r
+        Info.WorkspaceDir = self.WorkspaceDir\r
         Info.BuildTarget = self.BuildTarget\r
         Info.ToolChain = self.ToolChain\r
         Info.Arch = self.Arch\r
@@ -246,17 +515,17 @@ class AutoGen(object):
                                      Info.FileBase)\r
         Info.OutputDir = os.path.join(Info.BuildDir, "OUTPUT")\r
         Info.DebugDir = os.path.join(Info.BuildDir, "DEBUG")\r
-        Info.MakefileDir = Info.BuildDir\r
+        Info.MakeFileDir = Info.BuildDir\r
         if os.path.isabs(Info.BuildDir):\r
             CreateDirectory(Info.OutputDir)\r
             CreateDirectory(Info.DebugDir)\r
         else:\r
-            CreateDirectory(os.path.join(gWorkspaceDir, Info.OutputDir))\r
-            CreateDirectory(os.path.join(gWorkspaceDir, Info.DebugDir))\r
+            CreateDirectory(os.path.join(self.WorkspaceDir, Info.OutputDir))\r
+            CreateDirectory(os.path.join(self.WorkspaceDir, Info.DebugDir))\r
 \r
         for Type in self.Module.CustomMakefile:\r
             MakeType = gMakeTypeMap[Type]\r
-            Info.CustomMakefile[MakeType] = os.path.join(Info.SourceDir, self.Module.CustomMakefile[Type])\r
+            Info.CustomMakeFile[MakeType] = os.path.join(Info.SourceDir, self.Module.CustomMakefile[Type])\r
 \r
         if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
             Info.IsLibrary = True\r
@@ -288,68 +557,15 @@ class AutoGen(object):
 \r
         return Info\r
 \r
-    def InitPackageBuildInfo(self, Info):\r
-        Info.SourceDir = path.dirname(Info.Package.DescFilePath)\r
-        Info.IncludePathList.append(Info.SourceDir)\r
-        for Inc in Info.Package.Includes:\r
-            Info.IncludePathList.append(os.path.join(Info.SourceDir, Inc))\r
-\r
-    def GetPlatformBuildInfo(self, Platform, Target, Toolchain, Arch):\r
-        Key = Target, Toolchain, Platform\r
-        PlatformAutoGen = None\r
-        if Key in gAutoGenDatabase:\r
-            PlatformAutoGen = gAutoGenDatabase[Key]\r
-            if type(PlatformAutoGen.BuildInfo) == type({}):\r
-                if Arch in PlatformAutoGen.BuildInfo:\r
-                    return PlatformAutoGen.BuildInfo[Arch]\r
-            else:\r
-                return PlatformAutoGen.BuildInfo\r
-\r
-        Info = PlatformBuildInfo(Platform)\r
-\r
-        Info.Arch = Arch\r
-        Info.ToolChain = self.ToolChain\r
-        Info.BuildTarget = self.BuildTarget\r
-\r
-        Info.WorkspaceDir = gWorkspace.WorkspaceDir\r
-        Info.SourceDir = path.dirname(Platform.DescFilePath)\r
-        Info.OutputDir = Platform.OutputDirectory\r
-        Info.BuildDir = path.join(Info.OutputDir, self.BuildTarget + "_" + self.ToolChain)\r
-        Info.MakefileDir = Info.BuildDir\r
-        if gWorkspace.Fdf != "":\r
-            Info.FdfFile= path.join(gWorkspaceDir, gWorkspace.Fdf)\r
-\r
-        Info.DynamicPcdList = self.GetDynamicPcdList(Platform, Arch)\r
-        Info.PcdTokenNumber = self.GeneratePcdTokenNumber(Platform, Info.DynamicPcdList)\r
-        Info.PackageList = gPackageDatabase[Arch].values()\r
-\r
-        self.ProcessToolDefinition(Info)\r
-        Info.BuildRule = self.GetBuildRule()\r
-        Info.FdTargetList = gWorkspace.FdTargetList\r
-        Info.FvTargetList = gWorkspace.FvTargetList\r
-\r
-        if PlatformAutoGen != None:\r
-            if type(PlatformAutoGen.BuildInfo) == type({}):\r
-                PlatformAutoGen.BuildInfo[Arch] = Info\r
-            else:\r
-                PlatformAutoGen.BuildInfo = Info\r
-        return Info\r
-\r
-    def GetMakefileDir(self):\r
-        if self.IsPlatformAutoGen:\r
-            return self.BuildInfo[self.Arch[0]].MakefileDir\r
-        else:\r
-            return self.BuildInfo.MakefileDir\r
-\r
-    def GetBuildRule(self):\r
-        return BuildRule(gWorkspace.WorkspaceFile(gBuildRuleFile))\r
+    def GetMakeFileDir(self):\r
+        return os.path.join(self.WorkspaceDir, self.BuildInfo.MakeFileDir)\r
 \r
     def GetDerivedPackageList(self):\r
         PackageList = []\r
         for M in [self.Module] + self.BuildInfo.DependentLibraryList:\r
             for Package in M.Packages:\r
                 if Package not in PackageList:\r
-                    PackageList.append(gPackageDatabase[self.Arch][Package])\r
+                    PackageList.append(self.PlatformAutoGen.GetPackageObject(Package, self.Arch))\r
         return PackageList\r
 \r
     def GetDepexTokenList(self, Info):\r
@@ -390,8 +606,10 @@ class AutoGen(object):
                         break\r
                 else:\r
                     PackageListString = "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
-                    raise AutoGenError(msg="GUID [%s] used in module [%s] cannot be found in dependent packages!\n\t%s"\r
-                                       % (GuidCName, self.Module, PackageListString))\r
+                    EdkLogger.error("AutoGen", AUTOGEN_ERROR,\r
+                                    "GUID [%s] used in module [%s] cannot be found in dependent packages!"\r
+                                    % (GuidCName, self.Module),\r
+                                    ExtraData=PackageListString)\r
             TokenList[I] = Token\r
         EdkLogger.debug(EdkLogger.DEBUG_8, "TokenList(guid) = %s" % " ".join(TokenList))\r
         return TokenList\r
@@ -399,76 +617,6 @@ class AutoGen(object):
     def GetMacroList(self):\r
         return ["%s %s" % (Name, self.Module.Specification[Name]) for Name in self.Module.Specification]\r
 \r
-    def ProcessToolDefinition(self, Info):\r
-        ToolDefinition = gWorkspace.ToolDef.ToolsDefTxtDictionary\r
-        ToolCodeList = gWorkspace.ToolDef.ToolsDefTxtDatabase["COMMAND_TYPE"]\r
-        for Tool in ToolCodeList:\r
-            KeyBaseString = "%s_%s_%s_%s" % (Info.BuildTarget, Info.ToolChain, Info.Arch, Tool)\r
-\r
-            Key = "%s_PATH" % KeyBaseString\r
-            if Key not in ToolDefinition:\r
-                continue\r
-            Path = ToolDefinition[Key]\r
-\r
-            Key = "%s_FAMILY" % KeyBaseString\r
-            if Key in ToolDefinition:\r
-                Family = ToolDefinition[Key]\r
-            else:\r
-                Family = ""\r
-\r
-            Key = "%s_FLAGS" % KeyBaseString\r
-            if Key in ToolDefinition:\r
-                Option = ToolDefinition[Key]\r
-            else:\r
-                Option = ""\r
-\r
-            Key = "%s_DLL" % KeyBaseString\r
-            if Key in ToolDefinition:\r
-                Dll = ToolDefinition[Key]\r
-                os.environ["PATH"] = Dll + os.pathsep + os.environ["PATH"]\r
-            else:\r
-                Dll = ""\r
-\r
-            Key = KeyBaseString + "_OUTPUT"\r
-            if Key in ToolDefinition:\r
-                OutputFlag = ToolDefinition[Key]\r
-            elif (Family, Tool, "OUTPUT") in gOutputFlag:\r
-                OutputFlag = gOutputFlag[Family, Tool, "OUTPUT"]\r
-                if OutputFlag[0] == '"' and OutputFlag[-1] == '"':\r
-                    OutputFlag = OutputFlag[1:-1]\r
-            else:\r
-                OutputFlag = gDefaultOutputFlag\r
-\r
-            InputFlag = gIncludeFlag[Family]\r
-\r
-            Info.ToolPath[Tool] = Path\r
-            Info.ToolDynamicLib[Tool] = Dll\r
-            Info.ToolChainFamily[Tool] = Family\r
-            Info.DefaultToolOption[Tool] = Option\r
-            Info.OutputFlag[Tool] = OutputFlag\r
-            Info.IncludeFlag[Tool] = InputFlag\r
-\r
-        self.ToolChainFamily = Info.ToolChainFamily["CC"]\r
-        if self.IsPlatformAutoGen:\r
-            BuildOptions = self.Platform[Info.Arch].BuildOptions\r
-        else:\r
-            BuildOptions = self.Platform.BuildOptions\r
-\r
-        for Key in BuildOptions:\r
-            Family = Key[0]\r
-            Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
-            if Tool not in Info.ToolPath:\r
-                continue\r
-            if Family != None and Family != "" and Family != Info.ToolChainFamily[Tool]:\r
-                continue\r
-            if Target == "*" or Target == Info.BuildTarget:\r
-                if Tag == "*" or Tag == Info.ToolChain:\r
-                    if Arch == "*" or Arch == Info.Arch:\r
-                        Info.BuildOption[Tool] = BuildOptions[Key]\r
-        for Tool in Info.DefaultToolOption:\r
-            if Tool not in Info.BuildOption:\r
-                Info.BuildOption[Tool] = ""\r
-\r
     def GetModuleBuildOption(self, PlatformInfo):\r
         BuildOption = self.Module.BuildOptions\r
         OptionList = {}\r
@@ -483,7 +631,7 @@ class AutoGen(object):
                 if Tag == "*" or Tag == self.ToolChain:\r
                     if Arch == "*" or Arch == self.Arch:\r
                         OptionList[Tool] = BuildOption[Key]\r
-        for Tool in PlatformInfo.DefaultToolOption:\r
+        for Tool in PlatformInfo.ToolOption:\r
             if Tool not in OptionList:\r
                 OptionList[Tool] = ""\r
 \r
@@ -522,56 +670,28 @@ class AutoGen(object):
 \r
             # unicode must be processed by AutoGen\r
             if FileType == "Unicode-Text-File":\r
-                self.BuildInfo.UnicodeFileList.append(os.path.join(gWorkspaceDir, self.BuildInfo.SourceDir, SourceFile))\r
+                self.BuildInfo.UnicodeFileList.append(os.path.join(self.WorkspaceDir, self.BuildInfo.SourceDir, SourceFile))\r
                 continue\r
 \r
             # no command, no build\r
             if RuleObject == None or RuleObject.CommandList == []:\r
                 Buildable = False\r
-                EdkLogger.warn("No rule or command defined for building [%s], ignore file [%s]" % (FileType, SourceFile))\r
+                EdkLogger.warn(None, "No rule or command defined for building [%s], ignore file [%s]" % (FileType, SourceFile))\r
                 continue\r
 \r
             BuildFileList.append([SourceFile, FileType, RuleObject])\r
 \r
         return BuildFileList\r
 \r
-    def GetToolChainFamily(self, FileType):\r
-        PlatformInfo = self.BuildInfo.PlatformInfo\r
-        ToolChainFamily = PlatformInfo.ToolChainFamily\r
-        if FileType not in gBuildRuleDatabase[ToolChainFamily]:\r
-            for Family in gBuildRuleDatabase:\r
-                if FileType in gBuildRuleDatabase[Family]:\r
-                    ToolChainFamily = Family\r
-                    break\r
-            else:\r
-                return ""\r
-        FileBuildRule = gBuildRuleDatabase[ToolChainFamily][FileType]\r
-        ToolCodeList = FileBuildRule.ToolList\r
-\r
-        ToolChainFamily = ""\r
-        for ToolCode in ToolCodeList:\r
-            # if one tool is not defined in current toolchain, break the build\r
-            if ToolCode in PlatformInfo.ToolChainFamily:\r
-                ToolChainFamily = PlatformInfo.ToolChainFamily[ToolCode]\r
-                break\r
-\r
-        return ToolChainFamily\r
-\r
     def GetDependentPackageList(self):\r
-        #if self.Package != None and self.Package not in self.Module.Packages:\r
-        #    self.Module.Packages.insert(0, str(self.Package))\r
-\r
-        if self.Arch not in gPackageDatabase:\r
-            raise AutoGenError(msg="[%s] is not supported!")\r
-        PackageDatabase = gPackageDatabase[self.Arch]\r
-\r
         PackageList = []\r
         for PackageFile in self.Module.Packages:\r
             if PackageFile in PackageList:\r
                 continue\r
-            if PackageFile not in PackageDatabase:\r
-                raise AutoGenError(FILE_NOT_FOUND, name=PackageFile)\r
-            PackageList.append(PackageDatabase[PackageFile])\r
+            Package = self.PlatformAutoGen.GetPackageObject(PackageFile, self.Arch)\r
+            if Package == None:\r
+                EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData=PackageFile)\r
+            PackageList.append(Package)\r
         return PackageList\r
 \r
     def GetAutoGenFileList(self, BuildInfo):\r
@@ -585,76 +705,12 @@ class AutoGen(object):
 \r
     def GetSortedLibraryList(self):\r
         LibraryList = []\r
-        ModuleDatabase = gModuleDatabase[self.Arch]\r
         for Key in self.Module.LibraryClasses:\r
-            Library = ModuleDatabase[self.Module.LibraryClasses[Key]]\r
+            Library = self.PlatformAutoGen.GetModuleObject(self.Module.LibraryClasses[Key], self.Arch)\r
             if Library not in LibraryList:\r
                 LibraryList.append(Library)\r
         return LibraryList\r
 \r
-    def GetDynamicPcdList(self, Platform, Arch):\r
-        PcdList = []\r
-        NotFoundPcdList = set()\r
-        NoDatumTypePcdList = set()\r
-        PcdConsumerList = set()\r
-        for F in Platform.Modules:\r
-            M = gModuleDatabase[Arch][F]\r
-            for Key in M.Pcds:\r
-                PcdFromModule = M.Pcds[Key]\r
-                if not PcdFromModule.IsOverrided:\r
-                    NotFoundPcdList.add(" | ".join(Key))\r
-                    PcdConsumerList.add(str(M))\r
-                    continue\r
-\r
-                if Key not in Platform.Pcds:\r
-                    PcdFromPlatform = PcdFromModule\r
-                else:\r
-                    PcdFromPlatform = Platform.Pcds[Key]\r
-\r
-                if PcdFromModule.DatumType == "VOID*" and PcdFromPlatform.MaxDatumSize == None:\r
-                    NoDatumTypePcdList.add(" | ".join(Key))\r
-                    PcdConsumerList.add(str(M))\r
-\r
-                if PcdFromPlatform.Type in GenC.gDynamicPcd + GenC.gDynamicExPcd:\r
-                    if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
-                        PcdFromPlatform.Phase = "PEI"\r
-                    if PcdFromPlatform not in PcdList:\r
-                        PcdFromPlatform.DatumType = PcdFromModule.DatumType\r
-                        PcdList.append(PcdFromPlatform)\r
-\r
-        if len(NotFoundPcdList) > 0 or len(NoDatumTypePcdList) > 0:\r
-            NotFoundPcdListString = "\n\t\t".join(NotFoundPcdList)\r
-            NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
-            ModuleListString = "\n\t\t".join(PcdConsumerList)\r
-            raise AutoGenError(msg="\n\tPCD(s) not found in platform:\n\t\t%s"\r
-                                   "\n\tPCD(s) without MaxDatumSize:\n\t\t%s"\r
-                                   "\n\tUsed by:\n\t\t%s\n"\r
-                                   % (NotFoundPcdListString, NoDatumTypePcdListString, ModuleListString))\r
-        return PcdList\r
-\r
-    def GeneratePcdTokenNumber(self, Platform, DynamicPcdList):\r
-        PcdTokenNumber = sdict()\r
-        TokenNumber = 1\r
-        for Pcd in DynamicPcdList:\r
-            if Pcd.Phase == "PEI":\r
-                EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
-                PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
-                TokenNumber += 1\r
-\r
-        for Pcd in DynamicPcdList:\r
-            if Pcd.Phase == "DXE":\r
-                EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
-                PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
-                TokenNumber += 1\r
-\r
-        PlatformPcds = Platform.Pcds\r
-        for Key in PlatformPcds:\r
-            Pcd = PlatformPcds[Key]\r
-            if Key not in PcdTokenNumber:\r
-                PcdTokenNumber[Key] = TokenNumber\r
-                TokenNumber += 1\r
-        return PcdTokenNumber\r
-\r
     def GetPcdList(self, DependentLibraryList):\r
         PlatformPcds = self.Platform.Pcds\r
 \r
@@ -683,8 +739,9 @@ class AutoGen(object):
                     Guid[Key] = P.Ppis[Key]\r
                     break\r
             else:\r
-                PackageListString = "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
-                raise AutoGenError(msg='GUID [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.Module, PackageListString))\r
+                PackageListString = "\t" + "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, 'GUID [%s] used by [%s] cannot be found in dependent packages' % (Key, self.Module),\r
+                                ExtraData=PackageListString)\r
         return Guid\r
 \r
     def GetProtocolGuidList(self):\r
@@ -702,8 +759,10 @@ class AutoGen(object):
                     Guid[Key] = P.Ppis[Key]\r
                     break\r
             else:\r
-                PackageListString = "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
-                raise AutoGenError(msg='Protocol [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.Module, PackageListString))\r
+                PackageListString = "\t" + "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
+                #EdkLogger.error("AutoGen", AUTOGEN_ERROR, msg='Protocol [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.Module, PackageListString))\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, 'Protocol [%s] used by [%s] cannot be found in dependent packages' % (Key, self.Module),\r
+                                ExtraData=PackageListString)\r
         return Guid\r
 \r
     def GetPpiGuidList(self):\r
@@ -721,8 +780,10 @@ class AutoGen(object):
                     Guid[Key] = P.Ppis[Key]\r
                     break\r
             else:\r
-                PackageListString = "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
-                raise AutoGenError(msg='PPI [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.Module, PackageListString))\r
+                PackageListString = "\t" + "\n\t".join([str(P) for P in self.BuildInfo.DerivedPackageList])\r
+                #EdkLogger.error("AutoGen", AUTOGEN_ERROR, msg='PPI [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.Module, PackageListString))\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, 'PPI [%s] used by [%s] cannot be found in dependent packages' % (Key, self.Module),\r
+                                ExtraData=PackageListString)\r
         return Guid\r
 \r
     def GetIncludePathList(self, DependentPackageList):\r
@@ -739,138 +800,90 @@ class AutoGen(object):
                     IncludePathList.append(Inc)\r
         return IncludePathList\r
 \r
-    def CreateMakefile(self, FilePath=None):\r
-        myBuildOption = {\r
-            "ENABLE_PCH"        :   False,\r
-            "ENABLE_LOCAL_LIB"  :   True,\r
-        }\r
-        if self.IsMakefileCreated:\r
+    def CreateMakeFile(self, CreateLibraryMakeFile=True):\r
+        if self.IsMakeFileCreated:\r
             return\r
 \r
-        if self.IsPlatformAutoGen:\r
-            for Arch in self.BuildInfo:\r
-                Info = self.BuildInfo[Arch]\r
-                for ModuleFile in Info.Platform.Modules:\r
-                    Key = (Info.BuildTarget, Info.ToolChain, Arch, ModuleFile)\r
-                    ModuleAutoGen = None\r
-                    if Key not in gAutoGenDatabase:\r
-                        ModuleAutoGen = AutoGen(ModuleFile, Info.Platform, gWorkspace,\r
-                                                Info.BuildTarget, Info.ToolChain, Info.Arch)\r
-                    else:\r
-                        ModuleAutoGen = gAutoGenDatabase[Key]\r
-                    ModuleAutoGen.CreateMakefile()\r
-        else:\r
-            PlatformInfo = self.BuildInfo.PlatformInfo\r
-            if not self.BuildInfo.IsLibrary:\r
-                if self not in PlatformInfo.ModuleAutoGenList:\r
-                    PlatformInfo.ModuleAutoGenList.append(self)\r
-            elif self not in PlatformInfo.LibraryAutoGenList:\r
-                PlatformInfo.LibraryAutoGenList.append(self)\r
+        PlatformInfo = self.BuildInfo.PlatformInfo\r
+        #if not self.BuildInfo.IsLibrary:\r
+        #    if self not in PlatformInfo.ModuleAutoGenList:\r
+        #        PlatformInfo.ModuleAutoGenList.append(self)\r
+        #elif self not in PlatformInfo.LibraryAutoGenList:\r
+        #    PlatformInfo.LibraryAutoGenList.append(self)\r
 \r
+        if CreateLibraryMakeFile:\r
             for Lib in self.BuildInfo.DependentLibraryList:\r
                 EdkLogger.debug(EdkLogger.DEBUG_1, "###" + str(Lib))\r
-                Key = (self.BuildTarget, self.ToolChain, self.Arch, Lib)\r
-                LibraryAutoGen = None\r
-                if Key not in gAutoGenDatabase:\r
-                    LibraryAutoGen = AutoGen(Lib, self.Platform, gWorkspace,\r
-                                             self.BuildTarget, self.ToolChain, self.Arch)\r
-                else:\r
-                    LibraryAutoGen = gAutoGenDatabase[Key]\r
+                LibraryAutoGen = ModuleAutoGen.GetAutoGen(self.Workspace, self.Platform, Lib,\r
+                                                          self.BuildTarget, self.ToolChain, self.Arch)\r
                 if LibraryAutoGen not in self.BuildInfo.LibraryAutoGenList:\r
                     self.BuildInfo.LibraryAutoGenList.append(LibraryAutoGen)\r
-                LibraryAutoGen.CreateMakefile()\r
+                LibraryAutoGen.CreateMakeFile()\r
 \r
-            Makefile = GenMake.Makefile(self.BuildInfo, myBuildOption)\r
-            if Makefile.Generate():\r
-                EdkLogger.info("Generated makefile for module %s [%s]" %\r
-                               (self.BuildInfo.Name, self.BuildInfo.Arch))\r
-            else:\r
-                EdkLogger.info("Skipped the generation of makefile for module %s [%s]" %\r
-                               (self.BuildInfo.Name, self.BuildInfo.Arch))\r
-            self.IsMakefileCreated = True\r
-            return\r
-\r
-        Makefile = GenMake.Makefile(self.BuildInfo, myBuildOption)\r
+        Makefile = GenMake.Makefile(self.BuildInfo)\r
         if Makefile.Generate():\r
-            EdkLogger.info("Generated makefile for platform %s [%s]\n" %\r
-                           (self.BuildInfo[self.Arch[0]].Name, " ".join(self.Arch)))\r
+            EdkLogger.verbose("Generated makefile for module %s [%s]" %\r
+                           (self.BuildInfo.Name, self.BuildInfo.Arch))\r
         else:\r
-            EdkLogger.info("Skipped the generation of makefile for platform %s [%s]\n" %\r
-                           (self.BuildInfo[self.Arch[0]].Name, " ".join(self.Arch)))\r
-        self.IsMakefileCreated = True\r
+            EdkLogger.verbose("Skipped the generation of makefile for module %s [%s]" %\r
+                           (self.BuildInfo.Name, self.BuildInfo.Arch))\r
 \r
-    def CreateAutoGenFile(self, FilePath=None):\r
-        if self.IsAutoGenCodeCreated:\r
+        self.IsMakeFileCreated = True\r
+\r
+    def CreateCodeFile(self, CreateLibraryCodeFile=True):\r
+        if self.IsCodeFileCreated:\r
             return\r
 \r
-        if self.IsPlatformAutoGen:\r
-            for Arch in self.BuildInfo:\r
-                Info = self.BuildInfo[Arch]\r
-                for ModuleFile in Info.Platform.Modules:\r
-                    Key = (Info.BuildTarget, Info.ToolChain, Arch, ModuleFile)\r
-                    ModuleAutoGen = None\r
-                    if Key not in gAutoGenDatabase:\r
-                        ModuleAutoGen = AutoGen(ModuleFile, Info.Platform, gWorkspace,\r
-                                                Info.BuildTarget, Info.ToolChain, Info.Arch)\r
-                    else:\r
-                        ModuleAutoGen = gAutoGenDatabase[Key]\r
-                    ModuleAutoGen.CreateAutoGenFile()\r
-            EdkLogger.info("")\r
-        else:\r
-            PlatformInfo = self.BuildInfo.PlatformInfo\r
-            if not self.BuildInfo.IsLibrary and self not in PlatformInfo.ModuleAutoGenList:\r
-                PlatformInfo.ModuleAutoGenList.append(self)\r
-            elif self.BuildInfo.IsLibrary and self not in PlatformInfo.LibraryAutoGenList:\r
-                PlatformInfo.LibraryAutoGenList.append(self)\r
+        PlatformInfo = self.BuildInfo.PlatformInfo\r
+        #if not self.BuildInfo.IsLibrary and self not in PlatformInfo.ModuleAutoGenList:\r
+        #    PlatformInfo.ModuleAutoGenList.append(self)\r
+        #elif self.BuildInfo.IsLibrary and self not in PlatformInfo.LibraryAutoGenList:\r
+        #    PlatformInfo.LibraryAutoGenList.append(self)\r
 \r
+        if CreateLibraryCodeFile:\r
             for Lib in self.BuildInfo.DependentLibraryList:\r
-                Key = (self.BuildTarget, self.ToolChain, self.Arch, Lib)\r
-                LibraryAutoGen = None\r
-                if Key not in gAutoGenDatabase:\r
-                    LibraryAutoGen = AutoGen(Lib, self.Platform, gWorkspace,\r
-                                             self.BuildTarget, self.ToolChain, self.Arch)\r
-                else:\r
-                    LibraryAutoGen = gAutoGenDatabase[Key]\r
+                LibraryAutoGen = ModuleAutoGen.GetAutoGen(self.Workspace, self.Platform, Lib,\r
+                                                          self.BuildTarget, self.ToolChain, self.Arch)\r
                 if LibraryAutoGen not in self.BuildInfo.LibraryAutoGenList:\r
                     self.BuildInfo.LibraryAutoGenList.append(LibraryAutoGen)\r
-                LibraryAutoGen.CreateAutoGenFile()\r
-\r
-            AutoGenList = []\r
-            IgoredAutoGenList = []\r
-            if self.AutoGenC.String != "":\r
-                if GenC.Generate(os.path.join(self.BuildInfo.WorkspaceDir, self.BuildInfo.DebugDir, gAutoGenCodeFileName),\r
-                                 self.AutoGenC.String):\r
-                    AutoGenList.append(gAutoGenCodeFileName)\r
-                else:\r
-                    IgoredAutoGenList.append(gAutoGenCodeFileName)\r
+                LibraryAutoGen.CreateCodeFile()\r
 \r
-            if self.AutoGenH.String != "":\r
-                if GenC.Generate(os.path.join(self.BuildInfo.WorkspaceDir, self.BuildInfo.DebugDir, gAutoGenHeaderFileName),\r
-                                 self.AutoGenH.String):\r
-                    AutoGenList.append(gAutoGenHeaderFileName)\r
-                else:\r
-                    IgoredAutoGenList.append(gAutoGenHeaderFileName)\r
+        AutoGenList = []\r
+        IgoredAutoGenList = []\r
+        if self.AutoGenC.String != "":\r
+            if GenC.Generate(os.path.join(self.BuildInfo.WorkspaceDir, self.BuildInfo.DebugDir, gAutoGenCodeFileName),\r
+                             self.AutoGenC.String):\r
+                AutoGenList.append(gAutoGenCodeFileName)\r
+            else:\r
+                IgoredAutoGenList.append(gAutoGenCodeFileName)\r
 \r
-            if self.BuildInfo.DepexList != []:\r
-                Dpx = GenDepex.DependencyExpression(self.BuildInfo.DepexList, self.BuildInfo.ModuleType)\r
-                DpxFile = gAutoGenDepexFileName % {"module_name" : self.BuildInfo.Name}\r
-                if Dpx.Generate(os.path.join(gWorkspaceDir, self.BuildInfo.OutputDir, DpxFile)):\r
-                    AutoGenList.append(DpxFile)\r
-                else:\r
-                    IgoredAutoGenList.append(DpxFile)\r
-\r
-            if IgoredAutoGenList == []:\r
-                EdkLogger.info("Generated [%s] files for module %s [%s]" %\r
-                               (" ".join(AutoGenList), self.BuildInfo.Name, self.BuildInfo.Arch))\r
-            elif AutoGenList == []:\r
-                EdkLogger.info("Skipped the generation of [%s] files for module %s [%s]" %\r
-                               (" ".join(IgoredAutoGenList), self.BuildInfo.Name, self.BuildInfo.Arch))\r
+        if self.AutoGenH.String != "":\r
+            if GenC.Generate(os.path.join(self.BuildInfo.WorkspaceDir, self.BuildInfo.DebugDir, gAutoGenHeaderFileName),\r
+                             self.AutoGenH.String):\r
+                AutoGenList.append(gAutoGenHeaderFileName)\r
             else:\r
-                EdkLogger.info("Generated [%s] (skipped %s) files for module %s [%s]" %\r
-                               (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.BuildInfo.Name, self.BuildInfo.Arch))\r
+                IgoredAutoGenList.append(gAutoGenHeaderFileName)\r
 \r
-            self.IsAutoGenCodeCreated = True\r
-            return AutoGenList\r
+        if self.BuildInfo.DepexList != []:\r
+            Dpx = GenDepex.DependencyExpression(self.BuildInfo.DepexList, self.BuildInfo.ModuleType)\r
+            DpxFile = gAutoGenDepexFileName % {"module_name" : self.BuildInfo.Name}\r
+            if Dpx.Generate(os.path.join(self.WorkspaceDir, self.BuildInfo.OutputDir, DpxFile)):\r
+                AutoGenList.append(DpxFile)\r
+            else:\r
+                IgoredAutoGenList.append(DpxFile)\r
+\r
+        if IgoredAutoGenList == []:\r
+            EdkLogger.verbose("Generated [%s] files for module %s [%s]" %\r
+                           (" ".join(AutoGenList), self.BuildInfo.Name, self.BuildInfo.Arch))\r
+        elif AutoGenList == []:\r
+            EdkLogger.verbose("Skipped the generation of [%s] files for module %s [%s]" %\r
+                           (" ".join(IgoredAutoGenList), self.BuildInfo.Name, self.BuildInfo.Arch))\r
+        else:\r
+            EdkLogger.verbose("Generated [%s] (skipped %s) files for module %s [%s]" %\r
+                           (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.BuildInfo.Name, self.BuildInfo.Arch))\r
+\r
+        self.IsCodeFileCreated = True\r
+        return AutoGenList\r
 \r
 # Version and Copyright\r
 __version_number__ = "0.01"\r
@@ -936,12 +949,24 @@ def GetOptions():
     elif len(Args) == 1:\r
         Options.Target = Args[0].lower()\r
         if Options.Target not in ["genc", "genmake"]:\r
-            raise AutoGenError(OPTION_NOT_SUPPORTED, name="Not supported target", usage=Parser.get_usage())\r
+            EdkLogger.error("AutoGen", OPTION_NOT_SUPPORTED, "Not supported target",\r
+                            ExtraData="%s\n\n%s" % (Options.Target, Parser.get_usage()))\r
     else:\r
-        raise AutoGenError(OPTION_NOT_SUPPORTED, name="Too many targets", usage=Parser.get_usage())\r
+        EdkLogger.error("AutoGen", OPTION_NOT_SUPPORTED, "Too many targets",\r
+                        ExtraData=Parser.get_usage())\r
 \r
     return Options\r
 \r
+def GetAutoGen(Workspace, Platform, Module, Target, ToolChain, Arch):\r
+    if Module == None or Module == "":\r
+        if type(Arch) != type([]):\r
+            ArchList = [Arch]\r
+        else:\r
+            ArchList = Arch\r
+        return PlatformAutoGen.GetAutoGen(Workspace, Platform, Target, ToolChain, ArchList)\r
+    else:\r
+        return ModuleAutoGen.GetAutoGen(Workspace, Platform, Module, Target, ToolChain, Arch)\r
+\r
 ## Entrance method\r
 #\r
 # This method mainly dispatch specific methods per the command line options.\r
index c1e7d22..983616e 100644 (file)
@@ -31,9 +31,9 @@ def FileType2Macro(FileType):
 class FileBuildRule:\r
     def __init__(self, Input, Output, Command):\r
         if Input == {}:\r
-            raise AutoGenError(msg="No input files")\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No input files for a build rule")\r
         if Output == []:\r
-            raise AutoGenError(msg="No output files")\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No output files for a build rule")\r
 \r
         self.SourceFileType = {}\r
         self.SourceFileExtList = []\r
@@ -167,15 +167,16 @@ class BuildRule:
     _SubSectionList = [_InputFile, _OutputFile, _Command]\r
 \r
     def __init__(self, File=None, Content=None, LineIndex=0, SupportedFamily=["MSFT", "INTEL", "GCC"]):\r
+        self.RuleFile = File\r
         if File != None:\r
             try:\r
                 self.RuleContent = open(File, 'r').readlines()\r
             except:\r
-                raise ParserError(FILE_OPEN_FAILURE, name=File)\r
+                EdkLogger.error("BuildRuleParser", FILE_OPEN_FAILURE, ExtraData=File)\r
         elif Content != None:\r
             self.RuleContent = Content\r
         else:\r
-            raise ParserError(msg="No rule file or string given")\r
+            EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No rule file or string given")\r
 \r
         self.SupportedToolChainFamilyList = SupportedFamily\r
         self.RuleDatabase = {}  # {version : {family : {file type : FileBuildRule object}}}\r
@@ -217,12 +218,14 @@ class BuildRule:
     def ParseSection(self, LineIndex):\r
         TokenList = self.RuleContent[LineIndex].split("=", 1)\r
         if len(TokenList) != 2 or TokenList[0] != "BUILD_VERSION":\r
-            raise ParserError(msg="Invalid define: %s, line %d" % (self.RuleContent[LineIndex], LineIndex+1))\r
+            EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Invalid definition",\r
+                            File=RuleFile, Line=LineIndex+1, ExtraData=self.RuleContent[LineIndex])\r
 \r
         try:\r
             self._BuildVersion = int(TokenList[1].strip(), 0)\r
         except:\r
-            raise ParserError(msg="Version is not a valid number: %s, line %d" % (self.RuleContent[LineIndex], LineIndex+1))\r
+            EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Version is not a valid number",\r
+                            File=self.RuleFile, Line=LineIndex+1, ExtraData=self.RuleContent[LineIndex])\r
 \r
     def ParseSubSection(self, LineIndex):\r
         pass\r
@@ -271,12 +274,12 @@ class BuildRule:
             if self._InputFile in Rule:\r
                 Input = Rule[self._InputFile]\r
             else:\r
-                raise ParserError(msg="No input files found")\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No input files found for a rule")\r
 \r
             if self._OutputFile in Rule:\r
                 Output = Rule[self._OutputFile]\r
             else:\r
-                raise ParserError(msg="No output files found")\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No output files found a rule")\r
 \r
             if self._Command in Rule:\r
                 Command = Rule[self._Command]\r
@@ -306,18 +309,18 @@ class BuildRule:
         for RuleName in RuleNameList:\r
             TokenList = RuleName.split('.')\r
             if len(TokenList) == 1:\r
-                raise ParserError(msg="Invalid rule section: %s, line %d"\r
-                                  % (self.RuleContent[LineIndex], LineIndex+1))\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Invalid rule section",\r
+                                File=self.RuleFile, Line=LineIndex+1, ExtraData=self.RuleContent[LineIndex])\r
 \r
             Rule = TokenList[0].strip()\r
             if Rule.upper() != "BUILD":\r
-                #raise ParserError(msg="Not supported section %s" % Line)\r
                 self._State = self._UnknownSection\r
                 return\r
 \r
             FileType = TokenList[1].strip()\r
             if FileType == '':\r
-                raise ParserError(msg="No file type given: %s, line %d" % (Line, LineIndex+1))\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No file type given",\r
+                                File=self.RuleFile, Line=LineIndex+1, ExtraData=Line)\r
             FileTypeList.append(FileType)\r
 \r
         self._FileTypeList = FileTypeList\r
@@ -335,7 +338,8 @@ class BuildRule:
             if SectionType == "":\r
                 SectionType = Type\r
             elif SectionType != Type:\r
-                raise ParserError(msg="Two different section types are not allowed: %s, line %d" % (Line, LineIndex+1))\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Two different section types are not allowed",\r
+                                File=self.RuleFile, Line=LineIndex+1, ExtraData=Line)\r
 \r
             if len(TokenList) > 1:\r
                 Family = TokenList[1].strip().upper()\r
@@ -355,12 +359,14 @@ class BuildRule:
         if len(TokenList) > 1:\r
             FileType = TokenList[0].strip()\r
             if FileType not in self._FileTypeList:\r
-                raise ParserError(msg="File type must be %s: %s, line %d"\r
-                                  % (Line, self._FileTypeList, LineIndex))\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR,\r
+                                "File type must be one of %s: %s" % (self._FileTypeList, FileType),\r
+                                File=self.RuleFile, ExtraData=Line, Line=LineIndex+1)\r
             FileString = TokenList[1]\r
         else:\r
             if len(self._FileTypeList) > 1:\r
-                raise ParserError(msg="File type must be given: %s, line %d" % (Line, LineIndex))\r
+                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "File type must be given",\r
+                                File=self.RuleFile, Line=LineIndex, ExtraData=Line)\r
             else:\r
                 FileType = self._FileTypeList[0]\r
             FileString = TokenList[0]\r
index dddf798..cd936a6 100644 (file)
@@ -53,7 +53,7 @@ class ModuleBuildInfo(BuildInfo):
         self.BuildDir = ""
         self.OutputDir = ""
         self.DebugDir = ""
-        self.MakefileDir = ""
+        self.MakeFileDir = ""
         self.CustomMakefile = {}
 
         self.IncludePathList = []
@@ -109,7 +109,7 @@ class PlatformBuildInfo(BuildInfo):
         self.DebugDir = ""
         self.LibraryDir = ""
         self.FvDir = ""
-        self.MakefileDir = ""
+        self.MakeFileDir = ""
         self.FdfFile = ""
 
         self.ModuleAutoGenList = []
@@ -120,10 +120,10 @@ class PlatformBuildInfo(BuildInfo):
         self.DynamicPcdList = []    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
 
         self.ToolPath = {}          # toolcode : tool path
-        self.ToolDynamicLib = {}    # toolcode : lib path
+        self.ToolDllPath = {}    # toolcode : lib path
         self.ToolStaticLib = {}     # toolcode : lib path
         self.ToolChainFamily = {}   # toolcode : tool chain family
         self.BuildOption = {}       # toolcode : option
         self.OutputFlag = {}        # toolcode : output flag
         self.IncludeFlag = {}        # toolcode : include flag
-        self.DefaultToolOption = {}
+        self.ToolOption = {}
index bc3e9c3..5c39231 100644 (file)
@@ -798,7 +798,9 @@ def GetGuidValue(Packages, CName):
             return P.Ppis[CName]\r
     else:\r
         PackageListString = "\n\t".join([str(P) for P in Packages])\r
-        raise AutoGenError(msg="Cannot find GUID value for %s in all given packages:\n\t%s" % (CName, PackageListString))\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR,\r
+                        "Cannot find GUID value for %s in all given packages" % CName,\r
+                        ExtraData=PackageListString)\r
 \r
 def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
     PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
@@ -810,15 +812,15 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
         TokenNumber = int(Pcd.TokenValue, 0)\r
     else:\r
         if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
-            raise AutoGenError(msg="No generated token number for %s|%s\n" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No generated token number for %s|%s\n" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
         TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
     AutoGenH.Append('#define %s  %d\n' % (PcdTokenName, TokenNumber))\r
 \r
     EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "|" + Pcd.TokenSpaceGuidCName)\r
     if Pcd.Type not in gItemTypeStringDatabase:\r
-        raise AutoGenError(msg="Unknown PCD type [%s] of PCD %s|%s" % (Pcd.Type, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown PCD type [%s] of PCD %s|%s" % (Pcd.Type, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
     if Pcd.DatumType not in gDatumSizeStringDatabase:\r
-        raise AutoGenError(msg="Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
 \r
     DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
     DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
@@ -850,7 +852,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 Value += 'ULL'\r
         if Pcd.DatumType == 'VOID*':\r
             if Pcd.MaxDatumSize == None:\r
-                raise AutoGenError(msg="Unknown MaxDatumSize of PCD %s|%s" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown MaxDatumSize of PCD %s|%s" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
 \r
             ArraySize = int(Pcd.MaxDatumSize, 0)\r
             if Value[0] == '{':\r
@@ -901,13 +903,13 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
     TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
     TokenCName  = Pcd.TokenCName\r
     if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
-        raise AutoGenError(msg="No generated token number for %s|%s\n" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No generated token number for %s|%s\n" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
     TokenNumber = PcdTokenNumber[TokenCName, TokenSpaceGuidCName]\r
 \r
     if Pcd.Type not in gItemTypeStringDatabase:\r
-        raise AutoGenError(msg="Unknown PCD type [%s] of PCD %s|%s" % (Pcd.Type, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown PCD type [%s] of PCD %s|%s" % (Pcd.Type, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
     if Pcd.DatumType not in gDatumSizeStringDatabase:\r
-        raise AutoGenError(msg="Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
 \r
     DatumType   = Pcd.DatumType\r
     DatumSize   = gDatumSizeStringDatabaseH[DatumType]\r
@@ -1031,7 +1033,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
 \r
         EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, Phase))\r
         if Pcd.DatumType not in gDatumSizeStringDatabase:\r
-            raise AutoGenError(msg="Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
 \r
         if Pcd.Phase == 'PEI':\r
             NumberOfPeiLocalTokens += 1\r
@@ -1273,7 +1275,7 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):
     if Info.PcdIsDriver == "":\r
         return\r
     if Info.PcdIsDriver not in gPcdPhaseMap:\r
-        raise AutoGenError(msg="Not supported PcdIsDriver type:%s\n" % Info.PcdIsDriver)\r
+        EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Not supported PcdIsDriver type:%s\n" % Info.PcdIsDriver)\r
 \r
     AutoGenH.Append(gPcdDatabaseCommonAutoGenH)\r
     AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI')\r
@@ -1349,7 +1351,7 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
 \r
     if Info.ModuleType in ['PEI_CORE', 'DXE_CORE']:\r
         if NumEntryPoints != 1:\r
-            raise AutoGenError(msg='%s must have exactly one entry point' % Info.ModuleType)\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, '%s must have exactly one entry point' % Info.ModuleType)\r
     if Info.ModuleType == 'PEI_CORE':\r
         AutoGenC.Append(gPeiCoreEntryPointString, Dict)\r
     elif Info.ModuleType == 'DXE_CORE':\r
index 7e44b03..a27c4c3 100644 (file)
@@ -129,24 +129,22 @@ class DependencyExpression:
         while len(Stack) > 0:\r
             self.PostfixNotation.append(Stack.pop())\r
         self.PostfixNotation.append("END")\r
-        #print "  ","\n   ".join(self.PostfixNotation)\r
 \r
     def ValidateOpcode(self):\r
         for Op in self.AboveAllOpcode:\r
             if Op in self.OpcodeList and Op != self.OpcodeList[0]:\r
-                raise AutoGenError("Opcode=%s should be the first one in the expression", Op)\r
+                EdkLogger.error("DepexParser", PARSER_ERROR, "Opcode=%s should be the first one in the expression" % Op)\r
         for Op in self.ExclusiveOpcode:\r
             if Op in self.OpcodeList and len(self.OpcodeList) > 1:\r
-                raise AutoGenError("Opcode=%s should be the only opcode in the expression", Op)\r
-        # print "######", self.ExpressionString\r
+                EdkLogger.error("DepexParser", PARSER_ERROR, "Opcode=%s should be the only opcode in the expression" % Op)\r
         if self.TokenList[-1] in self.NonEndingOpcode:\r
-            raise AutoGenError("Extra %s at the end of the dependency expression" % self.TokenList[-1])\r
+            EdkLogger.error("DepexParser", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-1])\r
 \r
     def GetGuidValue(self, Guid):\r
         GuidValueString = Guid.replace("{", "").replace("}", "").replace(" ", "")\r
         GuidValueList = GuidValueString.split(",")\r
         if len(GuidValueList) != 11:\r
-            raise AutoGenError("Invalid GUID value string or opcode: %s" % Guid)\r
+            EdkLogger.error("DepexParser", PARSER_ERROR, "Invalid GUID value string or opcode: %s" % Guid)\r
         return pack("1I2H8B", *(int(value, 16) for value in GuidValueList))\r
 \r
     def Generate(self, File=None):\r
index a307570..196bae0 100755 (executable)
@@ -528,10 +528,10 @@ cleanlib:
 '''\r
 \r
 class Makefile(object):\r
-    def __init__(self, Info, Option):\r
+    def __init__(self, Info, Option=None):\r
         if isinstance(Info, ModuleBuildInfo):\r
             if Info == None or Info == "":\r
-                raise AutoGenError(msg="No valid module found! Please check your build configuration!\n")\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No valid module found! Please check your build configuration!\n")\r
             self.ModuleInfo = Info\r
             self.PlatformInfo = Info.PlatformInfo\r
             self.ModuleBuild = True\r
@@ -551,7 +551,7 @@ class Makefile(object):
 \r
         elif type(Info) == type({}):    # and isinstance(info, PlatformBuildInfo):\r
             if len(Info) <= 0:\r
-                raise AutoGenError(msg="No buildable platform found! Please check your build configuration!\n")\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No buildable platform found! Please check your build configuration!\n")\r
             self.PlatformInfo = Info\r
             self.ModuleBuild = False\r
             self.ModuleBuildCommandList = []\r
@@ -559,11 +559,11 @@ class Makefile(object):
             self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()\r
             self.LibraryBuildDirectoryList = self.GetLibraryBuildDirectoryList()\r
         else:\r
-            raise AutoGenError(msg="Non-buildable item:%s" % str(Info))\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Non-buildable item:%s" % str(Info))\r
 \r
-        self.Opt = Option\r
-        self.BuildWithPch = Option["ENABLE_PCH"]\r
-        self.BuildWithLocalLib = Option["ENABLE_LOCAL_LIB"]\r
+        #self.Opt = Option\r
+        #self.BuildWithPch = Option["ENABLE_PCH"]\r
+        #self.BuildWithLocalLib = Option["ENABLE_LOCAL_LIB"]\r
         self.IntermediateDirectoryList = []\r
 \r
     def PrepareDirectory(self):\r
@@ -637,7 +637,7 @@ class Makefile(object):
 \r
         FilePath = ""\r
         if File == None:\r
-            FilePath = path.join(PlatformInfo.WorkspaceDir, PlatformInfo.MakefileDir, MakefileName)\r
+            FilePath = path.join(PlatformInfo.WorkspaceDir, PlatformInfo.MakeFileDir, MakefileName)\r
         else:\r
             FilePath = File\r
 \r
@@ -666,15 +666,15 @@ class Makefile(object):
         if self.ModuleInfo.Arch == "EBC":\r
             EntryPoint = "EfiStart"\r
 \r
-        DefaultToolFlag = PlatformInfo.DefaultToolOption.values()\r
+        DefaultToolFlag = PlatformInfo.ToolOption.values()\r
         if self.ModuleInfo.ModuleType == "USER_DEFINED":\r
             DefaultToolFlag = ["" for p in DefaultToolFlag]\r
 \r
         if "CC" not in PlatformInfo.ToolChainFamily:\r
-            raise AutoGenError(msg="[CC] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Tool [CC] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
                                     self.ModuleInfo.ToolChain, self.ModuleInfo.Arch))\r
         if  "DLINK" not in PlatformInfo.ToolChainFamily:\r
-            raise AutoGenError(msg="[DLINK] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Tool [DLINK] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
                                     self.ModuleInfo.ToolChain, self.ModuleInfo.Arch))\r
 \r
         if self.ModuleInfo.IsLibrary:\r
@@ -776,7 +776,7 @@ class Makefile(object):
 \r
         FilePath = ""\r
         if File == None:\r
-            FilePath = path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.MakefileDir, MakefileName)\r
+            FilePath = path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.MakeFileDir, MakefileName)\r
         else:\r
             FilePath = File\r
 \r
@@ -815,7 +815,7 @@ class Makefile(object):
             "platform_build_directory"  : self.PlatformBuildDirectory,\r
 \r
             "separator"                 : Separator,\r
-            "default_tool_flags"        : self.PlatformInfo.DefaultToolOption.values(),\r
+            "default_tool_flags"        : self.PlatformInfo.ToolOption.values(),\r
             "platform_tool_flags"       : self.PlatformInfo.BuildOption.values(),\r
             "module_tool_flags"         : self.ModuleInfo.BuildOption.values(),\r
 \r
@@ -835,7 +835,7 @@ class Makefile(object):
 \r
         FilePath = ""\r
         if File == None:\r
-            FilePath = path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.MakefileDir, MakefileName)\r
+            FilePath = path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.MakeFileDir, MakefileName)\r
         else:\r
             FilePath = File\r
 \r
@@ -864,8 +864,9 @@ class Makefile(object):
 \r
         FileList = self.ModuleInfo.SourceFileList\r
         if len(FileList) == 0:\r
-            raise AutoGenError(msg="No files to be built in module [%s, %s, %s]:\n\t%s" % (self.ModuleInfo.BuildTarget,\r
-                                    self.ModuleInfo.ToolChain, self.ModuleInfo.Arch, str(self.ModuleInfo.Module)))\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No files to be built in module [%s, %s, %s]"\r
+                            % (self.ModuleInfo.BuildTarget, self.ModuleInfo.ToolChain, self.ModuleInfo.Arch),\r
+                            ExtraData=str(self.ModuleInfo.Module))\r
 \r
         CCodeFlag = False\r
         for FileInfo in FileList:\r
@@ -1110,7 +1111,7 @@ class Makefile(object):
                 try:\r
                     Fd = open(F, 'r')\r
                 except:\r
-                    raise AutoGenError(FILE_OPEN_FAILURE, name=F)\r
+                    EdkLogger.error("AutoGen", FILE_OPEN_FAILURE, ExtraData=F)\r
 \r
                 FileContent = Fd.read()\r
                 Fd.close()\r
index fac5025..e528b66 100644 (file)
@@ -76,7 +76,7 @@ def CreateHFileContent(BaseName, UniObjectClass):
             else:\r
                 Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED\r
             Str = WriteLine(Str, Line)\r
-    \r
+\r
     Str =  WriteLine(Str, '')\r
     Str = WriteLine(Str, 'extern unsigned char ' + BaseName + 'Strings[];')\r
     return Str\r
@@ -91,15 +91,15 @@ def CreateCFileHeader():
     Str = ''\r
     for Item in H_C_FILE_HEADER:\r
         Str = WriteLine(Str, Item)\r
-    \r
+\r
     return Str\r
-  \r
+\r
 def CreateArrayItem(Value, Width = 16):\r
     MaxLength = Width\r
     Index = 0\r
     Line = '  '\r
     ArrayItem = ''\r
-    \r
+\r
     for Item in Value:\r
         if Index < MaxLength:\r
             Line = Line + Item + ', '\r
@@ -109,7 +109,7 @@ def CreateArrayItem(Value, Width = 16):
             Line = '  ' + Item +  ', '\r
             Index = 1\r
     ArrayItem = Write(ArrayItem, Line.rstrip())\r
-    \r
+\r
     return ArrayItem\r
 \r
 def CreateCFileStringDef(Name, Offset, Token, UseOtherLangDef = ''):\r
@@ -119,11 +119,11 @@ def CreateCFileStringDef(Name, Offset, Token, UseOtherLangDef = ''):
     Str = Write('', CreateArrayItem(DecToHexList(Offset)) + '  ' + COMMENT + 'offset to string ' + Name + ' (' + DecToHexStr(Token, 4) + ')' + Comment)\r
 \r
     return Str\r
-    \r
-def CreateCFileStringValue(Name, Language, Value, Offset):    \r
+\r
+def CreateCFileStringValue(Name, Language, Value, Offset):\r
     Str = WriteLine('  ', COMMENT + STRING + ' ' + Name + ' ' + OFFSET + ' ' + DecToHexStr(Offset, 8))\r
     Str = WriteLine(Str, CreateArrayItem(Value))\r
-    \r
+\r
     return Str\r
 \r
 def CreateCFileContent(BaseName, UniObjectClass):\r
@@ -143,7 +143,7 @@ def CreateCFileContent(BaseName, UniObjectClass):
 \r
         Str = WriteLine(Str, '//******************************************************************************')\r
         Str = WriteLine(Str, COMMENT + 'Start of string definitions for ' + Language)\r
-        \r
+\r
         #\r
         # EFI_HII_STRING_PACK_HEADER\r
         #\r
@@ -151,7 +151,7 @@ def CreateCFileContent(BaseName, UniObjectClass):
         Length = Offset + Length\r
         List = DecToHexList(Length) + DecToHexList(2)[0:2] + DecToHexList(Offset) + DecToHexList(Offset + len(UniToHexList(Language)) + 2) + DecToHexList(Count) + DecToHexList(0)\r
         Str = WriteLine(Str, CreateArrayItem(List, 8))\r
-        \r
+\r
         Str = WriteLine(Str, '  // offset 0x16')\r
         StrStringDef = ''\r
         StrStringValue = ''\r
@@ -162,7 +162,7 @@ def CreateCFileContent(BaseName, UniObjectClass):
             Token = Item.Token\r
             Length = Item.Length\r
             UseOtherLangDef = Item.UseOtherLangDef\r
-             \r
+\r
             if Referenced:\r
                 StrStringDef = WriteLine(StrStringDef, CreateCFileStringDef(Name, Offset, Token, UseOtherLangDef))\r
                 StrStringValue = Write(StrStringValue, CreateCFileStringValue(Name, Language, Value, Offset))\r
@@ -189,12 +189,12 @@ def CreateCFile(BaseName, UniObjectClass):
 \r
 def GetFileList(IncludeList, SkipList):\r
     if IncludeList == None:\r
-        raise AutoGenError("Include path for unicode file is not defined")\r
-    \r
+        EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, "Include path for unicode file is not defined")\r
+\r
     FileList = []\r
     if SkipList == None:\r
         SkipList = []\r
-        \r
+\r
     for Dir in IncludeList:\r
         for File in os.listdir(Dir):\r
             File = os.path.join(Dir, os.path.normcase(File))\r
@@ -211,16 +211,16 @@ def GetFileList(IncludeList, SkipList):
                 if os.path.splitext(File)[1].upper() == Skip.upper():\r
                     IsSkip = True\r
                     break\r
-            \r
+\r
             if not IsSkip:\r
                 FileList.append(File)\r
-    \r
+\r
     return FileList\r
 \r
 def SearchString(UniObjectClass, FileList):\r
     if FileList == []:\r
         return UniObjectClass\r
-    \r
+\r
     for File in FileList:\r
         if os.path.isfile(File):\r
             Lines = open(File, 'r')\r
@@ -229,27 +229,27 @@ def SearchString(UniObjectClass, FileList):
                 for StrName in StringTokenList:\r
                     EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: " + StrName)\r
                     UniObjectClass.SetStringReferenced(StrName)\r
-    \r
+\r
     UniObjectClass.ReToken()\r
-    \r
+\r
     return UniObjectClass\r
 \r
 def GetStringFiles(UniFilList, IncludeList, SkipList, BaseName):\r
     Status = True\r
     ErrorMessage = ''\r
-    \r
+\r
     if len(UniFilList) > 0:\r
         Uni = UniFileClassObject(UniFilList)\r
     else:\r
-        raise AutoGenError('No unicode files given')\r
-    \r
+        EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, 'No unicode files given')\r
+\r
     FileList = GetFileList(IncludeList, SkipList)\r
-    \r
+\r
     Uni = SearchString(Uni, FileList)\r
-    \r
+\r
     HFile = CreateHFile(BaseName, Uni)\r
     CFile = CreateCFile(BaseName, Uni)\r
-    \r
+\r
     return HFile, CFile\r
 \r
 def Write(Target, Item):\r
@@ -257,12 +257,12 @@ def Write(Target, Item):
 \r
 def WriteLine(Target, Item):\r
     return Target + Item + '\n'\r
-    \r
+\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 if __name__ == '__main__':\r
     EdkLogger.info('start')\r
-    \r
+\r
 #    UniFileList = [\r
 #        r'E:\SRC\r9prime\verify\LakeportX64Dev\LakeportX64Pkg\SmbiosMiscDxe\SmbiosMiscStrings.uni',\r
 #        r'E:\SRC\r9prime\verify\LakeportX64Dev\LakeportX64Pkg\SmbiosMiscDxe\MiscOemString.uni',\r
@@ -288,7 +288,7 @@ if __name__ == '__main__':
 #        r'E:\SRC\r9prime\verify\LakeportX64Dev\LakeportX64Pkg',\r
 #        r'E:\SRC\r9prime\verify\LakeportX64Dev\LakeportX64Pkg\Include',\r
 #    ]\r
-    \r
+\r
     UniFileList = [\r
         r'C:\SVN\EDKII\Nt32Pkg\PlatformBdsDxe\Generic\FrontPageStrings.uni',\r
         r'C:\SVN\EDKII\Nt32Pkg\PlatformBdsDxe\Generic\Strings.uni',\r
@@ -317,7 +317,7 @@ if __name__ == '__main__':
         r'C:\SVN\EDKII\MdeModulePkg',\r
         r'C:\SVN\EDKII\MdeModulePkg\Include'\r
     ]\r
-    \r
+\r
     SkipList = ['.inf', '.uni']\r
     BaseName = 'SetupBrowser'\r
     (h, c) = GetStringFiles(UniFileList, IncludeList, SkipList, BaseName)\r
@@ -325,5 +325,5 @@ if __name__ == '__main__':
     cfile = open('unistring.c', 'w')\r
     hfile.write(h)\r
     cfile.write(c)\r
-    \r
+\r
     EdkLogger.info('end')\r
index 68b354b..d4a06aa 100644 (file)
@@ -8,7 +8,7 @@
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 #\r
-#This file is used to collect all defined strings in multiple uni files \r
+#This file is used to collect all defined strings in multiple uni files\r
 #\r
 \r
 import os, codecs, re\r
@@ -53,7 +53,7 @@ class StringDefClassObject(object):
         self.Referenced = Referenced\r
         self.UseOtherLangDef = UseOtherLangDef\r
         self.Length = 0\r
-        \r
+\r
         if Name != None:\r
             self.StringName = Name\r
             self.StringNameByteList = UniToHexList(Name)\r
@@ -76,21 +76,22 @@ class UniFileClassObject(object):
         self.Token = 2\r
         self.LanguageDef = []                   #[ [u'LanguageIdentifier', u'PrintableName'], ... ]\r
         self.OrderedStringList = {}             #{ u'LanguageIdentifier' : [StringDefClassObject]  }\r
-        \r
+\r
         if len(self.FileList) > 0:\r
             self.LoadUniFiles(FileList)\r
 \r
     def GetLangDef(self, Line):\r
         Lang = Line.split()\r
         if len(Lang) != 3:\r
-            raise ParserError(msg="""Wrong language definition '""" + Line + """' which should be '#langdef eng "English"'""")\r
+            EdkLogger.error("Unicode File Parser", PARSER_ERROR, "Wrong language definition",\r
+                            ExtraData="""%s\n\t*Correct format is '#langdef eng "English"'""" % Line)\r
         else:\r
             LangName = Lang[1]\r
             LangPrintName = Lang[2][1:-1]\r
 \r
         if [LangName, LangPrintName] not in self.LanguageDef:\r
             self.LanguageDef.append([LangName, LangPrintName])\r
-        \r
+\r
         #\r
         # Add language string\r
         #\r
@@ -98,12 +99,12 @@ class UniFileClassObject(object):
         self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', LangName, LangPrintName, 1, True)\r
 \r
         return True\r
-        \r
+\r
     def GetStringObject(self, Item):\r
         Name = ''\r
         Language = ''\r
         Value = ''\r
-        \r
+\r
         Name = Item.split()[1]\r
         LanguageList = Item.split(u'#language ')\r
         for IndexI in range(len(LanguageList)):\r
@@ -113,15 +114,15 @@ class UniFileClassObject(object):
                 Language = LanguageList[IndexI].split()[0]\r
                 Value = LanguageList[IndexI][LanguageList[IndexI].find(u'\"') + len(u'\"') : LanguageList[IndexI].rfind(u'\"')].replace(u'\r\n', u'')\r
                 self.AddStringToList(Name, Language, Value)\r
-    \r
+\r
     def GetIncludeFile(self, Item, Dir):\r
         FileName = Item[Item.find(u'#include ') + len(u'#include ') :Item.find(u' ', len(u'#include '))][1:-1]\r
         self.LoadUniFile(FileName)\r
-    \r
+\r
     def PreProcess(self, File):\r
         if not os.path.exists(File) or not os.path.isfile(File):\r
-            raise ParserError(msg=File + ' is not a valid file')\r
-        \r
+            EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File)\r
+\r
         Dir = os.path.dirname(File)\r
         FileIn = codecs.open(File, mode='rb', encoding='utf-16').readlines()\r
         Lines = []\r
@@ -139,7 +140,7 @@ class UniFileClassObject(object):
             Line = Line.replace(u'/string', u'#string')\r
             Line = Line.replace(u'/language', u'#language')\r
             Line = Line.replace(u'/include', u'#include')\r
-                        \r
+\r
             Line = Line.replace(UNICODE_WIDE_CHAR, WIDE_CHAR)\r
             Line = Line.replace(UNICODE_NARROW_CHAR, NARROW_CHAR)\r
             Line = Line.replace(UNICODE_NON_BREAKING_CHAR, NON_BREAKING_CHAR)\r
@@ -153,24 +154,24 @@ class UniFileClassObject(object):
 #           if Line.find(u'\\x'):\r
 #               hex = Line[Line.find(u'\\x') + 2 : Line.find(u'\\x') + 6]\r
 #               hex = "u'\\u" + hex + "'"\r
-                        \r
+\r
             IncList = gIncludePattern.findall(Line)\r
             if len(IncList) == 1:\r
                 Lines.extend(self.PreProcess(os.path.join(Dir, IncList[0])))\r
                 continue\r
 \r
             Lines.append(Line)\r
-        \r
+\r
         return Lines\r
-    \r
+\r
     def LoadUniFile(self, File = None):\r
         if File == None:\r
-            raise ParserError(ms='No unicode file is given')\r
+            EdkLogger.error("Unicode File Parser", PARSER_ERROR, 'No unicode file is given')\r
         #\r
         # Process special char in file\r
         #\r
         Lines = self.PreProcess(File)\r
-        \r
+\r
         #\r
         # Get Unicode Information\r
         #\r
@@ -180,14 +181,14 @@ class UniFileClassObject(object):
                 SecondLine = Lines[IndexI + 1]\r
             if (IndexI + 2) < len(Lines):\r
                 ThirdLine = Lines[IndexI + 2]\r
-                                    \r
+\r
             #\r
             # Get Language def information\r
-            # \r
+            #\r
             if Line.find(u'#langdef ') >= 0:\r
                 self.GetLangDef(Line)\r
                 continue\r
-            \r
+\r
             Name = ''\r
             Language = ''\r
             Value = ''\r
@@ -217,7 +218,7 @@ class UniFileClassObject(object):
                 Value = Value.replace(u'\r\n', u'')\r
                 self.AddStringToList(Name, Language, Value)\r
                 continue\r
-            \r
+\r
             #\r
             # Get string def information format 2 as below\r
             #\r
@@ -240,17 +241,17 @@ class UniFileClassObject(object):
                         StringItem = StringItem + Lines[IndexJ]\r
                     elif Lines[IndexJ].find(u'\"') >= 2:\r
                         StringItem = StringItem[ : StringItem.rfind(u'\"')] + Lines[IndexJ][Lines[IndexJ].find(u'\"') + len(u'\"') : ]\r
-                self.GetStringObject(StringItem)              \r
-    \r
+                self.GetStringObject(StringItem)\r
+\r
     def LoadUniFiles(self, FileList = []):\r
         if len(FileList) > 0:\r
             for File in FileList:\r
                 self.LoadUniFile(File)\r
-                \r
+\r
     def AddStringToList(self, Name, Language, Value, Token = None, Referenced = False, UseOtherLangDef = '', Index = -1):\r
         if Language not in self.OrderedStringList:\r
             self.OrderedStringList[Language] = []\r
-        \r
+\r
         IsAdded = False\r
         for Item in self.OrderedStringList[Language]:\r
             if Name == Item.StringName:\r
@@ -262,26 +263,26 @@ class UniFileClassObject(object):
                 self.OrderedStringList[Language].append(StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef))\r
             else:\r
                 self.OrderedStringList[Language].insert(Index, StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef))\r
-    \r
+\r
     def SetStringReferenced(self, Name):\r
         for Lang in self.OrderedStringList:\r
             for Item in self.OrderedStringList[Lang]:\r
                 if Name == Item.StringName:\r
                     Item.Referenced = True\r
                     break\r
-    \r
+\r
     def FindStringValue(self, Name, Lang):\r
         for Item in self.OrderedStringList[Lang]:\r
             if Item.StringName == Name:\r
                 return Item\r
-        \r
+\r
         return None\r
-    \r
+\r
     def ReToken(self):\r
         #\r
         # Search each string to find if it is defined for each language\r
         # Use secondary language value to replace if missing in any one language\r
-        #           \r
+        #\r
         for IndexI in range(0, len(self.LanguageDef)):\r
             LangKey = self.LanguageDef[IndexI][0]\r
             for Item in self.OrderedStringList[LangKey]:\r
@@ -294,7 +295,7 @@ class UniFileClassObject(object):
                     if self.FindStringValue(Name, LangFind) == None:\r
                         Token = len(self.OrderedStringList[LangFind])\r
                         self.AddStringToList(Name, LangFind, Value, Token, Referenced, LangKey, Index)\r
-        \r
+\r
         #\r
         # Retoken\r
         #\r
@@ -314,7 +315,7 @@ class UniFileClassObject(object):
             for Index in range(len(NotReferencedStringList)):\r
                 NotReferencedStringList[Index].Token = Token + Index\r
                 self.OrderedStringList[LangName].append(NotReferencedStringList[Index])\r
-        \r
+\r
     def ShowMe(self):\r
         print self.LanguageDef\r
         #print self.OrderedStringList\r
@@ -322,7 +323,7 @@ class UniFileClassObject(object):
             print Item\r
             for Member in self.OrderedStringList[Item]:\r
                 print str(Member)\r
-            \r
+\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 if __name__ == '__main__':\r
index d6a6965..cc0833a 100755 (executable)
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #
 
-#
-# name
-# type
-# lineno
-# msg
-# arg
-# arg1
-# arg2
-# directory
-# resource
-# structure
-# attribute
-# port
-#
-
 FILE_NOT_FOUND = 0
 FILE_OPEN_FAILURE = 1
 FILE_WRITE_FAILURE = 2
@@ -84,131 +69,64 @@ GENFDS_ERROR = 0xF002
 MIGRATION_ERROR = 0xF010
 UNKNOWN_ERROR = 0xFFFF
 
-gKeyWord = ["name", "type", "lineno", "msg", "arg", "arg1", "arg2", "directory",
-            "resource", "structure", "attribute", "port", "usage"]
-
 gErrorMessage = {
-    FILE_NOT_FOUND          :   "File not found: %(name)s",
-    FILE_OPEN_FAILURE       :   "Opening file: %(name)s",
-    FILE_WRITE_FAILURE      :   "Writing file: %(name)s",
-    FILE_PARSE_FAILURE      :   "Parsing file: %(name)s",
-    FILE_READ_FAILURE       :   "Reading file: %(name)s",
-    FILE_CREATE_FAILURE     :   "Creating file: %(name)s",
-    FILE_CHECKSUM_FAILURE   :   "Invalid checksum of file: %(name)s",
-    FILE_COMPRESS_FAILURE   :   "Compressing file: %(name)s",
-    FILE_DECOMPRESS_FAILURE :   "Decompressing file: %(name)s",
-    FILE_MOVE_FAILURE       :   "Moving file: %(name)s",
-    FILE_DELETE_FAILURE     :   "Deleting file: %(name)s",
-    FILE_COPY_FAILURE       :   "Copying file: %(name)s",
-    FILE_POSITIONING_FAILURE:   "Seeking position of ile: %(name)s",
-    FILE_ALREADY_EXIST      :   "File or directory already exists: %(name)s",
-    FILE_UNKNOWN_ERROR      :   "Unknown error encountered on file: %(name)s",
-
-    OPTION_UNKNOWN          :   "Unknown option: %(name)s\n%(usage)s",
-    OPTION_MISSING          :   "Missing option: %(name)s\n%(usage)s",
-    OPTION_CONFLICT         :   "Conflict options: %(arg1) <-> %(arg2)\n%(usage)s",
-    OPTION_VALUE_INVALID    :   "Invalid value of option: %(name)s\n%(usage)s",
-    OPTION_DEPRECATED       :   "Deprecated option: %(name)s\n%(usage)s",
-    OPTION_NOT_SUPPORTED    :   "Unsupported option: %(name)s\n%(usage)s",
+    FILE_NOT_FOUND          :   "File not found",
+    FILE_OPEN_FAILURE       :   "File open failure",
+    FILE_WRITE_FAILURE      :   "File write failure",
+    FILE_PARSE_FAILURE      :   "File parse failure",
+    FILE_READ_FAILURE       :   "File read failure",
+    FILE_CREATE_FAILURE     :   "File create failure",
+    FILE_CHECKSUM_FAILURE   :   "Invalid checksum of file",
+    FILE_COMPRESS_FAILURE   :   "File compress failure",
+    FILE_DECOMPRESS_FAILURE :   "File decompress failure",
+    FILE_MOVE_FAILURE       :   "File move failure",
+    FILE_DELETE_FAILURE     :   "File delete failure",
+    FILE_COPY_FAILURE       :   "File copy failure",
+    FILE_POSITIONING_FAILURE:   "Failed to seeking position",
+    FILE_ALREADY_EXIST      :   "File or directory already exists",
+    FILE_UNKNOWN_ERROR      :   "Unknown error encountered on file",
+
+    OPTION_UNKNOWN          :   "Unknown option",
+    OPTION_MISSING          :   "Missing option",
+    OPTION_CONFLICT         :   "Conflict options",
+    OPTION_VALUE_INVALID    :   "Invalid value of option",
+    OPTION_DEPRECATED       :   "Deprecated option",
+    OPTION_NOT_SUPPORTED    :   "Unsupported option",
     OPTION_UNKNOWN_ERROR    :   "Unknown error when processing options",
 
-    PARAMETER_INVALID       :   "Invalid parameter: %(name)s",
-    PARAMETER_MISSING       :   "Missing parameter: %(name)s",
+    PARAMETER_INVALID       :   "Invalid parameter",
+    PARAMETER_MISSING       :   "Missing parameter",
     PARAMETER_UNKNOWN_ERROR :   "Unknown error in parameters",
 
-    FORMAT_INVALID          :   "Invalid sytax/format at line %(lineno)s in file %(name)s",
-    FORMAT_NOT_SUPPORTED    :   "Not supported: %(name)s",
-    FORMAT_UNKNOWN          :   "Unknown format: %(name)s",
-    FORMAT_UNKNOWN_ERROR    :   "Unknown error in %(name)s",
-
-    RESOURCE_NOT_AVAILABLE  :   "%(name)s is not available",
-    RESOURCE_ALLOCATE_FAILURE :   "Failed to allocate %(name)s",
-    RESOURCE_FULL           :   "%(name)s is full",
-    RESOURCE_OVERFLOW       :   "%(name)s is overflow",
-    RESOURCE_UNDERRUN       :   "%(name)s is underrun",
-    RESOURCE_UNKNOWN_ERROR  :   "Unkown error in %(name)s",
-
-    ATTRIBUTE_NOT_AVAILABLE :   "%(name)s is not available",
-    ATTRIBUTE_GET_FAILURE   :   "Failed to get %(name)s",
-    ATTRIBUTE_SET_FAILURE   :   "Failed to set %(name)s",
-    ATTRIBUTE_UPDATE_FAILURE:   "Failed to update %(name)s",
-    ATTRIBUTE_ACCESS_DENIED :   "Access denied: %(name)s",
-    ATTRIBUTE_UNKNOWN_ERROR :   "Unknown error when accessing %(name)s",
-
-    IO_NOT_READY            :   "%(name)s is not ready",
-    IO_BUSY                 :   "%(name)s is busy",
-    IO_TIMEOUT              :   "%(name)s timeout",
-    IO_UNKNOWN_ERROR        :   "Unknown error in %(name)s",
-
-    AUTOGEN_ERROR           :   "%(msg)s",
-    PARSER_ERROR            :   "%(msg)s",
-    GENFDS_ERROR            :   "%(msg)s",
-    MIGRATION_ERROR         :   "%(msg)s",
-    
-    UNKNOWN_ERROR           :   "Unknown error: %(msg)s",
+    FORMAT_INVALID          :   "Invalid sytax/format",
+    FORMAT_NOT_SUPPORTED    :   "Not supported sytax/format",
+    FORMAT_UNKNOWN          :   "Unknown format",
+    FORMAT_UNKNOWN_ERROR    :   "Unknown error in sytax/format ",
+
+    RESOURCE_NOT_AVAILABLE  :   "Not available",
+    RESOURCE_ALLOCATE_FAILURE :   "Allocate failure",
+    RESOURCE_FULL           :   "Full",
+    RESOURCE_OVERFLOW       :   "Overflow",
+    RESOURCE_UNDERRUN       :   "Underrun",
+    RESOURCE_UNKNOWN_ERROR  :   "Unkown error",
+
+    ATTRIBUTE_NOT_AVAILABLE :   "Not available",
+    ATTRIBUTE_GET_FAILURE   :   "Failed to retrieve",
+    ATTRIBUTE_SET_FAILURE   :   "Failed to set",
+    ATTRIBUTE_UPDATE_FAILURE:   "Failed to update",
+    ATTRIBUTE_ACCESS_DENIED :   "Access denied",
+    ATTRIBUTE_UNKNOWN_ERROR :   "Unknown error when accessing",
+
+    IO_NOT_READY            :   "Not ready",
+    IO_BUSY                 :   "Busy",
+    IO_TIMEOUT              :   "Timeout",
+    IO_UNKNOWN_ERROR        :   "Unknown error in IO operation",
+
+    UNKNOWN_ERROR           :   "Unknown error",
 }
 
-class BuildToolError(Exception):
-    def __init__(self, code=0xffff, **kwargs):
-        if code not in gErrorMessage:
-            code = 0xffff
-
-        for key in gKeyWord:
-            if key not in kwargs:
-                kwargs[key] = "<Unknown>"
-
-        self.ErrorMessage = gErrorMessage[code] % kwargs
-        self.ErrorCode = 0xEEEE0000 + code
-
-    def __str__(self):
-        return "ERROR: %04X: %s" % (self.ErrorCode & 0xffff, self.ErrorMessage)
-
-class AutoGenError(BuildToolError):
-    def __init__(self, code=AUTOGEN_ERROR, **kwargs):
-        BuildToolError.__init__(self, code, **kwargs)
-
-    def __str__(self):
-        return "\nAutoGen: %s" % BuildToolError.__str__(self)
-
-class ParserError(BuildToolError):
-    def __init__(self, code=PARSER_ERROR, **kwargs):
-        BuildToolError.__init__(self, code, **kwargs)
-
-    def __str__(self):
-        return "\nParser: %s" % BuildToolError.__str__(self)
-
-class GenFdsError(BuildToolError):
-    def __init__(self, code=GENFDS_ERROR, **kwargs):
-        BuildToolError.__init__(self, code, **kwargs)
-
-    def __str__(self):
-        return "\nGenFds: %s" % BuildToolError.__str__(self)
-
-class MigrationError(BuildToolError):
-    def __init__(self, code=MIGRATION_ERROR, **kwargs):
-        BuildToolError.__init__(self, code, **kwargs)
+class FatalError(Exception):
+    pass
 
-    def __str__(self):
-        return "\nMigration: %s" % BuildToolError.__str__(self)
-    
 if __name__ == "__main__":
-    try:
-        raise AutoGenError(FILE_ALREADY_EXIST, name="my_fault.file")
-    except BuildToolError, e:
-        print e
-    except Exception, e:
-        print "Python:", e
-
-    try:
-        raise GenFdsError(msg="my fault")
-    except BuildToolError, e:
-        print e
-    except Exception, e:
-        print "Python:", e
-
-    try:
-        xyz = abc[1]
-    except BuildToolError, e:
-        print e
-    except Exception, e:
-        print "\nPython:", e
+    pass
index 6bd0a73..e1c754e 100755 (executable)
@@ -12,6 +12,7 @@
 #\r
 \r
 import os\r
+import EdkLogger\r
 from String import *\r
 from DataType import *\r
 from Identification import *\r
@@ -510,8 +511,8 @@ class Dsc(DscObject):
         for Key in Pcds:\r
             (Status, SkuInfoList) = self.GenSkuInfoList(Item[1], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', '', Key[2])\r
             if Status == False:\r
-                ErrorMsg = "SKUID '%s' of '%s' not defined in file '%s'" % (SkuInfoList, Type, self.Platform.Header.FullPath)\r
-                raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                ErrorMsg = "SKUID '%s' of '%s' is not defined" % (SkuInfoList, Type)\r
+                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, File=self.Platform.Header.FullPath)\r
             Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], SkuInfoList, [])\r
             Pcd.SupArchList = Pcds[Key]\r
             self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
@@ -543,8 +544,8 @@ class Dsc(DscObject):
         for Key in Pcds:\r
             (Status, SkuInfoList) = self.GenSkuInfoList(Item[1], self.Platform.SkuInfos.SkuInfoList, Key[2], Key[3], Key[4], Key[5], '', '')\r
             if Status == False:\r
-                ErrorMsg = "SKUID '%s' of '%s' not defined in file '%s'" % (SkuInfoList, Type, self.Platform.Header.FullPath)\r
-                raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                ErrorMsg = "SKUID '%s' of '%s' is not defined" % (SkuInfoList, Type)\r
+                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, File=self.Platform.Header.FullPath)\r
             Pcd = PcdClass(Key[0], '', Key[1], '', Key[6], Key[5], Key[7], [], SkuInfoList, [])\r
             Pcd.SupArchList = Pcds[Key]\r
             self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
@@ -576,8 +577,8 @@ class Dsc(DscObject):
         for Key in Pcds:\r
             (Status, SkuInfoList) = self.GenSkuInfoList(Item[1], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', Key[2], '')\r
             if Status == False:\r
-                ErrorMsg = "SKUID '%s' of '%s' not defined in file '%s'" % (SkuInfoList, Type, self.Platform.Header.FullPath)\r
-                raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                ErrorMsg = "SKUID '%s' of '%s' is not defined." % (SkuInfoList, Type)\r
+                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, File=self.Platform.Header.FullPath)\r
             Pcd = PcdClass(Key[0], '', Key[1], '', Key[3], '', Key[4], [], SkuInfoList, [])\r
             Pcd.SupArchList = Pcds[Key]\r
             self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
index fc8f6c0..2bfd28f 100755 (executable)
@@ -202,7 +202,7 @@ class WorkspaceBuild(object):
         if os.path.exists(File) and os.path.isfile(File):\r
             self.DscDatabase[DscFileName] = Dsc(File, True, True, self.WorkspaceDir)\r
         else:\r
-            raise ParserError(FILE_NOT_FOUND, name = File)\r
+            EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData = File)\r
 \r
         #\r
         # Parse platform to get module\r
@@ -553,7 +553,7 @@ class WorkspaceBuild(object):
                     EdkLogger.debug(EdkLogger.DEBUG_3, "%s for module type %s is not supported (%s)" % (Key + (LibraryPath,)))\r
                     continue\r
                 if LibraryPath == None or LibraryPath == "":\r
-                    EdkLogger.warn("\tWARNING: Library instance for library class %s is not found" % LibraryClassName)\r
+                    EdkLogger.warn(None, "\tWARNING: Library instance for library class %s is not found" % LibraryClassName)\r
                     continue\r
 \r
                 LibraryModule = ModuleDatabase[LibraryPath]\r
@@ -586,8 +586,10 @@ class WorkspaceBuild(object):
             #\r
             for Lc in m.LibraryClass:\r
                 if Lc.LibraryClass in LibraryInstance and str(m) != str(LibraryInstance[Lc.LibraryClass]):\r
-                    raise AutoGenError(msg="More than one library instance found for library class %s in module %s:\n\t%s\n\t%s"\r
-                                           % (Lc.LibraryClass, Module, LibraryInstance[Lc.LibraryClass], str(m)))\r
+                    EdkLogger.error("AutoGen", AUTOGEN_ERROR,\r
+                                    "More than one library instance found for library class %s in module %s" % (Lc.LibraryClass, Module),\r
+                                    ExtraData="\t%s\n\t%s" % (LibraryInstance[Lc.LibraryClass], str(m))\r
+                                    )\r
             if ConsumedByList[m] == []:\r
                 Q.insert(0, m)\r
         #\r
@@ -653,9 +655,9 @@ class WorkspaceBuild(object):
         #\r
         for m in LibraryList:\r
             if ConsumedByList[m] != [] and m in Constructor:\r
-                errorMessage = 'Library [%s] with constructors has a cycle:' % str(m)\r
-                errorMessage += "\n\tconsumed by " + "\n\tconsumed by ".join([str(l) for l in ConsumedByList[m]])\r
-                raise AutoGenError(msg=errorMessage)\r
+                ErrorMessage = 'Library [%s] with constructors has a cycle' % str(m)\r
+                EdkLogger.error("AutoGen", AUTOGEN_ERROR, ErrorMessage,\r
+                                "\tconsumed by " + "\n\tconsumed by ".join([str(l) for l in ConsumedByList[m]]))\r
             if m not in SortedLibraryList:\r
                 SortedLibraryList.append(m)\r
 \r
@@ -764,7 +766,7 @@ class WorkspaceBuild(object):
             if InfFileName not in self.InfDatabase:\r
                 self.InfDatabase[InfFileName] = Inf(File, True, True, self.WorkspaceDir)\r
         else:\r
-            raise ParserError(FILE_NOT_FOUND, name = File)\r
+            EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData=File)\r
 \r
     #\r
     # Create a Dec instance for input dec file and add it to DecDatabase\r
@@ -776,7 +778,7 @@ class WorkspaceBuild(object):
             if DecFileName not in self.DecDatabase:\r
                 self.DecDatabase[DecFileName] = Dec(File, True, True, self.WorkspaceDir)\r
         else:\r
-            raise ParserError(FILE_NOT_FOUND, name = File)\r
+            EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData=File)\r
 \r
     #\r
     # Search PlatformBuildDatabase to find LibraryClass Instance for Module\r
@@ -871,7 +873,7 @@ class WorkspaceBuild(object):
                 break\r
         if not IsFoundInDec:\r
             ErrorMsg = "Pcd '%s' defined in module '%s' is not found in any package" % (Name, ModuleName)\r
-            raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+            EdkLogger.error("AutoGen", PARSER_ERROR, ErrorMsg)\r
 \r
         #\r
         # Third get information from <Pcd> of <Compontents> from module database\r
@@ -903,7 +905,7 @@ class WorkspaceBuild(object):
         #\r
         if not IsFoundInDsc:\r
             ErrorMsg = "Pcd '%s' defined in module '%s' is not found in any platform" % (Name, ModuleName)\r
-            raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+            EdkLogger.error("AutoGen", PARSER_ERROR, ErrorMsg)\r
 \r
         return PcdClassObject(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, IsOverrided)\r
 \r
index 3600b4a..c9192e8 100644 (file)
@@ -1,4 +1,6 @@
 import sys, os, logging
+import traceback
+from  Common.BuildToolError import *
 
 DEBUG_0 = 1
 DEBUG_1 = 2
@@ -12,114 +14,196 @@ DEBUG_8 = 9
 DEBUG_9 = 10
 VERBOSE = 15
 WARN    = VERBOSE
-INFO    = logging.INFO      # 20
-ERROR   = 40
-QUIET   = 50
-
-_log_levels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5, DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO, ERROR, QUIET]
-
-_debug_logger = logging.getLogger("tool_debug")
-_debug_logger.setLevel(INFO)
-_debug_ch = logging.StreamHandler(sys.stdout)
-_debug_formatter = logging.Formatter("#[%(asctime)s] %(filename)s:%(lineno)d: %(message)s", datefmt="%H:%M:%S")
-_debug_ch.setFormatter(_debug_formatter)
-_debug_logger.addHandler(_debug_ch)
-
-_verbose_logger = logging.getLogger("tool_verbose")
-_verbose_logger.setLevel(INFO)
-_verbose_ch = logging.StreamHandler(sys.stdout)
-_verbose_formatter = logging.Formatter("> %(message)s")
-_verbose_ch.setFormatter(_verbose_formatter)
-_verbose_logger.addHandler(_verbose_ch)
-
-_warn_logger = logging.getLogger("tool_warn")
-_warn_logger.setLevel(INFO)
-_warn_ch = logging.StreamHandler(sys.stdout)
-_warn_formatter = logging.Formatter("! %(message)s")
-_warn_ch.setFormatter(_warn_formatter)
-_warn_logger.addHandler(_warn_ch)
-
-_info_logger = logging.getLogger("tool_info")
-_info_logger.setLevel(INFO)
-_info_ch = logging.StreamHandler(sys.stdout)
-_info_formatter = logging.Formatter("%(message)s")
-_info_ch.setFormatter(_info_formatter)
-_info_logger.addHandler(_info_ch)
-
-_error_logger = logging.getLogger("tool_error")
-_error_logger.setLevel(INFO)
-_error_ch = logging.StreamHandler(sys.stderr)
-_error_formatter = logging.Formatter("? %(message)s")
-_error_ch.setFormatter(_error_formatter)
-_error_logger.addHandler(_error_ch)
-
-_quiet_logger = logging.getLogger("tool_quiet")
-_quiet_logger.setLevel(INFO)
-_quiet_ch = logging.StreamHandler(sys.stderr)
-_quiet_formatter = logging.Formatter("%(message)s")
-_quiet_ch.setFormatter(_quiet_formatter)
-_quiet_logger.addHandler(_quiet_ch)
-
-
-debug   = _debug_logger.log
-
-def verbose(msg):
-    return _verbose_logger.log(VERBOSE, msg)
-
-def warn(msg):
-    return _warn_logger.log(WARN, msg)
-
-info    = _info_logger.info
-
-error   = _error_logger.error
-
-quiet   = _quiet_logger.critical
-
-def setLevel(level):
-    if level not in _log_levels:
-        info("Not supported log level (%d)" % level)
-        level = INFO
-    _debug_logger.setLevel(level)
-    _verbose_logger.setLevel(level)
-    _info_logger.setLevel(level)
-    _warn_logger.setLevel(level)
-    _error_logger.setLevel(level)
-    _quiet_logger.setLevel(level)
-
-def setLogFile(log):
-    if os.path.exists(log):
-        os.remove(log)
-
-    _ch = logging.FileHandler(log)
-    _ch.setFormatter(_debug_formatter)
-    _debug_logger.addHandler(_ch)
-
-    _ch = logging.FileHandler(log)
-    _ch.setFormatter(_verbose_formatter)
-    _verbose_logger.addHandler(_ch)
-
-    _ch = logging.FileHandler(log)
-    _ch.setFormatter(_warn_formatter)
-    _warn_logger.addHandler(_ch)
-
-    _ch = logging.FileHandler(log)
-    _ch.setFormatter(_info_formatter)
-    _info_logger.addHandler(_ch)
-
-    _ch = logging.FileHandler(log)
-    _ch.setFormatter(_error_formatter)
-    _error_logger.addHandler(_ch)
-
-    _ch = logging.FileHandler(log)
-    _ch.setFormatter(_quiet_formatter)
-    _quiet_logger.addHandler(_ch)
+INFO    = 20
+QUIET   = 40
+ERROR   = 50
+
+_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5, DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO, ERROR, QUIET]
+
+_DebugLogger = logging.getLogger("tool_debug")
+_DebugLogger.setLevel(INFO)
+_DebugChannel = logging.StreamHandler(sys.stdout)
+_DebugFormatter = logging.Formatter("[%(asctime)s.%(msecs)d]: %(message)s", datefmt="%H:%M:%S")
+_DebugChannel.setFormatter(_DebugFormatter)
+_DebugLogger.addHandler(_DebugChannel)
+
+##_VerboseLogger = logging.getLogger("tool_verbose")
+##_VerboseLogger.setLevel(INFO)
+##_VerboseChannel = logging.StreamHandler(sys.stdout)
+##_VerboseFormatter = logging.Formatter("%(message)s")
+##_VerboseChannel.setFormatter(_VerboseFormatter)
+##_VerboseLogger.addHandler(_VerboseChannel)
+##
+##_WarnLogger = logging.getLogger("tool_warn")
+##_WarnLogger.setLevel(INFO)
+##_WarnChannel = logging.StreamHandler(sys.stdout)
+##_WarnFormatter = logging.Formatter("%(message)s")
+##_WarnChannel.setFormatter(_WarnFormatter)
+##_WarnLogger.addHandler(_WarnChannel)
+
+_InfoLogger = logging.getLogger("tool_info")
+_InfoLogger.setLevel(INFO)
+_InfoChannel = logging.StreamHandler(sys.stdout)
+_InfoFormatter = logging.Formatter("%(message)s")
+_InfoChannel.setFormatter(_InfoFormatter)
+_InfoLogger.addHandler(_InfoChannel)
+
+_ErrorLogger = logging.getLogger("tool_error")
+_ErrorLogger.setLevel(INFO)
+_ErrorCh = logging.StreamHandler(sys.stderr)
+_ErrorFormatter = logging.Formatter("%(message)s")
+_ErrorCh.setFormatter(_ErrorFormatter)
+_ErrorLogger.addHandler(_ErrorCh)
+
+_ErrorMessageTemplate = '\n%(tool)s...\n%(file)s(%(line)s): error %(errorcode)X: %(msg)s'
+_ErrorMessageTemplateWithoutFile = '\n%(tool)s: : error %(errorcode)X: %(msg)s'
+_WarningMessageTemplate = '%(tool)s...\n%(file)s(%(line)s): warning: %(msg)s'
+_WarningMessageTemplateWithoutFile = '%(tool)s: : warning: %(msg)s'
+_DebugMessageTemplate = '%(file)s(%(line)s): debug: %(msg)s'
+
+_WarningAsError = False
+
+
+def debug(Level, Message, ExtraData=None):
+    if _DebugLogger.getEffectiveLevel() > Level:
+        return
+    if Level > DEBUG_9:
+        return
+
+    CallerStack = traceback.extract_stack()[-2]
+    TemplateDict = {
+        "file"      : CallerStack[0],
+        "line"      : CallerStack[1],
+        "msg"       : Message,
+    }
+
+    if ExtraData != None:
+        LogText = _DebugMessageTemplate % TemplateDict + "\n  " + ExtraData
+    else:
+        LogText = _DebugMessageTemplate % TemplateDict
+
+    _DebugLogger.log(Level, LogText)
+
+def verbose(Message):
+    return _InfoLogger.log(VERBOSE, Message)
+
+def warn(ToolName, Message, File=None, Line=None, ExtraData=None):
+    if _InfoLogger.getEffectiveLevel() > WARN:
+        return
+
+    # if no tool name given, use caller's source file name as tool name
+    if ToolName == None or ToolName == "":
+        ToolName = os.path.basename(traceback.extract_stack()[-2][0])
+
+    if Line == None:
+        Line = "..."
+    else:
+        Line = "%d" % Line
+
+    TemplateDict = {
+        "tool"      : ToolName,
+        "file"      : File,
+        "line"      : Line,
+        "msg"       : Message,
+    }
+
+    if File != None:
+        LogText = _WarningMessageTemplate % TemplateDict
+    else:
+        LogText = _WarningMessageTemplateWithoutFile % TemplateDict
+
+    if ExtraData != None:
+        LogText += "\n  " + ExtraData
+
+    _InfoLogger.log(WARN, LogText)
+
+    if _WarningAsError == True:
+        raise FatalError("%s failed by warning!" % ToolName)
+
+info    = _InfoLogger.info
+
+def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=None):
+    # if no tool name given, use caller's source file name as tool name
+    if ToolName == None or ToolName == "":
+        ToolName = os.path.basename(traceback.extract_stack()[-2][0])
+
+    if Line == None:
+        Line = "..."
+    else:
+        Line = "%d" % Line
+
+    if Message == None:
+        if ErrorCode in gErrorMessage:
+            Message = gErrorMessage[ErrorCode]
+        else:
+            Message = gErrorMessage[UNKNOWN_ERROR]
+
+    TemplateDict = {
+        "tool"      : ToolName,
+        "file"      : File,
+        "line"      : Line,
+        "errorcode" : ErrorCode,
+        "msg"       : Message,
+        "extra"     : ExtraData
+    }
+
+    if File != None:
+        LogText =  _ErrorMessageTemplate % TemplateDict
+    else:
+        LogText = _ErrorMessageTemplateWithoutFile % TemplateDict
+
+    if ExtraData != None:
+        LogText += "\n  " + ExtraData
+
+    _ErrorLogger.log(ERROR, LogText)
+    raise FatalError("%s failed!" % ToolName)
+
+quiet   = _ErrorLogger.error
+
+def SetLevel(Level):
+    if Level not in _LogLevels:
+        info("Not supported log level (%d)" % Level)
+        Level = INFO
+    _DebugLogger.setLevel(Level)
+    #_VerboseLogger.setLevel(Level)
+    _InfoLogger.setLevel(Level)
+    #_WarnLogger.setLevel(Level)
+    _ErrorLogger.setLevel(Level)
+    #_QuietLogger.setLevel(Level)
+
+def SetWarningAsError():
+    global _WarningAsError
+    _WarningAsError = True
+
+def SetLogFile(LogFile):
+    if os.path.exists(LogFile):
+        os.remove(LogFile)
+
+    _Ch = logging.FileHandler(LogFile)
+    _Ch.setFormatter(_DebugFormatter)
+    _DebugLogger.addHandler(_Ch)
+
+    #_Ch = logging.FileHandler(LogFile)
+    #_Ch.setFormatter(_VerboseFormatter)
+    #_VerboseLogger.addHandler(_Ch)
+
+    #_Ch = logging.FileHandler(LogFile)
+    #_Ch.setFormatter(_WarnFormatter)
+    #_WarnLogger.addHandler(_Ch)
+
+    _Ch= logging.FileHandler(LogFile)
+    _Ch.setFormatter(_InfoFormatter)
+    _InfoLogger.addHandler(_Ch)
+
+    _Ch = logging.FileHandler(LogFile)
+    _Ch.setFormatter(_ErrorFormatter)
+    _ErrorLogger.addHandler(_Ch)
+    
+    #
+    #_ch = logging.FileHandler(log)
+    #_ch.setFormatter(_quiet_formatter)
+    #_QuietLogger.addHandler(_ch)
 
 if __name__ == '__main__':
-    setLevel(QUIET)
-    quiet('hello')
+    pass
 
-    setLevel(ERROR)
-    error('hello')
-
-    setLevel(WARN)
-    warn('hello')
index 70fbce3..62e0179 100755 (executable)
@@ -70,7 +70,7 @@ def GuidStructureStringToGuidString(GuidValue):
     guidValueString = GuidValue.lower().replace("{", "").replace("}", "").replace(" ", "")\r
     guidValueList = guidValueString.split(",")\r
     if len(guidValueList) != 11:\r
-        raise AutoGenError(msg="Invalid GUID value string %s" % GuidValue)\r
+        EdkLogger.error(None, None, "Invalid GUID value string %s" % GuidValue)\r
     return "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % (\r
             int(guidValueList[0], 16),\r
             int(guidValueList[1], 16),\r
@@ -89,7 +89,7 @@ def GuidStructureStringToGuidValueName(GuidValue):
     guidValueString = GuidValue.lower().replace("{", "").replace("}", "").replace(" ", "")\r
     guidValueList = guidValueString.split(",")\r
     if len(guidValueList) != 11:\r
-        raise AutoGenError(msg="Invalid GUID value string %s" % GuidValue)\r
+        EdkLogger.error(None, None, "Invalid GUID value string %s" % GuidValue)\r
     return "%08x_%04x_%04x_%02x%02x_%02x%02x%02x%02x%02x%02x" % (\r
             int(guidValueList[0], 16),\r
             int(guidValueList[1], 16),\r
@@ -144,7 +144,7 @@ def Cache(Data, File):
         Fd = open(File, 'w')\r
         cPickle.dump(Data, Fd)\r
     except:\r
-        raise AutoGenError(FILE_OPEN_FAILURE, name=File)\r
+        EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=File)\r
     finally:\r
         if Fd != None:\r
             Fd.close()\r
@@ -154,7 +154,7 @@ def Restore(File):
         Fd = open(File, 'r')\r
         return cPickle.load(Fd)\r
     except Exception, e:\r
-        raise AutoGenError(FILE_OPEN_FAILURE, name=File)\r
+        EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=File)\r
     finally:\r
         if Fd != None:\r
             Fd.close()\r
@@ -196,7 +196,7 @@ class TemplateString(object):
                 if RepeatTime < 0:\r
                     RepeatTime = len(Value)\r
                 elif RepeatTime != len(Value):\r
-                    raise AutoGenError(msg=Key + " has different repeat time from others!")\r
+                    EdkLogger.error("TemplateString", None, Key + " has different repeat time from others!")\r
 \r
             NewString = ''\r
             for Index in range(0, RepeatTime):\r
@@ -309,15 +309,15 @@ class sdict(dict):
         value = None\r
         if key in self._key_list:\r
             value = self[key]\r
-            dict.__delitem__(self, key)\r
+            self.__delitem__(key)\r
         elif len(dv) != 0 :\r
             value = kv[0]\r
         return value\r
 \r
     def popitem(self):\r
-        key = self._key_list[0]\r
+        key = self._key_list[-1]\r
         value = self[key]\r
-        dict.__delitem__(self, key)\r
+        self.__delitem__(key)\r
         return key, value\r
 \r
 \r
index 92684e5..3839023 100644 (file)
@@ -14,6 +14,7 @@
 import DataType\r
 import os.path\r
 import string\r
+import EdkLogger\r
 from BuildToolError import *\r
 \r
 #\r
@@ -47,7 +48,7 @@ def GenDefines(String, Arch, Defines):
             return 0\r
         else:\r
             return -1\r
-    \r
+\r
     return 1\r
 \r
 #\r
@@ -62,20 +63,20 @@ def GenInclude(String, IncludeFiles, Arch):
         return True\r
     else:\r
         return False\r
-    \r
+\r
 #\r
 # Parse a string with format "InfFilename [EXEC = ExecFilename]"\r
 # Return (InfFilename, ExecFilename)\r
 #\r
 def GetExec(String):\r
     InfFilename = ''\r
-    ExecFilename = '' \r
+    ExecFilename = ''\r
     if String.find('EXEC') > -1:\r
         InfFilename = String[ : String.find('EXEC')].strip()\r
         ExecFilename = String[String.find('EXEC') + len('EXEC') : ].strip()\r
     else:\r
         InfFilename = String.strip()\r
-    \r
+\r
     return (InfFilename, ExecFilename)\r
 \r
 #\r
@@ -91,9 +92,9 @@ def GetBuildOption(String, File):
         Family = CleanString(List[0][ : List[0].find(':')])\r
         ToolChain = CleanString(List[0][List[0].find(':') + 1 : ])\r
     else:\r
-        ToolChain = CleanString(List[0])                    \r
+        ToolChain = CleanString(List[0])\r
     Flag = CleanString(List[1])\r
-    \r
+\r
     return (Family, ToolChain, Flag)\r
 \r
 #\r
@@ -109,13 +110,13 @@ def GetComponents(Lines, Key, KeyValues, CommentCharacter):
     LibraryClassItem = []\r
     BuildOption = []\r
     Pcd = []\r
-    \r
+\r
     LineList = Lines.split('\n')\r
     for Line in LineList:\r
         Line = CleanString(Line, CommentCharacter)\r
         if Line == None or Line == '':\r
             continue\r
-        \r
+\r
         if findBlock == False:\r
             ListItem = Line\r
             #find '{' at line tail\r
@@ -123,7 +124,7 @@ def GetComponents(Lines, Key, KeyValues, CommentCharacter):
                 findBlock = True\r
                 ListItem = CleanString(Line.rsplit('{', 1)[0], CommentCharacter)\r
 \r
-        if findBlock:    \r
+        if findBlock:\r
             if Line.find('<LibraryClasses>') != -1:\r
                 (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (True, False, False, False, False, False, False)\r
                 continue\r
@@ -178,7 +179,7 @@ def GetComponents(Lines, Key, KeyValues, CommentCharacter):
                 Pcd.append((DataType.TAB_PCDS_DYNAMIC_EX, Line))\r
         else:\r
             KeyValues.append([ListItem, [], [], []])\r
-        \r
+\r
     return True\r
 \r
 #\r
@@ -203,7 +204,7 @@ def GetDynamics(Lines, Key, KeyValues, CommentCharacter):
     # Get SkuId Name List\r
     #\r
     SkuIdNameList = SplitModuleType(Key)\r
-    \r
+\r
     Lines = Lines.split(DataType.TAB_SECTION_END, 1)[1]\r
     LineList = Lines.splitlines()\r
     for Line in LineList:\r
@@ -227,9 +228,9 @@ def SplitModuleType(Key):
         KeyValue = KeyValue + DataType.TAB_SPLIT + KeyList[1]\r
     ReturnValue.append(KeyValue)\r
     ReturnValue.append(GetSplitValueList(KeyList[2]))\r
-    \r
+\r
     return ReturnValue\r
-    \r
+\r
 #\r
 # Create a normal path\r
 # And replace DFEINE in the path\r
@@ -261,7 +262,7 @@ def CleanString(Line, CommentCharacter = DataType.TAB_COMMENT_SPLIT):
     Line = Line.split(CommentCharacter, 1)[0];\r
     #remove whitespace again\r
     Line = Line.strip();\r
-    \r
+\r
     return Line\r
 \r
 def GetMultipleValuesOfKeyFromLines(Lines, Key, KeyValues, CommentCharacter):\r
@@ -284,7 +285,7 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
     Value = ''\r
     DefineValues = ['']\r
     SpecValues = ['']\r
-    \r
+\r
     for Line in Lines:\r
         #\r
         # Handle DEFINE and SPEC\r
@@ -299,7 +300,7 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
                 SpecValues.remove('')\r
             SpecValues.append(GetDefineValue(Line, DataType.TAB_INF_DEFINES_SPEC, CommentCharacter))\r
             continue\r
-                \r
+\r
         #\r
         # Handle Others\r
         #\r
@@ -313,20 +314,20 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
                     Value = map(string.strip, LineList[1].split(ValueSplitCharacter))\r
                 else:\r
                     Value = CleanString(LineList[1], CommentCharacter).splitlines()\r
-                \r
+\r
                 if Key[0] not in Keys:\r
                     Dictionary[Key[0]] = Value\r
                     Keys.append(Key[0])\r
                 else:\r
-                    Dictionary[Key[0]].extend(Value)                \r
-    \r
+                    Dictionary[Key[0]].extend(Value)\r
+\r
     if DefineValues == []:\r
         DefineValues == ['']\r
     if SpecValues == []:\r
         SpecValues == ['']\r
     Dictionary[DataType.TAB_INF_DEFINES_DEFINE] = DefineValues\r
     Dictionary[DataType.TAB_INF_DEFINES_SPEC] = SpecValues\r
-    \r
+\r
     return True\r
 \r
 #\r
@@ -345,7 +346,7 @@ def PreCheck(FileName, FileContent, SupSectionTag):
         #\r
         if Line.find('$') > -1:\r
             if Line.find('$(') < 0 or Line.find(')') < 0:\r
-                raise ParserError(FORMAT_INVALID, lineno = LineNo, name = FileName)\r
+                EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName)\r
 \r
         #\r
         # Check []\r
@@ -355,7 +356,7 @@ def PreCheck(FileName, FileContent, SupSectionTag):
             # Only get one '[' or one ']'\r
             #\r
             if not (Line.find('[') > -1 and Line.find(']') > -1):\r
-                raise ParserError(FORMAT_INVALID, lineno = LineNo, name = FileName)\r
+                EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName)\r
 \r
             #\r
             # Tag not in defined value\r
@@ -368,11 +369,11 @@ def PreCheck(FileName, FileContent, SupSectionTag):
                 if Tag.upper() == DataType.TAB_USER_EXTENSIONS.upper():\r
                     break\r
                 if Tag.upper() not in map(lambda s: s.upper(), SupSectionTag):\r
-                    ErrorMsg = "'%s' is not a supportted section name found at line %s in file '%s'" % (Tag, LineNo, FileName)\r
-                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
-    \r
+                    ErrorMsg = "'%s' is not a supportted section name." % Tag\r
+                    EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=FileName, Line=LineNo)\r
+\r
     if IsFailed:\r
-       raise ParserError(FORMAT_INVALID, lineno = LineNo, name = FileName)\r
+       EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName)\r
 \r
 #\r
 # Check if the Filename is including ExtName\r
@@ -385,9 +386,10 @@ def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line):
         if Ext.upper() != ExtName.upper():\r
             ContainerFile = open(ContainerFilename, 'r').read()\r
             LineNo = GetLineNo(ContainerFile, Line)\r
-            ErrorMsg = "Invalid %s '%s' is defined at line %s in file '%s', it is NOT a valid '%s' file" % (SectionName, CheckFilename, LineNo, ContainerFilename, ExtName) \r
-            raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
-    \r
+            ErrorMsg = "Invalid %s. '%s' is found, but '%s' file is needed" % (SectionName, CheckFilename, ExtName)\r
+            EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, Line=LineNo,\r
+                            File=ContainerFilename)\r
+\r
     return True\r
 \r
 #\r
@@ -403,9 +405,10 @@ def CheckFileExist(WorkspaceDir, CheckFilename, ContainerFilename, SectionName,
         else:\r
             ContainerFile = open(ContainerFilename, 'r').read()\r
             LineNo = GetLineNo(ContainerFile, Line)\r
-            ErrorMsg = "Can't find file '%s' defined in section '%s' at line %s in file '%s'" % (CheckFile, SectionName, LineNo, ContainerFilename) \r
-            raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
-    \r
+            ErrorMsg = "Can't find file '%s' defined in section '%s'" % (CheckFile, SectionName)\r
+            EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg,\r
+                            File=ContainerFilename, Line=LineNo)\r
+\r
     return True\r
 \r
 #\r
@@ -417,7 +420,7 @@ def CheckPcdTokenInfo(TokenInfoString, Section, File):
         TokenInfoList = GetSplitValueList(TokenInfoString, DataType.TAB_SPLIT)\r
         if len(TokenInfoList) != 2:\r
             RaiseParserError(TokenInfoString, Section, File, Format)\r
-    \r
+\r
     return True\r
 \r
 #\r
@@ -428,7 +431,7 @@ def GetLineNo(FileContent, Line):
     for Index in range(len(LineList)):\r
         if LineList[Index].find(Line) > -1:\r
             return Index + 1\r
-    \r
+\r
     return -1\r
 \r
 #\r
@@ -436,8 +439,9 @@ def GetLineNo(FileContent, Line):
 #\r
 def RaiseParserError(Line, Section, File, Format):\r
     LineNo = GetLineNo(open(os.path.normpath(File), 'r').read(), Line)\r
-    ErrorMsg = "Invalid statement '%s' is found in section '%s' at line %s in file '%s', correct format is '%s'" % (Line, Section, LineNo, File, Format) \r
-    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+    ErrorMsg = "Invalid statement '%s' is found in section '%s'" % (Line, Section)\r
+    EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=File, Line=LineNo,\r
+                    ExtraData="Correct format is " + Format)\r
 \r
 #\r
 # Return a full path with workspace dir\r
index a548540..fe288b6 100644 (file)
@@ -35,7 +35,7 @@ class TargetTxtClassObject(object):
         if os.path.exists(filename) and os.path.isfile(filename):\r
              return self.ConvertTextFileToDict(filename, '#', '=')\r
         else:\r
-            raise ParseError('LoadTargetTxtFile() : No Target.txt file exist')\r
+            EdkLogger.error("Target.txt Parser", FILE_NOT_FOUND, ExtraData=filename)\r
             return 1\r
 \r
 #\r
@@ -90,4 +90,4 @@ if __name__ == '__main__':
     pass\r
     Target = TargetTxtDict(os.getenv("WORKSPACE"))\r
     print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r
-    print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]
\ No newline at end of file
+    print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]\r
index 14a8da4..6c3f3ef 100755 (executable)
@@ -40,9 +40,9 @@ class ToolDefClassObject(object):
                 F = open(FileName,'r')\r
                 FileContent = F.readlines()\r
             except:\r
-                raise ParserError(FILE_OPEN_FAILURE, name=FileName)\r
+                EdkLogger.error("tools_def.txt parser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
         else:\r
-            raise ParserError(FILE_NOT_FOUND, name=FileName)\r
+            EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=FileName)\r
 \r
         self.ToolsDefTxtDatabase = {\r
             TAB_TOD_DEFINES_TARGET          :   [],\r
@@ -72,7 +72,9 @@ class ToolDefClassObject(object):
                 EnvReference = gEnvRefPattern.findall(Value)\r
                 for Ref in EnvReference:\r
                     if Ref not in self.MacroDictionary:\r
-                        raise ParserError(msg="Environment [%s] has not been defined" % Ref)\r
+                        EdkLogger.error("tools_def.txt parser", PARSER_ERROR,\r
+                                        "Environment [%s] has not been defined" % Ref,\r
+                                        File=FileName, Line=Index+1)\r
                     Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
 \r
                 MacroName = MacroDefinition[0].strip()\r
@@ -83,7 +85,9 @@ class ToolDefClassObject(object):
             MacroReference = gMacroRefPattern.findall(Value)\r
             for Ref in MacroReference:\r
                 if Ref not in self.MacroDictionary:\r
-                    raise ParserError(msg="Macro [%s] has not been defined" % Ref)\r
+                    EdkLogger.error("tools_def.txt parser", PARSER_ERROR,\r
+                                    "Macro [%s] has not been defined" % Ref,\r
+                                    File=FileName, Line=Index+1)\r
                 Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
 \r
             List = Name.split('_')\r