]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
Sync BaseTools Branch (version r2321) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index 54265952d03ba034d540168a6429e66603005161..51deb3890cae6b9e44dc057b9f4e9530dc97e5ce 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # build a platform or a module\r
 #\r
-#  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2011, 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
@@ -34,6 +34,7 @@ from Common import Misc as Utils
 from Common.TargetTxtClassObject import *\r
 from Common.ToolDefClassObject import *\r
 from Common.DataType import *\r
+from Common.BuildVersion import gBUILD_VERSION\r
 from AutoGen.AutoGen import *\r
 from Common.BuildToolError import *\r
 from Workspace.WorkspaceDatabase import *\r
@@ -46,7 +47,7 @@ import Common.EdkLogger
 import Common.GlobalData as GlobalData\r
 \r
 # Version and Copyright\r
-VersionNumber = "0.5"\r
+VersionNumber = "0.5" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + VersionNumber\r
 __copyright__ = "Copyright (c) 2007 - 2010, Intel Corporation  All rights reserved."\r
 \r
@@ -100,9 +101,10 @@ def CheckEnvVariable():
     os.environ["WORKSPACE"] = WorkspaceDir\r
 \r
     #\r
-    # Check EFI_SOURCE (R8 build convention). EDK_SOURCE will always point to ECP\r
+    # Check EFI_SOURCE (Edk build convention). EDK_SOURCE will always point to ECP\r
     #\r
-    os.environ["ECP_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
+    if "ECP_SOURCE" not in os.environ:\r
+        os.environ["ECP_SOURCE"] = os.path.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
@@ -121,13 +123,13 @@ def CheckEnvVariable():
     os.environ["EDK_TOOLS_PATH"] = os.path.normcase(os.environ["EDK_TOOLS_PATH"])\r
     \r
     if not os.path.exists(EcpSourceDir):\r
-        EdkLogger.verbose("ECP_SOURCE = %s doesn't exist. R8 modules could not be built." % EcpSourceDir)\r
+        EdkLogger.verbose("ECP_SOURCE = %s doesn't exist. Edk modules could not be built." % EcpSourceDir)\r
     elif ' ' in EcpSourceDir:\r
         EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in ECP_SOURCE path",\r
                         ExtraData=EcpSourceDir)\r
     if not os.path.exists(EdkSourceDir):\r
         if EdkSourceDir == EcpSourceDir:\r
-            EdkLogger.verbose("EDK_SOURCE = %s doesn't exist. R8 modules could not be built." % EdkSourceDir)\r
+            EdkLogger.verbose("EDK_SOURCE = %s doesn't exist. Edk modules could not be built." % EdkSourceDir)\r
         else:\r
             EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE does not exist",\r
                             ExtraData=EdkSourceDir)\r
@@ -136,7 +138,7 @@ def CheckEnvVariable():
                         ExtraData=EdkSourceDir)\r
     if not os.path.exists(EfiSourceDir):\r
         if EfiSourceDir == EcpSourceDir:\r
-            EdkLogger.verbose("EFI_SOURCE = %s doesn't exist. R8 modules could not be built." % EfiSourceDir)\r
+            EdkLogger.verbose("EFI_SOURCE = %s doesn't exist. Edk modules could not be built." % EfiSourceDir)\r
         else:\r
             EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE does not exist",\r
                             ExtraData=EfiSourceDir)\r
@@ -704,7 +706,7 @@ class Build():
     #   @param  SkuId               SKU id from command line\r
     #\r
     def __init__(self, Target, WorkspaceDir, Platform, Module, Arch, ToolChain,\r
-                 BuildTarget, FlashDefinition, FdList=[], FvList=[],\r
+                 BuildTarget, FlashDefinition, FdList=[], FvList=[], CapList=[],\r
                  MakefileType="nmake", SilentMode=False, ThreadNumber=2,\r
                  SkipAutoGen=False, Reparse=False, SkuId=None, \r
                  ReportFile=None, ReportType=None, UniFlag=None):\r
