]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
BaseTools: update the mail address for stack trace info
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index e463a57a911dc0b55d3cdd521949156fface0258..23ca76e82c121777c7455bb35c0ba7e4abc160ca 100644 (file)
@@ -1,7 +1,8 @@
 ## @file\r
 # build a platform or a module\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -40,6 +41,7 @@ from Common.BuildVersion import gBUILD_VERSION
 from AutoGen.AutoGen import *\r
 from Common.BuildToolError import *\r
 from Workspace.WorkspaceDatabase import *\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 from BuildReport import BuildReport\r
 from GenPatchPcdTable.GenPatchPcdTable import *\r
@@ -49,7 +51,7 @@ import Common.EdkLogger
 import Common.GlobalData as GlobalData\r
 \r
 # Version and Copyright\r
-VersionNumber = "0.51" + ' ' + gBUILD_VERSION\r
+VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + VersionNumber\r
 __copyright__ = "Copyright (c) 2007 - 2014, Intel Corporation  All rights reserved."\r
 \r
@@ -57,9 +59,8 @@ __copyright__ = "Copyright (c) 2007 - 2014, Intel Corporation  All rights reserv
 gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']\r
 \r
 ## build configuration file\r
-gBuildConfiguration = "Conf/target.txt"\r
-gBuildCacheDir = "Conf/.cache"\r
-gToolsDefinition = "Conf/tools_def.txt"\r
+gBuildConfiguration = "target.txt"\r
+gToolsDefinition = "tools_def.txt"\r
 \r
 TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$')\r
 TmpTableDict = {}\r
@@ -104,12 +105,16 @@ def CheckEnvVariable():
         EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in WORKSPACE path",\r
                         ExtraData=WorkspaceDir)\r
     os.environ["WORKSPACE"] = WorkspaceDir\r
+    \r
+    # set multiple workspace\r
+    PackagesPath = os.getenv("PACKAGES_PATH")\r
+    mws.setWs(WorkspaceDir, PackagesPath)\r
 \r
     #\r
     # Check EFI_SOURCE (Edk build convention). EDK_SOURCE will always point to ECP\r
     #\r
     if "ECP_SOURCE" not in os.environ:\r
-        os.environ["ECP_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
+        os.environ["ECP_SOURCE"] = mws.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
     if "EFI_SOURCE" not in os.environ:\r
         os.environ["EFI_SOURCE"] = os.environ["ECP_SOURCE"]\r
     if "EDK_SOURCE" not in os.environ:\r
@@ -151,16 +156,18 @@ def CheckEnvVariable():
         EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in EFI_SOURCE path",\r
                         ExtraData=EfiSourceDir)\r
 \r
-    # change absolute path to relative path to WORKSPACE\r
-    if EfiSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
-        EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE is not under WORKSPACE",\r
-                        ExtraData="WORKSPACE = %s\n    EFI_SOURCE = %s" % (WorkspaceDir, EfiSourceDir))\r
-    if EdkSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
-        EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE is not under WORKSPACE",\r
-                        ExtraData="WORKSPACE = %s\n    EDK_SOURCE = %s" % (WorkspaceDir, EdkSourceDir))\r
-    if EcpSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
-        EdkLogger.error("build", PARAMETER_INVALID, "ECP_SOURCE is not under WORKSPACE",\r
-                        ExtraData="WORKSPACE = %s\n    ECP_SOURCE = %s" % (WorkspaceDir, EcpSourceDir))\r
+    # check those variables on single workspace case\r
+    if not PackagesPath:\r
+        # change absolute path to relative path to WORKSPACE\r
+        if EfiSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
+            EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE is not under WORKSPACE",\r
+                            ExtraData="WORKSPACE = %s\n    EFI_SOURCE = %s" % (WorkspaceDir, EfiSourceDir))\r
+        if EdkSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
+            EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE is not under WORKSPACE",\r
+                            ExtraData="WORKSPACE = %s\n    EDK_SOURCE = %s" % (WorkspaceDir, EdkSourceDir))\r
+        if EcpSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
+            EdkLogger.error("build", PARAMETER_INVALID, "ECP_SOURCE is not under WORKSPACE",\r
+                            ExtraData="WORKSPACE = %s\n    ECP_SOURCE = %s" % (WorkspaceDir, EcpSourceDir))\r
 \r
     # check EDK_TOOLS_PATH\r
     if "EDK_TOOLS_PATH" not in os.environ:\r
