]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools: Refactor python except statements
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenMake.py
index 7d3374a493734f661e111acb6c53692618b13587..48b66c570e0a86d6ae0612f799e97aca7792639e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Create makefile for MS nmake and GNU make\r
 #\r
-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -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
@@ -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,21 +792,25 @@ 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
                         if Tool:\r
+                            if 'PATH' not in self._AutoGenObject._BuildOption[Tool]:\r
+                                EdkLogger.error("build", AUTOGEN_ERROR, "%s_PATH doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))\r
                             SingleCommandLength += len(self._AutoGenObject._BuildOption[Tool]['PATH'])\r
                             for item in SingleCommandList[1:]:\r
                                 if FlagDict[Tool]['Macro'] in item:\r
+                                    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
@@ -819,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
@@ -837,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
@@ -902,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
@@ -1027,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
@@ -1512,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
@@ -1547,18 +1550,15 @@ class TopLevelMakefile(BuildFile):
         if GlobalData.gIgnoreSource:\r
             ExtraOption += " --ignore-sources"\r
 \r
-        if GlobalData.BuildOptionPcd:\r
-            for index, option in enumerate(GlobalData.gCommand):\r
-                if "--pcd" == option and GlobalData.gCommand[index+1]:\r
-                    pcdName, pcdValue = GlobalData.gCommand[index+1].split('=')\r
-                    if pcdValue.startswith('H'):\r
-                        pcdValue = 'H' + '"' + pcdValue[1:] + '"'\r
-                        ExtraOption += " --pcd " + pcdName + '=' + pcdValue\r
-                    elif pcdValue.startswith('L'):\r
-                        pcdValue = 'L' + '"' + pcdValue[1:] + '"'\r
-                        ExtraOption += " --pcd " + pcdName + '=' + pcdValue\r
-                    else:\r
-                        ExtraOption += " --pcd " + GlobalData.gCommand[index+1]\r
+        for pcd in GlobalData.BuildOptionPcd:\r
+            if pcd[2]:\r
+                pcdname = '.'.join(pcd[0:3])\r
+            else:\r
+                pcdname = '.'.join(pcd[0:2])\r
+            if pcd[3].startswith('{'):\r
+                ExtraOption += " --pcd " + pcdname + '=' + 'H' + '"' + pcd[3] + '"'\r
+            else:\r
+                ExtraOption += " --pcd " + pcdname + '=' + pcd[3]\r
 \r
         MakefileName = self._FILE_NAME_[self._FileType]\r
         SubBuildCommandList = []\r