@@ -719,6 +721,7 @@ class Build():
         self.Fdf            = FlashDefinition\r
         self.FdList         = FdList\r
         self.FvList         = FvList\r
+        self.CapList        = CapList\r
         self.MakefileType   = MakefileType\r
         self.SilentMode     = SilentMode\r
         self.ThreadNumber   = ThreadNumber\r
@@ -744,13 +747,15 @@ class Build():
         self.LoadConfiguration()\r
         \r
         #\r
-        # @attention Treat $(TARGET) in meta data files as special macro when it has only one build target.\r
-        # This is not a complete support for $(TARGET) macro as it can only support one build target in ONE\r
-        # invocation of build command. However, it should cover the frequent usage model that $(TARGET) macro\r
-        # is used in DSC files to specify different libraries & PCD setting for debug/release build.\r
+        # @attention Treat $(TARGET)/$(TOOL_CHAIN_TAG) in meta data files as special macro when it has only one build target/toolchain.\r
+        # This is not a complete support for $(TARGET)/$(TOOL_CHAIN_TAG) macro as it can only support one build target/toolchain in ONE\r
+        # invocation of build command. However, it should cover the frequent usage model that $(TARGET)/$(TOOL_CHAIN_TAG) macro\r
+        # is used in DSC/FDF files to specify different libraries & PCD setting for debug/release build.\r
         #\r
         if len(self.BuildTargetList) == 1:\r
             self.Db._GlobalMacros.setdefault("TARGET", self.BuildTargetList[0])\r
+        if len(self.ToolChainList) == 1:   \r
+            self.Db._GlobalMacros.setdefault("TOOL_CHAIN_TAG", self.ToolChainList[0])\r
         \r
         self.InitBuild()\r
 \r
@@ -888,7 +893,7 @@ class Build():
                     self.LoadFixAddress = int (LoadFixAddressString, 16)\r
                 else:\r
                     self.LoadFixAddress = int (LoadFixAddressString)\r
-            except:
+            except:\r
                 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (LoadFixAddressString))\r
             if self.LoadFixAddress < 0:\r
                 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value %s" % (LoadFixAddressString))\r
@@ -908,6 +913,8 @@ class Build():
                 self.FvList = []\r
         else:\r
             FdfParserObj = FdfParser(str(self.Fdf))\r
+            for key in self.Db._GlobalMacros:\r
+                InputMacroDict[key] = self.Db._GlobalMacros[key]\r
             FdfParserObj.ParseFile()\r
             for fvname in self.FvList:\r
                 if fvname.upper() not in FdfParserObj.Profile.FvDict.keys():\r
@@ -974,6 +981,7 @@ class Build():
             if not self.SkipAutoGen or Target == 'genmake':\r
                 self.Progress.Start("Generating makefile")\r
                 AutoGenObject.CreateMakeFile(CreateDepsMakeFile)\r
+                AutoGenObject.CreateAsBuiltInf()\r
                 self.Progress.Stop("done!")\r
             if Target == "genmake":\r
                 return True\r
@@ -995,11 +1003,16 @@ 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
 \r
-    ## Rebase module image and Get function address for the inpug module list.\r
+    ## Rebase module image and Get function address for the input module list.\r
     #\r
     def _RebaseModule (self, MapBuffer, BaseAddress, ModuleList, AddrIsOffset = True, ModeIsSmm = False):\r
         if ModeIsSmm:\r
@@ -1007,8 +1020,8 @@ class Build():
         InfFileNameList = ModuleList.keys()\r
         #InfFileNameList.sort()\r
         for InfFile in InfFileNameList:\r
-            sys.stdout.write (".")
-            sys.stdout.flush()
+            sys.stdout.write (".")\r
+            sys.stdout.flush()\r
             ModuleInfo = ModuleList[InfFile]\r
             ModuleName = ModuleInfo.BaseName\r
             ModuleOutputImage = ModuleInfo.Image.FileName\r