@@ -182,7 +189,7 @@ def CheckEnvVariable():
     GlobalData.gGlobalDefines["EDK_SOURCE"] = EdkSourceDir\r
     GlobalData.gGlobalDefines["ECP_SOURCE"] = EcpSourceDir\r
     GlobalData.gGlobalDefines["EDK_TOOLS_PATH"] = os.environ["EDK_TOOLS_PATH"]\r
-\r
+    \r
 ## Get normalized file path\r
 #\r
 # Convert the path to be local format, and remove the WORKSPACE path at the\r
@@ -198,11 +205,12 @@ def NormFile(FilePath, Workspace):
     if os.path.isabs(FilePath):\r
         FileFullPath = os.path.normpath(FilePath)\r
     else:\r
-        FileFullPath = os.path.normpath(os.path.join(Workspace, FilePath))\r
+        FileFullPath = os.path.normpath(mws.join(Workspace, FilePath))\r
+        Workspace = mws.getWs(Workspace, FilePath)\r
 \r
     # check if the file path exists or not\r
     if not os.path.isfile(FileFullPath):\r
-        EdkLogger.error("build", FILE_NOT_FOUND, ExtraData="\t%s (Please give file in absolute path or relative to WORKSPACE)"  % FileFullPath)\r
+        EdkLogger.error("build", FILE_NOT_FOUND, ExtraData="\t%s (Please give file in absolute path or relative to WORKSPACE)" % FileFullPath)\r
 \r
     # remove workspace directory from the beginning part of the file path\r
     if Workspace[-1] in ["\\", "/"]:\r
@@ -279,6 +287,7 @@ def LaunchCommand(Command, WorkingDir):
         Proc.wait()\r
     except: # in case of aborting\r
         # terminate the threads redirecting the program output\r
+        EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
         if EndOfProcedure != None:\r
             EndOfProcedure.set()\r
         if Proc == None:\r
@@ -630,7 +639,8 @@ class BuildTask:
     #\r
     def AddDependency(self, Dependency):\r
         for Dep in Dependency:\r
-            self.DependencyList.append(BuildTask.New(Dep))    # BuildTask list\r
+            if not Dep.BuildObject.IsBinaryModule:\r
+                self.DependencyList.append(BuildTask.New(Dep))    # BuildTask list\r
 \r
     ## The thread wrapper of LaunchCommand function\r
     #\r
@@ -732,16 +742,34 @@ class Build():
         self.SkipAutoGen    = BuildOptions.SkipAutoGen\r
         self.Reparse        = BuildOptions.Reparse\r
         self.SkuId          = BuildOptions.SkuId\r
+        self.ConfDirectory = BuildOptions.ConfDirectory\r
         self.SpawnMode      = True\r
         self.BuildReport    = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)\r
         self.TargetTxt      = TargetTxtClassObject()\r
         self.ToolDef        = ToolDefClassObject()\r
+        #Set global flag for build mode\r
+        GlobalData.gIgnoreSource = BuildOptions.IgnoreSources\r
+\r
+        if self.ConfDirectory:\r
+            # Get alternate Conf location, if it is absolute, then just use the absolute directory name\r
+            ConfDirectoryPath = os.path.normpath(self.ConfDirectory)\r
+\r
+            if not os.path.isabs(ConfDirectoryPath):\r
+                # Since alternate directory name is not absolute, the alternate directory is located within the WORKSPACE\r
+                # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf\r
+                ConfDirectoryPath = mws.join(self.WorkspaceDir, ConfDirectoryPath)\r
+        else:\r
+            # Get standard WORKSPACE/Conf use the absolute path to the WORKSPACE/Conf\r
+            ConfDirectoryPath = mws.join(self.WorkspaceDir, 'Conf')\r
+        GlobalData.gConfDirectory = ConfDirectoryPath\r
+        GlobalData.gDatabasePath = os.path.normpath(os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath))\r
+\r
         if BuildOptions.DisableCache:\r
             self.Db         = WorkspaceDatabase(":memory:")\r
         else:\r
