]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenMake.py
index 60bd625cd2b1f7d88b2722b52cb05b51c8d70374..ea73de5fa55fb68ee402099e8b95c8cb09b6f8b8 100644 (file)
@@ -22,9 +22,10 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 from Common.BuildToolError import *\r
 from Common.Misc import *\r
-from Common.String import *\r
+from Common.StringUtils import *\r
 from BuildEngine import *\r
 import Common.GlobalData as GlobalData\r
+from collections import OrderedDict\r
 \r
 ## Regular expression for finding header file inclusions\r
 gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)\r
@@ -426,8 +427,6 @@ cleanlib:
         self.ResultFileList = []\r
         self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
 \r
-        self.SourceFileDatabase = {}        # {file type : file path}\r
-        self.DestFileDatabase = {}          # {file type : file path}\r
         self.FileBuildTargetList = []       # [(src, target string)]\r
         self.BuildTargetList = []           # [target string]\r
         self.PendingBuildTargetList = []    # [FileBuildRule objects]\r
@@ -442,7 +441,7 @@ cleanlib:
         self.LibraryMakefileList = []\r
         self.LibraryBuildDirectoryList = []\r
         self.SystemLibraryList = []\r
-        self.Macros = sdict()\r
+        self.Macros = OrderedDict()\r
         self.Macros["OUTPUT_DIR"      ] = self._AutoGenObject.Macros["OUTPUT_DIR"]\r
         self.Macros["DEBUG_DIR"       ] = self._AutoGenObject.Macros["DEBUG_DIR"]\r
         self.Macros["MODULE_BUILD_DIR"] = self._AutoGenObject.Macros["MODULE_BUILD_DIR"]\r
@@ -491,14 +490,14 @@ cleanlib:
             ImageEntryPoint = "_ModuleEntryPoint"\r
 \r
         for k, v in self._AutoGenObject.Module.Defines.iteritems():\r
-            if k not in self._AutoGenObject.Macros.keys():\r
+            if k not in self._AutoGenObject.Macros:\r
                 self._AutoGenObject.Macros[k] = v\r
 \r
-        if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():\r
+        if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros:\r
             self._AutoGenObject.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint\r
-        if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():\r
+        if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros:\r
             self._AutoGenObject.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint\r
-        if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():\r
+        if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros:\r
             self._AutoGenObject.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint\r
 \r
         PCI_COMPRESS_Flag = False\r
@@ -539,7 +538,7 @@ cleanlib:
         RespFileList = os.path.join(self._AutoGenObject.OutputDir, 'respfilelist.txt')\r
         if RespDict:\r
             RespFileListContent = ''\r
-            for Resp in RespDict.keys():\r
+            for Resp in RespDict:\r
                 RespFile = os.path.join(self._AutoGenObject.OutputDir, str(Resp).lower() + '.txt')\r
                 StrList = RespDict[Resp].split(' ')\r
                 UnexpandMacro = []\r
@@ -562,7 +561,7 @@ cleanlib:
 \r
         # convert source files and binary files to build targets\r
         self.ResultFileList = [str(T.Target) for T in self._AutoGenObject.CodaTargetList]\r
-        if len(self.ResultFileList) == 0 and len(self._AutoGenObject.SourceFileList) <> 0:\r
+        if len(self.ResultFileList) == 0 and len(self._AutoGenObject.SourceFileList) != 0:\r
             EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",\r
                             ExtraData="[%s]" % str(self._AutoGenObject))\r
 \r
@@ -699,7 +698,7 @@ cleanlib:
                     Src = self.ReplaceMacro(Src)\r
                     Dst = self.ReplaceMacro(Dst)\r
                     if Dst not in self.ResultFileList:\r
-                        self.ResultFileList.append('%s' % Dst)\r
+                        self.ResultFileList.append(Dst)\r
                     if '%s :' %(Dst) not in self.BuildTargetList:\r
                         self.BuildTargetList.append("%s :" %(Dst))\r
                         self.BuildTargetList.append('\t' + self._CP_TEMPLATE_[self._FileType] %{'Src': Src, 'Dst': Dst})\r
@@ -717,7 +716,7 @@ cleanlib:
             if DepsFileString == '':\r
                 continue\r
             OutputFile = self.ReplaceMacro(OutputFile)\r
-            self.ResultFileList.append('%s' % OutputFile)\r
+            self.ResultFileList.append(OutputFile)\r
             DepsFileString = self.ReplaceMacro(DepsFileString)\r
             self.BuildTargetList.append('%s : %s' % (OutputFile, DepsFileString))\r
             CmdString = ' '.join(FfsCmdList).strip()\r
@@ -793,7 +792,7 @@ cleanlib:
                         SingleCommandLength = len(SingleCommand)\r
                         SingleCommandList = SingleCommand.split()\r
                         if len(SingleCommandList) > 0:\r