@@ -1141,8 +1154,8 @@ class Build():
     ## Collect MAP information of all modules\r
     #\r
     def _CollectModuleMapBuffer (self, MapBuffer, ModuleList):\r
-        sys.stdout.write ("Generate Load Module At Fix Address Map")
-        sys.stdout.flush()
+        sys.stdout.write ("Generate Load Module At Fix Address Map")\r
+        sys.stdout.flush()\r
         PatchEfiImageList = []\r
         PeiModuleList  = {}\r
         BtModuleList   = {}\r
@@ -1187,11 +1200,11 @@ class Build():
                         SmmModuleList[Module.MetaFile] = ImageInfo\r
                         SmmSize += ImageInfo.Image.Size\r
                         if Module.ModuleType == 'DXE_SMM_DRIVER':\r
-                            PiSpecVersion = 0
-                            if 'PI_SPECIFICATION_VERSION' in Module.Module.Specification:
-                                PiSpecVersion = Module.Module.Specification['PI_SPECIFICATION_VERSION']
+                            PiSpecVersion = '0x00000000'\r
+                            if 'PI_SPECIFICATION_VERSION' in Module.Module.Specification:\r
+                                PiSpecVersion = Module.Module.Specification['PI_SPECIFICATION_VERSION']\r
                             # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver.\r
-                            if PiSpecVersion < 0x0001000A:\r
+                            if int(PiSpecVersion, 16) < 0x0001000A:\r
                                 BtModuleList[Module.MetaFile] = ImageInfo\r
                                 BtSize += ImageInfo.Image.Size\r
                     break\r
@@ -1245,7 +1258,7 @@ class Build():
             #\r
             # Get PCD offset in EFI image by GenPatchPcdTable function\r
             #\r
-            PcdTable = parsePcdInfoFromMapFile(EfiImageMap, EfiImage) 
+            PcdTable = parsePcdInfoFromMapFile(EfiImageMap, EfiImage) \r
             #\r
             # Patch real PCD value by PatchPcdValue tool\r
             #\r
@@ -1277,8 +1290,8 @@ class Build():
         self._RebaseModule (MapBuffer, RtBaseAddr, RtModuleList, TopMemoryAddress == 0)\r
         self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset = False, ModeIsSmm = True)\r
         MapBuffer.write('\n\n')\r
-        sys.stdout.write ("\n")
-        sys.stdout.flush()
+        sys.stdout.write ("\n")\r
+        sys.stdout.flush()\r
     \r
     ## Save platform Map file\r
     #\r
@@ -1291,10 +1304,10 @@ class Build():
         # Save address map into MAP file.\r
         #\r
         SaveFileOnChange(MapFilePath, MapBuffer.getvalue(), False)\r
-        MapBuffer.close()
-        if self.LoadFixAddress != 0:
-            sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" %(MapFilePath))
-        sys.stdout.flush()
+        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.flush()\r
 \r
     ## Build active platform for different build targets and different tool chains\r
     #\r
@@ -1313,6 +1326,7 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
+                        self.CapList,\r
                         self.SkuId,\r
                         self.UniFlag\r
                         )\r
@@ -1381,6 +1395,7 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
+                        self.CapList,\r
                         self.SkuId,\r
                         self.UniFlag\r
                         )\r
@@ -1459,6 +1474,7 @@ class Build():
                         self.Fdf,\r
                         self.FdList,\r
                         self.FvList,\r
+                        self.CapList,\r
                         self.SkuId,\r
                         self.UniFlag\r
                         )\r
@@ -1487,6 +1503,7 @@ class Build():
 \r
                             if not self.SkipAutoGen or self.Target == 'genmake':\r
                                 Ma.CreateMakeFile(True)\r
+                                Ma.CreateAsBuiltInf()\r
                             if self.Target == "genmake":\r
                                 continue\r
                         self.Progress.Stop("done!")\r
@@ -1694,8 +1711,8 @@ def MyOptionParser():
         help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")\r
     Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback,\r
         help="Build the module specified by the INF file name argument.")\r