-            self.Db         = WorkspaceDatabase(None, self.Reparse)\r
-        self.BuildDatabase  = self.Db.BuildObject\r
-        self.Platform       = None\r
+            self.Db = WorkspaceDatabase(GlobalData.gDatabasePath, self.Reparse)\r
+        self.BuildDatabase = self.Db.BuildObject\r
+        self.Platform = None\r
         self.LoadFixAddress = 0\r
         self.UniFlag        = BuildOptions.Flag\r
         self.BuildModules = []\r
@@ -753,10 +781,16 @@ class Build():
 \r
         # print current build environment and configuration\r
         EdkLogger.quiet("%-16s = %s" % ("WORKSPACE", os.environ["WORKSPACE"]))\r
+        if "PACKAGES_PATH" in os.environ:\r
+            # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env. \r
+            EdkLogger.quiet("%-16s = %s" % ("PACKAGES_PATH", os.path.normcase(os.path.normpath(os.environ["PACKAGES_PATH"]))))\r
         EdkLogger.quiet("%-16s = %s" % ("ECP_SOURCE", os.environ["ECP_SOURCE"]))\r
         EdkLogger.quiet("%-16s = %s" % ("EDK_SOURCE", os.environ["EDK_SOURCE"]))\r
         EdkLogger.quiet("%-16s = %s" % ("EFI_SOURCE", os.environ["EFI_SOURCE"]))\r
         EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"]))\r
+        if "EDK_TOOLS_BIN" in os.environ:\r
+            # Print the same path style with WORKSPACE env. \r
+            EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"]))))\r
 \r
         EdkLogger.info("")\r
 \r
@@ -770,14 +804,14 @@ class Build():
         #\r
         # Check target.txt and tools_def.txt and Init them\r
         #\r
-        BuildConfigurationFile = os.path.normpath(os.path.join(self.WorkspaceDir, gBuildConfiguration))\r
+        BuildConfigurationFile = os.path.normpath(os.path.join(GlobalData.gConfDirectory, gBuildConfiguration))\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             StatusCode = self.TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)\r
 \r
             ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
             if ToolDefinitionFile == '':\r
                 ToolDefinitionFile = gToolsDefinition\r
-            ToolDefinitionFile = os.path.normpath(os.path.join(self.WorkspaceDir, ToolDefinitionFile))\r
+                ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))\r
             if os.path.isfile(ToolDefinitionFile) == True:\r
                 StatusCode = self.ToolDef.LoadToolDefFile(ToolDefinitionFile)\r
             else:\r
@@ -913,14 +947,9 @@ class Build():
 \r
         makefile = GenMake.BuildFile(AutoGenObject)._FILE_NAME_[GenMake.gMakeType]\r
 \r
-        # genfds\r
-        if Target == 'fds':\r
-            LaunchCommand(AutoGenObject.GenFdsCommand, AutoGenObject.MakeFileDir)\r
-            return True\r
-\r
         # run\r
         if Target == 'run':\r
-            RunDir = os.path.normpath(os.path.join(AutoGenObject.BuildDir, 'IA32'))\r
+            RunDir = os.path.normpath(os.path.join(AutoGenObject.BuildDir, GlobalData.gGlobalDefines['ARCH']))\r
             Command = '.\SecMain'\r
             os.chdir(RunDir)\r
             LaunchCommand(Command, RunDir)\r
@@ -979,11 +1008,6 @@ class Build():
             try:\r
                 #os.rmdir(AutoGenObject.BuildDir)\r
                 RemoveDirectory(AutoGenObject.BuildDir, True)\r
-                #\r
-                # First should close DB.\r
-                #\r
-                self.Db.Close()\r
-                RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True)\r
             except WindowsError, X:\r
                 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))\r
         return True\r
@@ -1041,6 +1065,14 @@ class Build():
                                 (AutoGenObject.BuildTarget, AutoGenObject.ToolChain, AutoGenObject.Arch),\r
                             ExtraData=str(AutoGenObject))\r
 \r