-                            for Flag in FlagDict.keys():\r
+                            for Flag in FlagDict:\r
                                 if '$('+ Flag +')' in SingleCommandList[0]:\r
                                     Tool = Flag\r
                                     break\r
@@ -806,12 +805,12 @@ cleanlib:
                                     if 'FLAGS' not in self._AutoGenObject._BuildOption[Tool]:\r
                                         EdkLogger.error("build", AUTOGEN_ERROR, "%s_FLAGS doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))\r
                                     Str = self._AutoGenObject._BuildOption[Tool]['FLAGS']\r
-                                    for Option in self._AutoGenObject.BuildOption.keys():\r
+                                    for Option in self._AutoGenObject.BuildOption:\r
                                         for Attr in self._AutoGenObject.BuildOption[Option]:\r
                                             if Str.find(Option + '_' + Attr) != -1:\r
                                                 Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])\r
                                     while(Str.find('$(') != -1):\r
-                                        for macro in self._AutoGenObject.Macros.keys():\r
+                                        for macro in self._AutoGenObject.Macros:\r
                                             MacroName = '$('+ macro + ')'\r
                                             if (Str.find(MacroName) != -1):\r
                                                 Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])\r
@@ -823,12 +822,12 @@ cleanlib:
                                     SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList)\r
                                 elif item.find('$(') != -1:\r
                                     Str = item\r
-                                    for Option in self._AutoGenObject.BuildOption.keys():\r
+                                    for Option in self._AutoGenObject.BuildOption:\r
                                         for Attr in self._AutoGenObject.BuildOption[Option]:\r
                                             if Str.find(Option + '_' + Attr) != -1:\r
                                                 Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])\r
                                     while(Str.find('$(') != -1):\r
-                                        for macro in self._AutoGenObject.Macros.keys():\r
+                                        for macro in self._AutoGenObject.Macros:\r
                                             MacroName = '$('+ macro + ')'\r
                                             if (Str.find(MacroName) != -1):\r
                                                 Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])\r
@@ -841,19 +840,19 @@ cleanlib:
                                 FlagDict[Tool]['Value'] = True\r
 \r
                 # generate the response file content by combine the FLAGS and INC\r
-                for Flag in FlagDict.keys():\r
+                for Flag in FlagDict:\r
                     if FlagDict[Flag]['Value']:\r
                         Key = Flag + '_RESP'\r
                         RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP')\r
                         Value = self._AutoGenObject.BuildOption[Flag]['FLAGS']\r
                         for inc in self._AutoGenObject._IncludePathList:\r
                             Value += ' ' + IncPrefix + inc\r
-                        for Option in self._AutoGenObject.BuildOption.keys():\r
+                        for Option in self._AutoGenObject.BuildOption:\r
                             for Attr in self._AutoGenObject.BuildOption[Option]:\r
                                 if Value.find(Option + '_' + Attr) != -1:\r
                                     Value = Value.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])\r
                         while (Value.find('$(') != -1):\r
-                            for macro in self._AutoGenObject.Macros.keys():\r
+                            for macro in self._AutoGenObject.Macros:\r
                                 MacroName = '$('+ macro + ')'\r
                                 if (Value.find(MacroName) != -1):\r
                                     Value = Value.replace(MacroName, self._AutoGenObject.Macros[macro])\r
@@ -906,12 +905,12 @@ cleanlib:
             # skip non-C files\r
             if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
                 continue\r
-            elif DepSet == None:\r
+            elif DepSet is None:\r
                 DepSet = set(self.FileDependency[File])\r
             else:\r
                 DepSet &= set(self.FileDependency[File])\r
         # in case nothing in SourceFileList\r
-        if DepSet == None:\r
+        if DepSet is None:\r
             DepSet = set()\r
         #\r
         # Extract common files list in the dependency files\r
@@ -1031,7 +1030,7 @@ cleanlib:
             else:\r
                 try:\r
                     Fd = open(F.Path, 'r')\r
-                except BaseException, X:\r
+                except BaseException as X:\r
                     EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))\r
 \r
                 FileContent = Fd.read()\r
@@ -1516,7 +1515,7 @@ class TopLevelMakefile(BuildFile):
 \r
         # TRICK: for not generating GenFds call in makefile if no FDF file\r
         MacroList = []\r
-        if PlatformInfo.FdfFile != None and PlatformInfo.FdfFile != "":\r
+        if PlatformInfo.FdfFile is not None and PlatformInfo.FdfFile != "":\r
             FdfFileList = [PlatformInfo.FdfFile]\r
             # macros passed to GenFds\r
             MacroList.append('"%s=%s"' % ("EFI_SOURCE", GlobalData.gEfiSource.replace('\\', '\\\\')))\r