-    Parser.add_option("-b", "--buildtarget", action="append", type="choice", choices=['DEBUG','RELEASE'], dest="BuildTarget",\r
-        help="BuildTarget is one of list: DEBUG, RELEASE, which overrides target.txt's TARGET definition. To specify more TARGET, please repeat this option.")\r
+    Parser.add_option("-b", "--buildtarget", action="append", type="choice", choices=['DEBUG','RELEASE','NOOPT'], dest="BuildTarget",\r
+        help="BuildTarget is one of list: DEBUG, RELEASE, NOOPT, which overrides target.txt's TARGET definition. To specify more TARGET, please repeat this option.")\r
     Parser.add_option("-t", "--tagname", action="append", type="string", dest="ToolChain",\r
         help="Using the Tool Chain Tagname to build the platform, overriding target.txt's TOOL_CHAIN_TAG definition.")\r
     Parser.add_option("-x", "--sku-id", action="callback", type="string", dest="SkuId", callback=SingleCheckCallback,\r
@@ -1710,7 +1727,8 @@ def MyOptionParser():
         help="The name of FD to be generated. The name must be from [FD] section in FDF file.")\r
     Parser.add_option("-i", "--fv-image", action="append", type="string", dest="FvImage", default=[],\r
         help="The name of FV to be generated. The name must be from [FV] section in FDF file.")\r
-\r
+    Parser.add_option("-C", "--capsule-image", action="append", type="string", dest="CapName", default=[],\r
+        help="The name of Capsule to be generated. The name must be from [Capsule] section in FDF file.")\r
     Parser.add_option("-u", "--skip-autogen", action="store_true", dest="SkipAutoGen", help="Skip AutoGen step.")\r
     Parser.add_option("-e", "--re-parse", action="store_true", dest="Reparse", help="Re-parse all meta-data files.")\r
 \r
@@ -1786,7 +1804,8 @@ def Main():
     else:\r
         GlobalData.gIsWindows = False\r
 \r
-    EdkLogger.quiet(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[%s]\n" % platform.platform())\r
+    EdkLogger.quiet("Build environment: %s" % platform.platform())\r
+    EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime()));\r
     ReturnCode = 0\r
     MyBuild = None\r
     try:\r
@@ -1855,7 +1874,7 @@ def Main():
 \r
         MyBuild = Build(Target, Workspace, Option.PlatformFile, Option.ModuleFile,\r
                         Option.TargetArch, Option.ToolChain, Option.BuildTarget,\r
-                        Option.FdfFile, Option.RomImage, Option.FvImage,\r
+                        Option.FdfFile, Option.RomImage, Option.FvImage, Option.CapName,\r
                         None, Option.SilentMode, Option.ThreadNumber,\r
                         Option.SkipAutoGen, Option.Reparse, Option.SkuId, \r
                         Option.ReportFile, Option.ReportType, Option.Flag)\r
@@ -1913,13 +1932,19 @@ def Main():
     else:\r
         Conclusion = "Failed"\r
     FinishTime = time.time()\r
-    BuildDuration = time.strftime("%M:%S", time.gmtime(int(round(FinishTime - StartTime))))\r
+    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
+    else:\r
+        BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration)\r
     if MyBuild != None:\r
-        MyBuild.BuildReport.GenerateReport(BuildDuration)\r
+        MyBuild.BuildReport.GenerateReport(BuildDurationStr)\r
         MyBuild.Db.Close()\r
     EdkLogger.SetLevel(EdkLogger.QUIET)\r
-    EdkLogger.quiet("\n- %s -\n%s [%s]" % (Conclusion, time.strftime("%H:%M:%S, %b.%d %Y", time.localtime()), BuildDuration))\r
-\r
+    EdkLogger.quiet("\n- %s -" % Conclusion)\r
+    EdkLogger.quiet(time.strftime("Build end time: %H:%M:%S, %b.%d %Y", time.localtime()))\r
+    EdkLogger.quiet("Build total time: %s\n" % BuildDurationStr)\r
     return ReturnCode\r
 \r
 if __name__ == '__main__':\r