+        # build modules\r
+        if BuildModule:\r
+            if Target != 'fds':\r
+                BuildCommand = BuildCommand + [Target]\r
+            LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)\r
+            self.CreateAsBuiltInf()\r
+            return True\r
+\r
         # genfds\r
         if Target == 'fds':\r
             LaunchCommand(AutoGenObject.GenFdsCommand, AutoGenObject.MakeFileDir)\r
@@ -1048,19 +1080,12 @@ class Build():
 \r
         # run\r
         if Target == 'run':\r
-            RunDir = os.path.normpath(os.path.join(AutoGenObject.BuildDir, 'IA32'))\r
+            RunDir = os.path.normpath(os.path.join(AutoGenObject.BuildDir, GlobalData.gGlobalDefines['ARCH']))\r
             Command = '.\SecMain'\r
             os.chdir(RunDir)\r
             LaunchCommand(Command, RunDir)\r
             return True\r
 \r
-        # build modules\r
-        BuildCommand = BuildCommand + [Target]\r
-        if BuildModule:\r
-            LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)\r
-            self.CreateAsBuiltInf()\r
-            return True\r
-\r
         # build library\r
         if Target == 'libraries':\r
             pass\r
@@ -1073,11 +1098,6 @@ class Build():
             try:\r
                 #os.rmdir(AutoGenObject.BuildDir)\r
                 RemoveDirectory(AutoGenObject.BuildDir, True)\r
-                #\r
-                # First should close DB.\r
-                #\r
-                self.Db.Close()\r
-                RemoveDirectory(gBuildCacheDir, True)\r
             except WindowsError, X:\r
                 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))\r
         return True\r
@@ -1103,13 +1123,13 @@ class Build():
                 # Update Image to new BaseAddress by GenFw tool\r
                 #\r
                 LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
-                LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleDebugImage],  ModuleInfo.DebugDir)\r
+                LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)\r
             else:\r
                 #\r
                 # Set new address to the section header only for SMM driver.\r
                 #\r
                 LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
-                LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage],  ModuleInfo.DebugDir)\r
+                LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)\r
             #\r
             # Collect funtion address from Map file\r
             #\r
@@ -1117,7 +1137,7 @@ class Build():
             FunctionList = []\r
             if os.path.exists(ImageMapTable):\r
                 OrigImageBaseAddress = 0\r
-                ImageMap = open (ImageMapTable, 'r')\r
+                ImageMap = open(ImageMapTable, 'r')\r
                 for LinStr in ImageMap:\r
                     if len (LinStr.strip()) == 0:\r
                         continue\r
@@ -1130,7 +1150,7 @@ class Build():
 \r
                     StrList = LinStr.split()\r
                     if len (StrList) > 4:\r
-                        if StrList[3] == 'f' or StrList[3] =='F':\r
+                        if StrList[3] == 'f' or StrList[3] == 'F':\r
                             Name = StrList[1]\r
                             RelativeAddress = int (StrList[2], 16) - OrigImageBaseAddress\r
                             FunctionList.append ((Name, RelativeAddress))\r
@@ -1254,7 +1274,7 @@ class Build():
                     if not ImageClass.IsValid:\r
                         EdkLogger.error("build", FILE_PARSE_FAILURE, ExtraData=ImageClass.ErrorInfo)\r
                     ImageInfo = PeImageInfo(Module.Name, Module.Guid, Module.Arch, Module.OutputDir, Module.DebugDir, ImageClass)\r
-                    if Module.ModuleType in ['PEI_CORE', 'PEIM', 'COMBINED_PEIM_DRIVER','PIC_PEIM', 'RELOCATABLE_PEIM', 'DXE_CORE']:\r
+                    if Module.ModuleType in ['PEI_CORE', 'PEIM', 'COMBINED_PEIM_DRIVER', 'PIC_PEIM', 'RELOCATABLE_PEIM', 'DXE_CORE']:\r
                         PeiModuleList[Module.MetaFile] = ImageInfo\r
                         PeiSize += ImageInfo.Image.Size\r
                     elif Module.ModuleType in ['BS_DRIVER', 'DXE_DRIVER', 'UEFI_DRIVER']:\r
@@ -1335,21 +1355,21 @@ class Build():
             for PcdInfo in PcdTable:\r
                 ReturnValue = 0\r
                 if PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE:\r
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize/0x1000))\r
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize / 0x1000))\r
                 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE:\r
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize/0x1000))\r
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize / 0x1000))\r
                 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE:\r
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize/0x1000))\r
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize / 0x1000))\r
                 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0:\r
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize/0x1000))\r
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize / 0x1000))\r
                 if ReturnValue != 0:\r
                     EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD value failed", ExtraData=ErrorInfo)\r
 \r
-        MapBuffer.write('PEI_CODE_PAGE_NUMBER      = 0x%x\n' % (PeiSize/0x1000))\r
-        MapBuffer.write('BOOT_CODE_PAGE_NUMBER     = 0x%x\n' % (BtSize/0x1000))\r
-        MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER  = 0x%x\n' % (RtSize/0x1000))\r
+        MapBuffer.write('PEI_CODE_PAGE_NUMBER      = 0x%x\n' % (PeiSize / 0x1000))\r
+        MapBuffer.write('BOOT_CODE_PAGE_NUMBER     = 0x%x\n' % (BtSize / 0x1000))\r
+        MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER  = 0x%x\n' % (RtSize / 0x1000))\r
         if len (SmmModuleList) > 0:\r
-            MapBuffer.write('SMM_CODE_PAGE_NUMBER      = 0x%x\n' % (SmmSize/0x1000))\r
+            MapBuffer.write('SMM_CODE_PAGE_NUMBER      = 0x%x\n' % (SmmSize / 0x1000))\r
 \r
         PeiBaseAddr = TopMemoryAddress - RtSize - BtSize\r
         BtBaseAddr  = TopMemoryAddress - RtSize\r
@@ -1358,7 +1378,7 @@ class Build():
         self._RebaseModule (MapBuffer, PeiBaseAddr, PeiModuleList, TopMemoryAddress == 0)\r
         self._RebaseModule (MapBuffer, BtBaseAddr, BtModuleList, TopMemoryAddress == 0)\r
         self._RebaseModule (MapBuffer, RtBaseAddr, RtModuleList, TopMemoryAddress == 0)\r
-        self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset = False, ModeIsSmm = True)\r
+        self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset=False, ModeIsSmm=True)\r
         MapBuffer.write('\n\n')\r
         sys.stdout.write ("\n")\r
         sys.stdout.flush()\r
@@ -1376,7 +1396,7 @@ class Build():
         SaveFileOnChange(MapFilePath, MapBuffer.getvalue(), False)\r
         MapBuffer.close()\r
         if self.LoadFixAddress != 0:\r
-            sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" %(MapFilePath))\r
+            sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" % (MapFilePath))\r
         sys.stdout.flush()\r
 \r
     ## Build active platform for different build targets and different tool chains\r
@@ -1445,12 +1465,11 @@ class Build():
                         # Rebase module to the preferred memory address before GenFds\r
                         #\r
                         self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
-                        if self.Fdf:\r
-                            #\r
-                            # create FDS again for the updated EFI image\r
-                            #\r
-                            self._Build("fds", Wa)\r
                     if self.Fdf:\r
+                        #\r
+                        # create FDS again for the updated EFI image\r
+                        #\r
+                        self._Build("fds", Wa)\r
                         #\r
                         # Create MAP file for all platform FVs after GenFds.\r
                         #\r
@@ -1511,7 +1530,7 @@ class Build():
                                 BUILD_ERROR,\r
                                 "Module for [%s] is not a component of active platform."\\r
                                 " Please make sure that the ARCH and inf file path are"\\r
-                                " given in the same as in [%s]" %\\r
+                                " given in the same as in [%s]" % \\r
                                     (', '.join(Wa.ArchList), self.PlatformFile),\r
                                 ExtraData=self.ModuleFile\r
                                 )\r
@@ -1540,10 +1559,10 @@ class Build():
                         # Rebase module to the preferred memory address before GenFds\r
                         #\r
                         self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
-                        #\r
-                        # create FDS again for the updated EFI image\r
-                        #\r
-                        self._Build("fds", Wa)\r
+                    #\r
+                    # create FDS again for the updated EFI image\r
+                    #\r
+                    self._Build("fds", Wa)\r
                     #\r
                     # Create MAP file for all platform FVs after GenFds.\r
                     #\r
@@ -1787,6 +1806,10 @@ class Build():
             self.SpawnMode = False\r
             self._BuildModule()\r
 \r
+        if self.Target == 'cleanall':\r
+            self.Db.Close()\r
+            RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True)\r
+\r
     def CreateAsBuiltInf(self):\r
         for Module in self.BuildModules:\r
             Module.CreateAsBuiltInf()\r
@@ -1802,19 +1825,19 @@ class Build():
         EdkLogger.SetLevel(OldLogLevel)\r
 \r
     def DumpBuildData(self):\r
-        CacheDirectory = os.path.join(self.WorkspaceDir, gBuildCacheDir)\r
+        CacheDirectory = os.path.dirname(GlobalData.gDatabasePath)\r
         Utils.CreateDirectory(CacheDirectory)\r
         Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache"))\r
         Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase"))\r
 \r
     def RestoreBuildData(self):\r
-        FilePath = os.path.join(self.WorkspaceDir, gBuildCacheDir, "gFileTimeStampCache")\r
+        FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gFileTimeStampCache")\r
         if Utils.gFileTimeStampCache == {} and os.path.isfile(FilePath):\r
             Utils.gFileTimeStampCache = Utils.DataRestore(FilePath)\r
             if Utils.gFileTimeStampCache == None:\r
                 Utils.gFileTimeStampCache = {}\r
 \r
-        FilePath = os.path.join(self.WorkspaceDir, gBuildCacheDir, "gDependencyDatabase")\r
+        FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gDependencyDatabase")\r
         if Utils.gDependencyDatabase == {} and os.path.isfile(FilePath):\r
             Utils.gDependencyDatabase = Utils.DataRestore(FilePath)\r
             if Utils.gDependencyDatabase == None:\r
@@ -1852,8 +1875,8 @@ def SingleCheckCallback(option, opt_str, value, parser):
 #   @retval Args  Target of build command\r
 #\r
 def MyOptionParser():\r
-    Parser = OptionParser(description=__copyright__,version=__version__,prog="build.exe",usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]")\r
-    Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32','X64','IPF','EBC','ARM', 'AARCH64'], dest="TargetArch",\r
+    Parser = OptionParser(description=__copyright__, version=__version__, prog="build.exe", usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]")\r
+    Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'IPF', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch",\r
         help="ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 or EBC, which overrides target.txt's TARGET_ARCH definition. To specify more archs, please repeat this option.")\r
     Parser.add_option("-p", "--platform", action="callback", type="string", dest="PlatformFile", callback=SingleCheckCallback,\r
         help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")\r
@@ -1895,7 +1918,7 @@ def MyOptionParser():
     Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")\r
 \r
     Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.")\r
-    Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD','LIBRARY','FLASH','DEPEX','BUILD_FLAGS','FIXED_ADDRESS', 'EXECUTION_ORDER'], dest="ReportType", default=[],\r
+    Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', 'FIXED_ADDRESS', 'EXECUTION_ORDER'], dest="ReportType", default=[],\r
         help="Flags that control the type of build report to generate.  Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, EXECUTION_ORDER].  "\\r
              "To specify more than one flag, repeat this option on the command line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS]")\r
     Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",\r
@@ -1903,8 +1926,11 @@ def MyOptionParser():
              "This option can also be specified by setting *_*_*_BUILD_FLAGS in [BuildOptions] section of platform DSC. If they are both specified, this value "\\r
              "will override the setting in [BuildOptions] section of platform DSC.")\r
     Parser.add_option("-N", "--no-cache", action="store_true", dest="DisableCache", default=False, help="Disable build cache mechanism")\r
+    Parser.add_option("--conf", action="store", type="string", dest="ConfDirectory", help="Specify the customized Conf directory.")\r
+    Parser.add_option("--check-usage", action="store_true", dest="CheckUsage", default=False, help="Check usage content of entries listed in INF file.")\r
+    Parser.add_option("--ignore-sources", action="store_true", dest="IgnoreSources", default=False, help="Focus to a binary build and ignore all source files")\r
 \r
-    (Opt, Args)=Parser.parse_args()\r
+    (Opt, Args) = Parser.parse_args()\r
     return (Opt, Args)\r
 \r
 ## Tool entrance method\r
@@ -1954,18 +1980,19 @@ def Main():
     EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime()));\r
     ReturnCode = 0\r
     MyBuild = None\r
+    BuildError = True\r
     try:\r
         if len(Target) == 0:\r
             Target = "all"\r
         elif len(Target) >= 2:\r
             EdkLogger.error("build", OPTION_NOT_SUPPORTED, "More than one targets are not supported.",\r
-                            ExtraData="Please select one of: %s" %(' '.join(gSupportedTarget)))\r
+                            ExtraData="Please select one of: %s" % (' '.join(gSupportedTarget)))\r
         else:\r
             Target = Target[0].lower()\r
 \r
         if Target not in gSupportedTarget:\r
             EdkLogger.error("build", OPTION_NOT_SUPPORTED, "Not supported target [%s]." % Target,\r
-                            ExtraData="Please select one of: %s" %(' '.join(gSupportedTarget)))\r
+                            ExtraData="Please select one of: %s" % (' '.join(gSupportedTarget)))\r
 \r
         #\r
         # Check environment variable: EDK_TOOLS_PATH, WORKSPACE, PATH\r
@@ -2024,6 +2051,10 @@ def Main():
             SqlCommand = """drop table IF EXISTS %s""" % TmpTableName\r
             TmpTableDict[TmpTableName].execute(SqlCommand)\r
         #MyBuild.DumpBuildData()\r
+        #\r
+        # All job done, no error found and no exception raised\r
+        #\r
+        BuildError = False\r
     except FatalError, X:\r
         if MyBuild != None:\r
             # for multi-thread build exits safely\r
@@ -2039,7 +2070,7 @@ def Main():
         if Option != None and Option.debug != None:\r
             EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
         else:\r
-            EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError = False)\r
+            EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False)\r
         ReturnCode = FORMAT_INVALID\r
     except KeyboardInterrupt:\r
         ReturnCode = ABORT_ERROR\r
@@ -2061,13 +2092,14 @@ def Main():
                     "\nbuild",\r
                     CODE_ERROR,\r
                     "Unknown fatal error when processing [%s]" % MetaFile,\r
-                    ExtraData="\n(Please send email to edk2-buildtools-devel@lists.sourceforge.net for help, attaching following call stack trace!)\n",\r
+                    ExtraData="\n(Please send email to edk2-devel@lists.01.org for help, attaching following call stack trace!)\n",\r
                     RaiseError=False\r
                     )\r
         EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
         ReturnCode = CODE_ERROR\r
     finally:\r
         Utils.Progressor.Abort()\r
+        Utils.ClearDuplicatedInf()\r
 \r
     if ReturnCode == 0:\r
         Conclusion = "Done"\r
@@ -2079,11 +2111,12 @@ def Main():
     BuildDuration = time.gmtime(int(round(FinishTime - StartTime)))\r
     BuildDurationStr = ""\r
     if BuildDuration.tm_yday > 1:\r
-        BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration) + ", %d day(s)"%(BuildDuration.tm_yday - 1)\r
+        BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration) + ", %d day(s)" % (BuildDuration.tm_yday - 1)\r
     else:\r
         BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration)\r
     if MyBuild != None:\r
-        MyBuild.BuildReport.GenerateReport(BuildDurationStr)\r
+        if not BuildError:\r
+            MyBuild.BuildReport.GenerateReport(BuildDurationStr)\r
         MyBuild.Db.Close()\r
     EdkLogger.SetLevel(EdkLogger.QUIET)\r
     EdkLogger.quiet("\n- %s -" % Conclusion)\r