1) Added single FD/FV build
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 13 Sep 2007 09:13:56 +0000 (09:13 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 13 Sep 2007 09:13:56 +0000 (09:13 +0000)
2) Implemented MACRO in tools_def.txt
3) Added library without library class support
4) Fixed the issue in Trim tool which zero file will be generated if the trimmed file has not line directive

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@729 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/AutoGen/AutoGen.py
Source/Python/AutoGen/BuildInfo.py
Source/Python/AutoGen/GenC.py
Source/Python/AutoGen/GenDepex.py
Source/Python/AutoGen/GenMake.py
Source/Python/Common/EdkIIWorkspaceBuild.py
Source/Python/Common/Misc.py
Source/Python/Common/ToolDefClassObject.py
Source/Python/Trim/Trim.py
Source/Python/build/build.py

index 70cd3c9..e4ab527 100755 (executable)
@@ -18,6 +18,8 @@ import os
 import re\r
 import os.path as path\r
 import imp\r
+from optparse import OptionParser\r
+from optparse import make_option\r
 \r
 import Common.EdkLogger\r
 import GenC\r
@@ -92,6 +94,11 @@ gIncludeFlag = {"MSFT" : "/I", "GCC" : "-I", "INTEL" : "-I"}
 ## Build rule configuration file\r
 gBuildRuleFile = 'Conf/build_rule.txt'\r
 \r
+## default file name for AutoGen\r
+gAutoGenCodeFileName = "AutoGen.c"\r
+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
@@ -310,7 +317,7 @@ class AutoGen(object):
         Info.BuildDir = path.join(Info.OutputDir, self.BuildTarget + "_" + self.ToolChain)\r
         Info.MakefileDir = Info.BuildDir\r
         if Platform.FlashDefinition != "":\r
-            Info.FdfFileList.append(path.join(gWorkspaceDir, Platform.FlashDefinition))\r
+            Info.FdfFile= path.join(gWorkspaceDir, Platform.FlashDefinition)\r
 \r
         Info.DynamicPcdList = self.GetDynamicPcdList(Platform, Arch)\r
         Info.PcdTokenNumber = self.GeneratePcdTokenNumber(Platform, Info.DynamicPcdList)\r
@@ -318,6 +325,8 @@ class AutoGen(object):
 \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
@@ -326,6 +335,12 @@ class AutoGen(object):
                 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
 \r
@@ -389,16 +404,11 @@ class AutoGen(object):
         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
-            Key = "%s_NAME" % KeyBaseString\r
-            if Key not in ToolDefinition:\r
-                continue\r
-            Name = ToolDefinition[Key]\r
 \r
             Key = "%s_PATH" % KeyBaseString\r
-            if Key in ToolDefinition:\r
-                Path = ToolDefinition[Key]\r
-            else:\r
-                Path = ""\r
+            if Key not in ToolDefinition:\r
+                continue\r
+            Path = ToolDefinition[Key]\r
 \r
             Key = "%s_FAMILY" % KeyBaseString\r
             if Key in ToolDefinition:\r
@@ -412,19 +422,13 @@ class AutoGen(object):
             else:\r
                 Option = ""\r
 \r
-            Key = "%s_DPATH" % KeyBaseString\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 = "%s_SPATH" % KeyBaseString\r
-            if Key in ToolDefinition:\r
-                Lib = ToolDefinition[Key]\r
-            else:\r
-                Lib = ""\r
-\r
             Key = KeyBaseString + "_OUTPUT"\r
             if Key in ToolDefinition:\r
                 OutputFlag = ToolDefinition[Key]\r
@@ -437,9 +441,8 @@ class AutoGen(object):
 \r
             InputFlag = gIncludeFlag[Family]\r
 \r
-            Info.ToolPath[Tool] = os.path.join(Path, Name)\r
+            Info.ToolPath[Tool] = Path\r
             Info.ToolDynamicLib[Tool] = Dll\r
-            Info.ToolStaticLib[Tool] = Lib\r
             Info.ToolChainFamily[Tool] = Family\r
             Info.DefaultToolOption[Tool] = Option\r
             Info.OutputFlag[Tool] = OutputFlag\r
@@ -528,8 +531,6 @@ class AutoGen(object):
                 EdkLogger.warn("No rule or command defined for building [%s], ignore file [%s]" % (FileType, SourceFile))\r
                 continue\r
 \r
-            if Ext == ".dxs":\r
-                print "###", SourceFile, FileType, RuleObject\r
             BuildFileList.append([SourceFile, FileType, RuleObject])\r
 \r
         return BuildFileList\r
@@ -580,7 +581,6 @@ class AutoGen(object):
             FileList.append("AutoGen.c")\r
         if self.AutoGenH.String != "":\r
             FileList.append("AutoGen.h")\r
-            #print self.AutoGenH.String\r
         return FileList\r
 \r
     def GetSortedLibraryList(self):\r
@@ -781,17 +781,23 @@ class AutoGen(object):
                 LibraryAutoGen.CreateMakefile()\r
 \r
             Makefile = GenMake.Makefile(self.BuildInfo, myBuildOption)\r
-            F = Makefile.Generate()\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
-            EdkLogger.info("Generated [%s] for module %s [%s]" % (path.basename(F), self.BuildInfo.Name, self.BuildInfo.Arch))\r
-            return F\r
+            return\r
 \r
         Makefile = GenMake.Makefile(self.BuildInfo, myBuildOption)\r
-        F = Makefile.Generate()\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
+        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.info("Generated [%s] for platform %s\n" % (path.basename(F), self.BuildInfo[self.Arch[0]].Name))\r
-\r
-        return F\r
 \r
     def CreateAutoGenFile(self, FilePath=None):\r
         if self.IsAutoGenCodeCreated:\r
@@ -809,7 +815,7 @@ class AutoGen(object):
                     else:\r
                         ModuleAutoGen = gAutoGenDatabase[Key]\r
                     ModuleAutoGen.CreateAutoGenFile()\r
-            print\r
+            EdkLogger.info("")\r
         else:\r
             PlatformInfo = self.BuildInfo.PlatformInfo\r
             if not self.BuildInfo.IsLibrary and self not in PlatformInfo.ModuleAutoGenList:\r
@@ -829,108 +835,133 @@ class AutoGen(object):
                     self.BuildInfo.LibraryAutoGenList.append(LibraryAutoGen)\r
                 LibraryAutoGen.CreateAutoGenFile()\r
 \r
-            AutoGenList = GenC.Generate(os.path.join(self.BuildInfo.WorkspaceDir, self.BuildInfo.DebugDir),\r
-                                        self.AutoGenC, self.AutoGenH)\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.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
 \r
             if self.BuildInfo.DepexList != []:\r
-                dpx = GenDepex.DependencyExpression(self.BuildInfo.DepexList, self.BuildInfo.ModuleType)\r
-                dpxFile = dpx.Generate(os.path.join(gWorkspaceDir, self.BuildInfo.OutputDir, self.BuildInfo.Name + ".depex"))\r
-                AutoGenList.append(dpxFile)\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
+            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
 \r
             self.IsAutoGenCodeCreated = True\r
-            EdkLogger.info("Generated [%s] files for module %s [%s]" % (" ".join([path.basename(f) for f in AutoGenList]), self.BuildInfo.Name, self.BuildInfo.Arch))\r
-\r
             return AutoGenList\r
 \r
-# This acts like the main() function for the script, unless it is 'import'ed into another\r
-# script.\r
+# Version and Copyright\r
+__version_number__ = "0.01"\r
+__version__ = "%prog Version " + __version_number__\r
+__copyright__ = "Copyright (c) 2007, Intel Corporation. All rights reserved."\r
+\r
+## Parse command line options\r
+#\r
+# Using standard Python module optparse to parse command line option of this tool.\r
+#\r
+# @retval Options   A optparse.Values object containing the parsed options\r
+# @retval InputFile Path of file to be trimmed\r
+#\r
+def GetOptions():\r
+    OptionList = [\r
+        make_option("-a", "--arch", dest="Arch",\r
+                          help="The input file is preprocessed source code, including C or assembly code"),\r
+        make_option("-p", "--platform", dest="ActivePlatform",\r
+                          help="The input file is preprocessed VFR file"),\r
+        make_option("-m", "--module", dest="ActiveModule",\r
+                          help="Convert standard hex format (0xabcd) to MASM format (abcdh)"),\r
+        make_option("-f", "--FDF-file", dest="FdfFile",\r
+                          help="Convert standard hex format (0xabcd) to MASM format (abcdh)"),\r
+        make_option("-o", "--output", dest="OutputDirectory",\r
+                          help="File to store the trimmed content"),\r
+        make_option("-t", "--toolchain-tag", dest="ToolChain",\r
+                          help=""),\r
+        make_option("-k", "--msft", dest="MakefileType", action="store_const", const="nmake",\r
+                          help=""),\r
+        make_option("-g", "--gcc", dest="MakefileType", action="store_const", const="gmake",\r
+                          help=""),\r
+        make_option("-v", "--verbose", dest="LogLevel", action="store_const", const=EdkLogger.VERBOSE,\r
+                          help="Run verbosely"),\r
+        make_option("-d", "--debug", dest="LogLevel", type="int",\r
+                          help="Run with debug information"),\r
+        make_option("-q", "--quiet", dest="LogLevel", action="store_const", const=EdkLogger.QUIET,\r
+                          help="Run quietly"),\r
+        make_option("-?", action="help", help="show this help message and exit"),\r
+    ]\r
+\r
+    # use clearer usage to override default usage message\r
+    UsageString = "%prog [-a ARCH] [-p PLATFORM] [-m MODULE] [-t TOOLCHAIN_TAG] [-k] [-g] [-v|-d <debug_level>|-q] [-o <output_directory>] [GenC|GenMake]"\r
+\r
+    Parser = OptionParser(description=__copyright__, version=__version__, option_list=OptionList, usage=UsageString)\r
+    Parser.set_defaults(Arch=[])\r
+    Parser.set_defaults(ActivePlatform=None)\r
+    Parser.set_defaults(ActiveModule=None)\r
+    Parser.set_defaults(OutputDirectory="build")\r
+    Parser.set_defaults(FdfFile=None)\r
+    Parser.set_defaults(ToolChain="MYTOOLS")\r
+    if sys.platform == "win32":\r
+        Parser.set_defaults(MakefileType="nmake")\r
+    else:\r
+        Parser.set_defaults(MakefileType="gmake")\r
+    Parser.set_defaults(LogLevel=EdkLogger.INFO)\r
+\r
+    Options, Args = Parser.parse_args()\r
+\r
+    # error check\r
+    if len(Args) == 0:\r
+        Options.Target = "genmake"\r
+        sys.argv.append("genmake")\r
+    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
+    else:\r
+        raise AutoGenError(OPTION_NOT_SUPPORTED, name="Too many targets", usage=Parser.get_usage())\r
+\r
+    return Options\r
+\r
+## Entrance method\r
+#\r
+# This method mainly dispatch specific methods per the command line options.\r
+# If no error found, return zero value so the caller of this tool can know\r
+# if it's executed successfully or not.\r
+#\r
+# @retval 0     Tool was successful\r
+# @retval 1     Tool failed\r
+#\r
+def Main():\r
+    from build import build\r
+    try:\r
+        Option = GetOptions()\r
+        build.main()\r
+    except Exception, e:\r
+        print e\r
+        return 1\r
+\r
+    return 0\r
+\r
+# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
 if __name__ == '__main__':\r
-    print "Running Operating System =", sys.platform\r
-    ewb = WorkspaceBuild()\r
-    #print ewb.Build.keys()\r
-\r
-    myArch = ewb.Build["IA32"].Arch\r
-    print myArch\r
-\r
-    myBuild = ewb.Build["IA32"]\r
-\r
-    myWorkspace = ewb\r
-    apf = os.path.normpath(ewb.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0])\r
-    myPlatform = myBuild.PlatformDatabase[os.path.normpath(apf)]\r
-\r
-    #LoadBuildRule(myWorkspace.Workspace.WorkspaceFile('Tools/Conf/build.rule'))\r
-\r
-    myToolchain = ewb.TargetTxt.TargetTxtDictionary["TOOL_CHAIN_TAG"][0]\r
-    #print myToolchain\r
-\r
-    myBuildTarget = ewb.TargetTxt.TargetTxtDictionary["TARGET"][0]\r
-    #print myBuildTarget\r
-\r
-    myBuildOption = {\r
-        "ENABLE_PCH"        :   False,\r
-        "ENABLE_LOCAL_LIB"  :   True,\r
-    }\r
-\r
-    def PrintAutoGen(ag):\r
-        bi = ag.ModuleBuildInfo\r
-\r
-        print " WorkSpaceDir =",bi.WorkspaceDir\r
-        print " SourceDir =",bi.SourceDir\r
-        print " Is Library =",bi.IsLibrary\r
-        print " BaseName =",bi.BaseName\r
-        print " FileBase =",bi.FileBase\r
-        print " FileExt =",bi.FileExt\r
-        print " BuildDir =",bi.BuildDir\r
-        print " OutputDir =",bi.OutputDir\r
-        print " DebugDir =",bi.DebugDir\r
-        print " MakefileDir =",bi.MakefileDir\r
-\r
-        print " Include Path:","\n   ","\n    ".join(bi.InclduePathList)\r
-        print " SourceFileList:","\n   ","\n    ".join(bi.SourceFileList)\r
-\r
-        print " BuildOption:","\n   ","\n    ".join(["%s = %s" % (tool,bi.BuildOption[tool]) for tool in bi.BuildOption])\r
-        print " PcdList:","\n   ","\n    ".join([pcd.TokenCName for pcd in bi.PcdList])\r
-        print " GuidList:","\n   ","\n    ".join(bi.GuidList)\r
-        print " ProtocolList:","\n   ","\n    ".join(bi.ProtocolList)\r
-        print " PpiList:","\n   ","\n    ".join(bi.PpiList)\r
-        print " LibraryList:","\n   ","\n    ".join([str(l) for l in bi.DependentLibraryList])\r
-\r
-        print\r
-\r
-##        for key in gAutoGenDatabase:\r
-##            if str(myPlatform) == str(key[0]):\r
-##                pi = gAutoGenDatabase[key]\r
-##                print " BuildDir =",pi.BuildDir\r
-##                print " OutputDir =",pi.OutputDir\r
-##                print " DebugDir =",pi.DebugDir\r
-##                print " LibraryDir =",pi.LibraryDir\r
-##                print " FvDir =",pi.FvDir\r
-##                print " MakefileDir =",pi.MakefileDir\r
-##                print " PcdTokenNumber:","\n   ","\n    ".join(["%s = %s" % (pcd,pi.PcdTokenNumber[pcd]) for pcd in pi.PcdTokenNumber])\r
-##                print " DynamicPcdList:","\n   ","\n    ".join([str(pcd) for pcd in pi.DynamicPcdList])\r
-##\r
-##                print " ToolPath:","\n   ","\n    ".join(["%s = %s" % (tool,pi.ToolPath[tool]) for tool in pi.ToolPath])\r
-##                print " ToolDynamicLib:","\n   ","\n    ".join(["%s = %s" % (tool,pi.ToolDynamicLib[tool]) for tool in pi.ToolDynamicLib])\r
-##                print " ToolStaticLib:","\n   ","\n    ".join(["%s = %s" % (tool,pi.ToolStaticLib[tool]) for tool in pi.ToolStaticLib])\r
-##                print " ToolChainFamily:","\n   ","\n    ".join(["%s = %s" % (tool,pi.ToolChainFamily[tool]) for tool in pi.ToolChainFamily])\r
-##                print " BuildOption:","\n   ","\n    ".join(["%s = %s" % (tool,pi.BuildOption[tool]) for tool in pi.BuildOption])\r
-##                print " DefaultToolOption:","\n   ","\n    ".join(["%s = %s" % (tool,pi.DefaultToolOption[tool]) for tool in pi.DefaultToolOption])\r
-\r
-    for mf in myBuild.ModuleDatabase:\r
-        #mf = "MdePkg\\Library\\BaseLib\\BaseLib.inf"\r
-        #if mf in myPlatform.Modules and mf in myBuild.ModuleDatabase:\r
-        #print mf\r
-        myModule = myBuild.ModuleDatabase[mf]\r
-        ag = AutoGen(myModule, myPlatform, myWorkspace, myBuildTarget, myToolchain, myArch)\r
-        ag.CreateAutoGenFile()\r
-        ag.CreateMakefile()\r
-\r
-        #PrintAutoGen(ag)\r
-##        for lib in ag.ModuleBuildInfo.DependentLibraryList:\r
-##            ag = AutoGen(lib, myPlatform, myWorkspace, myArch, myToolchain, myBuildTarget)\r
-##            ag.CreateAutoGenFile()\r
-##            ag.CreateMakefile()\r
-##            #PrintAutoGen(ag)\r
-    platformAutoGen = AutoGen(None, apf, myWorkspace, myBuildTarget, myToolchain, myWorkspace.SupArchList)\r
-    platformAutoGen.CreateAutoGenFile()\r
-    platformAutoGen.CreateMakefile()\r
+    sys.exit(Main())\r
index fc5f470..dddf798 100644 (file)
@@ -47,7 +47,7 @@ class ModuleBuildInfo(BuildInfo):
         self.BaseName = ""
         self.FileBase = ""
         self.FileExt = ""
-        
+
         self.WorkspaceDir = ""
         self.SourceDir = ""
         self.BuildDir = ""
@@ -85,7 +85,7 @@ class PackageBuildInfo(BuildInfo):
         self.Name       = package.PackageName
         self.Guid       = package.Guid
         self.Version    = package.Version
-        
+
         self.SourceDir = ""
         self.IncludePathList = []
 
@@ -110,12 +110,12 @@ class PlatformBuildInfo(BuildInfo):
         self.LibraryDir = ""
         self.FvDir = ""
         self.MakefileDir = ""
-        self.FdfFileList = []
+        self.FdfFile = ""
 
         self.ModuleAutoGenList = []
         self.LibraryAutoGenList = []
         self.PackageList = []
-        
+
         self.PcdTokenNumber = {}    # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
         self.DynamicPcdList = []    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
 
index afe0825..b7e2cff 100644 (file)
@@ -1537,15 +1537,5 @@ def CreateCode(Info, AutoGenC, AutoGenH):
 \r
     CreateFooterCode(Info, AutoGenC, AutoGenH)\r
 \r
-def Generate(FilePath, AutoGenC, AutoGenH):\r
-    CreateDirectory(FilePath)\r
-\r
-    AutoGenFileList = []\r
-    SaveFileOnChange(os.path.join(FilePath, "AutoGen.h"), AutoGenH.String)\r
-    AutoGenFileList.append("AutoGen.h")\r
-\r
-    if AutoGenC.String != "":\r
-        SaveFileOnChange(os.path.join(FilePath, "AutoGen.c"), AutoGenC.String)\r
-        AutoGenFileList.append("AutoGen.c")\r
-\r
-    return AutoGenFileList\r
+def Generate(FilePath, Content):\r
+    return SaveFileOnChange(FilePath, Content)\r
index f66b975..7e44b03 100644 (file)
@@ -19,6 +19,7 @@ from StringIO import StringIO
 from struct import pack\r
 from Common.EdkIIWorkspace import CreateDirectory\r
 from Common.BuildToolError import *\r
+from Common.Misc import SaveFileOnChange\r
 \r
 gType2Phase = {\r
     "BASE"              :   None,\r
@@ -71,18 +72,18 @@ class DependencyExpression:
     }\r
 \r
     SupportedOpcode = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "TRUE", "FALSE", "END", "SOR"]\r
-    \r
+\r
     NonEndingOpcode = ["AND", "OR"]\r
 \r
     ExclusiveOpcode = ["BEFORE", "AFTER"]\r
-    \r
+\r
     AboveAllOpcode = ["SOR"]\r
 \r
     #\r
     # open and close brace must be taken as individual tokens\r
     #\r
     TokenPattern = re.compile("(\(|\)|\{[^{}]+\{[^{}]+\}[ ]*\}|\w+)")\r
-    \r
+\r
     def __init__(self, expression, mtype):\r
         self.Phase = gType2Phase[mtype]\r
         if type(expression) == type([]):\r
@@ -148,19 +149,6 @@ class DependencyExpression:
             raise AutoGenError("Invalid GUID value string or opcode: %s" % Guid)\r
         return pack("1I2H8B", *(int(value, 16) for value in GuidValueList))\r
 \r
-    def SaveFile(self, File, Content):\r
-        CreateDirectory(os.path.dirname(File))\r
-        F = None\r
-        if os.path.exists(File):\r
-            F = open(File, 'rb')\r
-            if Content == F.read():\r
-                F.close()\r
-                return\r
-            F.close()\r
-        F = open(File, "wb")\r
-        F.write(Content)\r
-        F.close()\r
-\r
     def Generate(self, File=None):\r
         Buffer = StringIO()\r
         for Item in self.PostfixNotation:\r
@@ -170,15 +158,15 @@ class DependencyExpression:
                 Buffer.write(self.GetGuidValue(Item))\r
 \r
         FilePath = ""\r
+        FileChangeFlag = True\r
         if File == None:\r
             sys.stdout.write(Buffer.getvalue())\r
             FilePath = "STDOUT"\r
         else:\r
-            self.SaveFile(File, Buffer.getvalue())\r
-            FilePath = File\r
+            FileChangeFlag = SaveFileOnChange(File, Buffer.getvalue(), True)\r
 \r
         Buffer.close()\r
-        return FilePath\r
+        return FileChangeFlag\r
 \r
 versionNumber = "0.01"\r
 __version__ = "%prog Version " + versionNumber\r
index f4185e1..1ea7f2e 100755 (executable)
@@ -45,7 +45,7 @@ gMakefileHeader = '''#
 '''\r
 \r
 gLibraryMakeCommand = '''cd %(makedir)s\r
-\t$(MAKE) $(MAKE_FLAGS) -f %(makefile)s %(target)s\r
+\t$(MAKE) $(MAKE_FLAGS) %(target)s\r
 \tcd $(MODULE_BUILD_DIR)'''\r
 \r
 gMakeType = ""\r
@@ -62,9 +62,9 @@ gCreateDirectoryCommand = {"nmake" : "mkdir", "gmake" : "mkdir -p"}
 gRemoveDirectoryCommand = {"nmake" : "rmdir /s /q", "gmake" : "rm -r -f"}\r
 gRemoveFileCommand = {"nmake" : "del /f /q", "gmake" : "rm -f"}\r
 gCopyFileCommand = {"nmake" : "copy /y", "gmake" : "cp -f"}\r
-gCreateDirectoryCommandTemplate = {"nmake" : "if not exist %(dir)s mkdir %(dir)s",\r
+gCreateDirectoryCommandTemplate = {"nmake" : 'if not exist %(dir)s mkdir %(dir)s',\r
                                    "gmake" : "test ! -e %(dir)s && mkdir -p %(dir)s"}\r
-gRemoveDirectoryCommandTemplate = {"nmake" : "if exist %(dir)s rmdir /s /q %(dir)s",\r
+gRemoveDirectoryCommandTemplate = {"nmake" : 'if exist %(dir)s rmdir /s /q %(dir)s',\r
                                    "gmake" : "test -e %(dir)s && rm -r -f %(dir)s"}\r
 \r
 #   $(CP)     copy file command\r
@@ -347,6 +347,12 @@ pbuild: $(INIT_TARGET) $(PCH_TARGET) $(CODA_TARGET)
 mbuild: $(INIT_TARGET) gen_libs $(PCH_TARGET) $(CODA_TARGET)\r
 \r
 \r
+#\r
+# Target to update the FD\r
+#\r
+\r
+fds: mbuild gen_fds\r
+\r
 #\r
 # Initialization target: print build information and create necessary directories\r
 #\r
@@ -363,6 +369,14 @@ gen_libs:
 \t$(MAKE) $(MAKE_FLAGS)\r
 \t${END}cd $(MODULE_BUILD_DIR)\r
 \r
+#\r
+# Build Flash Device Image\r
+#\r
+gen_fds:\r
+\tcd $(BUILD_DIR)\r
+\t$(MAKE) $(MAKE_FLAGS) fds\r
+\tcd $(MODULE_BUILD_DIR)\r
+\r
 #\r
 # Individual Object Build Targets\r
 #\r
@@ -454,7 +468,7 @@ modules: init build_libraries build_modules
 #\r
 # Flash Device Image Target\r
 #\r
-fds: init build_libraries build_modules build_fds\r
+fds: init build_fds\r
 \r
 #\r
 # Build all libraries:\r
@@ -477,7 +491,7 @@ build_modules:
 #\r
 build_fds:\r
 \t-@echo Generating flash image, if any ...\r
-${BEGIN}\tGenFds -f ${fdf_file} -o $(BUILD_DIR) -p ${active_platform} -a ${build_architecture_list}${END}\r
+${BEGIN}\tGenFds -f ${fdf_file} -o $(BUILD_DIR) -p ${active_platform} -a ${build_architecture_list}${END}${BEGIN} -r ${fd} ${END}${BEGIN} -i ${fv} ${END}\r
 \r
 #\r
 # run command for emulator platform only\r
@@ -584,6 +598,12 @@ class Makefile(object):
         self.IntermediateDirectoryList = ["$(BUILD_DIR)%s%s" % (Separator, Arch) for Arch in self.PlatformInfo]\r
         self.IntermediateDirectoryList.append("$(FV_DIR)")\r
 \r
+        # TRICK: for not generating GenFds call in makefile if no FDF file\r
+        if PlatformInfo.FdfFile != None and PlatformInfo.FdfFile != "":\r
+            FdfFileList = [PlatformInfo.FdfFile]\r
+        else:\r
+            FdfFileList = []\r
+\r
         MakefileName = gMakefileName[MakeType]\r
         MakefileTemplateDict = {\r
             "makefile_header"           : gMakefileHeader % MakefileName,\r
@@ -605,8 +625,10 @@ class Makefile(object):
             "cleanall_command"          : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList, MakeType),\r
             "library_build_directory"   : self.LibraryBuildDirectoryList,\r
             "module_build_directory"    : self.ModuleBuildDirectoryList,\r
-            "fdf_file"                  : PlatformInfo.FdfFileList,\r
+            "fdf_file"                  : FdfFileList,\r
             "active_platform"           : PlatformInfo.WorkspaceDir + Separator + ActivePlatform.DescFilePath,\r
+            "fd"                        : PlatformInfo.FdTargetList,\r
+            "fv"                        : PlatformInfo.FvTargetList\r
         }\r
 \r
         self.PrepareDirectory()\r
@@ -620,39 +642,39 @@ class Makefile(object):
         else:\r
             FilePath = File\r
 \r
-        SaveFileOnChange(FilePath, str(AutoGenMakefile))\r
-        return FilePath\r
+        return SaveFileOnChange(FilePath, str(AutoGenMakefile))\r
 \r
     def GenerateModuleMakefile(self, File=None, MakeType=gMakeType):\r
         if MakeType in self.ModuleInfo.CustomMakefile and self.ModuleInfo.CustomMakefile[MakeType] != "":\r
             return self.GenerateCustomBuildMakefile(File, MakeType)\r
 \r
         Separator = gDirectorySeparator[MakeType]\r
+        PlatformInfo = self.PlatformInfo\r
 \r
-        if os.path.isabs(self.PlatformInfo.OutputDir):\r
-            self.PlatformBuildDirectory = self.PlatformInfo.OutputDir\r
+        if os.path.isabs(PlatformInfo.OutputDir):\r
+            self.PlatformBuildDirectory = PlatformInfo.OutputDir\r
         else:\r
-            self.PlatformBuildDirectory = "$(WORKSPACE)" + Separator + self.PlatformInfo.OutputDir\r
+            self.PlatformBuildDirectory = "$(WORKSPACE)" + Separator + PlatformInfo.OutputDir\r
 \r
         self.ProcessSourceFileList(MakeType)\r
         self.ProcessDependentLibrary(MakeType)\r
 \r
-        if "DLINK" in self.PlatformInfo.ToolStaticLib:\r
-            EdkLogger.debug(EdkLogger.DEBUG_5, "Static library: " + self.PlatformInfo.ToolStaticLib["DLINK"])\r
-            self.SystemLibraryList.append(self.PlatformInfo.ToolStaticLib["DLINK"])\r
+        if "DLINK" in PlatformInfo.ToolStaticLib:\r
+            EdkLogger.debug(EdkLogger.DEBUG_5, "Static library: " + PlatformInfo.ToolStaticLib["DLINK"])\r
+            self.SystemLibraryList.append(PlatformInfo.ToolStaticLib["DLINK"])\r
 \r
         EntryPoint = "_ModuleEntryPoint"\r
         if self.ModuleInfo.Arch == "EBC":\r
             EntryPoint = "EfiStart"\r
 \r
-        DefaultToolFlag = self.PlatformInfo.DefaultToolOption.values()\r
+        DefaultToolFlag = PlatformInfo.DefaultToolOption.values()\r
         if self.ModuleInfo.ModuleType == "USER_DEFINED":\r
             DefaultToolFlag = ["" for p in DefaultToolFlag]\r
 \r
-        if "CC" not in self.PlatformInfo.ToolChainFamily:\r
+        if "CC" not in PlatformInfo.ToolChainFamily:\r
             raise AutoGenError(msg="[CC] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
                                     self.ModuleInfo.ToolChain, self.ModuleInfo.Arch))\r
-        if  "DLINK" not in self.PlatformInfo.ToolChainFamily:\r
+        if  "DLINK" not in PlatformInfo.ToolChainFamily:\r
             raise AutoGenError(msg="[DLINK] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
                                     self.ModuleInfo.ToolChain, self.ModuleInfo.Arch))\r
 \r
@@ -688,11 +710,11 @@ class Makefile(object):
         MakefileName = gMakefileName[MakeType]\r
         MakefileTemplateDict = {\r
             "makefile_header"           : gMakefileHeader % MakefileName,\r
-            "platform_name"             : self.PlatformInfo.Name,\r
-            "platform_guid"             : self.PlatformInfo.Guid,\r
-            "platform_version"          : self.PlatformInfo.Version,\r
-            "platform_relative_directory": self.PlatformInfo.SourceDir,\r
-            "platform_output_directory" : self.PlatformInfo.OutputDir,\r
+            "platform_name"             : PlatformInfo.Name,\r
+            "platform_guid"             : PlatformInfo.Guid,\r
+            "platform_version"          : PlatformInfo.Version,\r
+            "platform_relative_directory": PlatformInfo.SourceDir,\r
+            "platform_output_directory" : PlatformInfo.OutputDir,\r
 \r
             "module_name"               : self.ModuleInfo.Name,\r
             "module_guid"               : self.ModuleInfo.Guid,\r
@@ -709,22 +731,22 @@ class Makefile(object):
 \r
             "separator"                 : Separator,\r
             "default_tool_flags"        : DefaultToolFlag,\r
-            "platform_tool_flags"       : [self.PlatformInfo.BuildOption[tool] for tool in self.PlatformInfo.ToolPath],\r
-            "module_tool_flags"         : [self.ModuleInfo.BuildOption[tool] for tool in self.PlatformInfo.ToolPath],\r
+            "platform_tool_flags"       : [PlatformInfo.BuildOption[tool] for tool in PlatformInfo.ToolPath],\r
+            "module_tool_flags"         : [self.ModuleInfo.BuildOption[tool] for tool in PlatformInfo.ToolPath],\r
 \r
-            "tool_code"                 : self.PlatformInfo.ToolPath.keys(),\r
-            "tool_path"                 : self.PlatformInfo.ToolPath.values(),\r
+            "tool_code"                 : PlatformInfo.ToolPath.keys(),\r
+            "tool_path"                 : PlatformInfo.ToolPath.values(),\r
 \r
             "shell_command_code"        : gShellCommand[MakeType].keys(),\r
             "shell_command"             : gShellCommand[MakeType].values(),\r
 \r
             "module_entry_point"        : EntryPoint,\r
             #"auto_generated_file"       : self.AutoGenBuildFileList,\r
-            "include_path_prefix"       : gIncludeFlag[self.PlatformInfo.ToolChainFamily["CC"]],\r
-            "dlink_output_flag"         : self.PlatformInfo.OutputFlag["DLINK"],\r
-            "slink_output_flag"         : self.PlatformInfo.OutputFlag["SLINK"],\r
-            "start_group_flag"          : gStartGroupFlag[self.PlatformInfo.ToolChainFamily["DLINK"]],\r
-            "end_group_flag"            : gEndGroupFlag[self.PlatformInfo.ToolChainFamily["DLINK"]],\r
+            "include_path_prefix"       : gIncludeFlag[PlatformInfo.ToolChainFamily["CC"]],\r
+            "dlink_output_flag"         : PlatformInfo.OutputFlag["DLINK"],\r
+            "slink_output_flag"         : PlatformInfo.OutputFlag["SLINK"],\r
+            "start_group_flag"          : gStartGroupFlag[PlatformInfo.ToolChainFamily["DLINK"]],\r
+            "end_group_flag"            : gEndGroupFlag[PlatformInfo.ToolChainFamily["DLINK"]],\r
             "include_path"              : self.ModuleInfo.IncludePathList,\r
             "target_file"               : self.TargetFileList,\r
             "object_file"               : self.ObjectFileList,\r
@@ -745,7 +767,7 @@ class Makefile(object):
             "target_file_macro"         : TargetFileMacroList,\r
             "source_file_macro_name"    : SourceFileMacroNameList,\r
             "target_file_macro_name"    : TargetFileMacroNameList,\r
-            "file_build_target"         : self.BuildTargetList\r
+            "file_build_target"         : self.BuildTargetList,\r
         }\r
 \r
         self.PrepareDirectory()\r
@@ -759,8 +781,7 @@ class Makefile(object):
         else:\r
             FilePath = File\r
 \r
-        SaveFileOnChange(FilePath, str(AutoGenMakefile))\r
-        return FilePath\r
+        return SaveFileOnChange(FilePath, str(AutoGenMakefile))\r
 \r
     def GenerateCustomBuildMakefile(self, File=None, MakeType=gMakeType):\r
         Separator = gDirectorySeparator[MakeType]\r
@@ -819,8 +840,7 @@ class Makefile(object):
         else:\r
             FilePath = File\r
 \r
-        SaveFileOnChange(FilePath, str(AutoGenMakefile))\r
-        return FilePath\r
+        return SaveFileOnChange(FilePath, str(AutoGenMakefile))\r
 \r
     def ProcessSourceFileList(self, MakeType=gMakeType):\r
         Separator = gDirectorySeparator[MakeType]\r
@@ -1159,43 +1179,6 @@ class Makefile(object):
     def GetRemoveDirectoryCommand(self, DirList, MakeType=gMakeType):\r
         return [gRemoveDirectoryCommandTemplate[MakeType] % {'dir':Dir} for Dir in DirList]\r
 \r
-# This acts like the main() function for the script, unless it is 'import'ed into another\r
-# script.\r
+# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
 if __name__ == '__main__':\r
-    print "Running Operating System =", sys.platform\r
-    ewb = WorkspaceBuild()\r
-    #print ewb.Build.keys()\r
-\r
-    myArch = ewb.Build["IA32"].Arch\r
-    #print myArch\r
-\r
-    myBuild = ewb.Build["IA32"]\r
-\r
-    myWorkspace = ewb\r
-    apf = ewb.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0]\r
-    myPlatform = myBuild.PlatformDatabase[os.path.normpath(apf)]\r
-\r
-    for mf in myBuild.ModuleDatabase:\r
-        #mf = "MdePkg\\Library\\BaseLib\\BaseLib.inf"\r
-        #if mf in myPlatform.Modules and mf in myBuild.ModuleDatabase:\r
-        #print mf\r
-\r
-        myModule = myBuild.ModuleDatabase[mf]\r
-\r
-        myPackage = FindModuleOwner(myModule.DescFilePath, myBuild.PackageDatabase)\r
-\r
-        myToolchain = ewb.TargetTxt.TargetTxtDictionary["TOOL_CHAIN_TAG"][0]\r
-        #print myToolchain\r
-\r
-        myBuildTarget = ewb.TargetTxt.TargetTxtDictionary["TARGET"][0]\r
-        #print myBuildTarget\r
-\r
-        myBuildOption = {\r
-            "ENABLE_PCH"        :   False,\r
-            "ENABLE_LOCAL_LIB"  :   True,\r
-        }\r
-\r
-        myMakefile = Makefile(myModule, myPackage, myPlatform, myWorkspace, myToolchain, myBuildTarget,\r
-                              myArch, myBuildOption, "nmake")\r
-\r
-        myMakefile.NewGenerate()\r
+    pass\r
index 09b49d7..279f25e 100755 (executable)
@@ -26,7 +26,7 @@ from SequentialDict import *
 from CommonDataClass.CommonClass import *\r
 \r
 #\r
-# This Class is used for PcdObject \r
+# This Class is used for PcdObject\r
 #\r
 class PcdClassObject(object):\r
     def __init__(self, Name = None, Guid = None, Type = None, DatumType = None, Value = None, Token = None, MaxDatumSize = None, SkuInfoList = {}, IsOverrided = False):\r
@@ -40,7 +40,7 @@ class PcdClassObject(object):
         self.SkuInfoList = SkuInfoList\r
         self.IsOverrided = IsOverrided\r
         self.Phase = "DXE"\r
-        \r
+\r
     def __str__(self):\r
         rtn = '\tTokenCName=' + str(self.TokenCName) + ', ' + \\r
               'TokenSpaceGuidCName=' + str(self.TokenSpaceGuidCName) + ', ' + \\r
@@ -52,7 +52,7 @@ class PcdClassObject(object):
         for Item in self.SkuInfoList.values():\r
             rtn = rtn + 'SkuId=' + Item.SkuId + ', ' + 'SkuIdName=' + Item.SkuIdName\r
         rtn = rtn + str(self.IsOverrided)\r
-        \r
+\r
         return rtn\r
 \r
     def __eq__(self, other):\r
@@ -70,7 +70,7 @@ class LibraryClassObject(object):
         self.SupModList = SupModList\r
         if Type != None:\r
             self.SupModList = CleanString(Type).split(DataType.TAB_SPACE_SPLIT)\r
-        \r
+\r
 class ModuleBuildClassObject(object):\r
     def __init__(self):\r
         self.DescFilePath            = ''\r
@@ -87,7 +87,7 @@ class ModuleBuildClassObject(object):
         self.ModuleUnloadImageList   = []\r
         self.ConstructorList         = []\r
         self.DestructorList          = []\r
-        \r
+\r
         self.Binaries                = []        #[ ModuleBinaryClassObject, ...]\r
         self.Sources                 = []        #[ ModuleSourceFilesClassObject, ... ]\r
         self.LibraryClasses          = {}        #{ [LibraryClassName, ModuleType] : LibraryClassInfFile }\r
@@ -115,14 +115,14 @@ class PackageBuildClassObject(object):
         self.PackageName             = ''\r
         self.Guid                    = ''\r
         self.Version                 = ''\r
-        \r
+\r
         self.Protocols               = {}       #{ [ProtocolName] : Protocol Guid, ... }\r
         self.Ppis                    = {}       #{ [PpiName] : Ppi Guid, ... }\r
         self.Guids                   = {}       #{ [GuidName] : Guid, ... }\r
-        self.Includes                = []       #[ IncludePath, ... ]        \r
+        self.Includes                = []       #[ IncludePath, ... ]\r
         self.LibraryClasses          = {}       #{ [LibraryClassName] : LibraryClassInfFile }\r
         self.Pcds                    = {}       #{ [(PcdCName, PcdGuidCName)] : PcdClassObject}\r
-        \r
+\r
     def __str__(self):\r
         return self.DescFilePath\r
 \r
@@ -143,13 +143,13 @@ class PlatformBuildClassObject(object):
         self.FlashDefinition         = ''\r
         self.BuildNumber             = ''\r
         self.MakefileName            = ''\r
-                \r
+\r
         self.SkuIds                  = {}       #{ 'SkuName' : SkuId, '!include' : includefilename, ...}\r
         self.Modules                 = []       #[ InfFileName, ... ]\r
         self.Libraries               = []       #[ InfFileName, ... ]\r
         self.LibraryClasses          = {}       #{ (LibraryClassName, ModuleType) : LibraryClassInfFile }\r
         self.Pcds                    = {}       #{ [(PcdCName, PcdGuidCName)] : PcdClassObject }\r
-        self.BuildOptions            = {}       #{ [BuildOptionKey] : BuildOptionValue }    \r
+        self.BuildOptions            = {}       #{ [BuildOptionKey] : BuildOptionValue }\r
 \r
     def __str__(self):\r
         return self.DescFilePath\r
@@ -166,7 +166,7 @@ class ItemBuild(object):
         self.PlatformDatabase        = {}        #{ [DscFileName] : PlatformBuildClassObject, ...}\r
         self.PackageDatabase         = {}        #{ [DecFileName] : PacakgeBuildClassObject, ...}\r
         self.ModuleDatabase          = {}        #{ [InfFileName] : ModuleBuildClassObject, ...}\r
-        \r
+\r
 #\r
 # This class is used to parse active platform to init all inf/dec/dsc files\r
 # Generate module/package/platform databases for build\r
@@ -178,20 +178,22 @@ class WorkspaceBuild(object):
         self.BuildTarget             = []        #[ 'RELEASE', 'DEBUG']\r
         self.SkuId                   = ''\r
         self.Fdf                     = ''\r
+        self.FdTargetList            = []\r
+        self.FvTargetList            = []\r
         self.TargetTxt               = None\r
         self.ToolDef                 = None\r
-        \r
+\r
         self.InfDatabase             = {}        #{ [InfFileName] : InfClassObject}\r
         self.DecDatabase             = {}        #{ [DecFileName] : DecClassObject}\r
         self.DscDatabase             = {}        #{ [DscFileName] : DscClassObject}\r
-        \r
+\r
         #\r
         # Init build for all arches\r
         #\r
         self.Build                   = {}\r
         for Arch in DataType.ARCH_LIST:\r
             self.Build[Arch] = ItemBuild(Arch)\r
-        \r
+\r
         #\r
         # Get active platform\r
         #\r
@@ -201,13 +203,13 @@ class WorkspaceBuild(object):
             self.DscDatabase[DscFileName] = Dsc(File, True, True, self.WorkspaceDir)\r
         else:\r
             raise ParserError(FILE_NOT_FOUND, name = File)\r
-        \r
+\r
         #\r
         # Parse platform to get module\r
         #\r
         for DscFile in self.DscDatabase.keys():\r
             Platform = self.DscDatabase[DscFile].Platform\r
-            \r
+\r
             #\r
             # Get global information\r
             #\r
@@ -215,14 +217,14 @@ class WorkspaceBuild(object):
             self.BuildTarget = Platform.Header.BuildTargets\r
             self.SkuId = Platform.Header.SkuIdName\r
             self.Fdf = NormPath(Platform.FlashDefinitionFile.FilePath)\r
-            \r
+\r
             #\r
             # Get all inf files\r
             #\r
             for Item in Platform.LibraryClasses.LibraryList:\r
                 for Arch in Item.SupArchList:\r
                     self.AddToInfDatabase(Item.FilePath)\r
-            \r
+\r
             for Item in Platform.Modules.ModuleList:\r
                 for Arch in Item.SupArchList:\r
                     #\r
@@ -236,7 +238,7 @@ class WorkspaceBuild(object):
                     for Lib in Item.LibraryClasses.LibraryList:\r
                         self.AddToInfDatabase(Lib.FilePath)\r
                         self.UpdateLibraryClassOfModule(Module, Lib.Name, Arch, Lib.FilePath)\r
-        \r
+\r
         #\r
         # Parse module to get package\r
         #\r
@@ -249,17 +251,17 @@ class WorkspaceBuild(object):
                 for Arch in Item.SupArchList:\r
                     self.AddToDecDatabase(Item.FilePath)\r
     # End of self.Init()\r
-    \r
+\r
     #\r
     # Generate PlatformDatabase\r
     #\r
     def GenPlatformDatabase(self):\r
         for Dsc in self.DscDatabase.keys():\r
             Platform = self.DscDatabase[Dsc].Platform\r
-            \r
+\r
             for Arch in self.SupArchList:\r
                 pb = PlatformBuildClassObject()\r
-                \r
+\r
                 # Defines\r
                 pb.DescFilePath = Dsc\r
                 pb.PlatformName = Platform.Header.Name\r
@@ -269,28 +271,28 @@ class WorkspaceBuild(object):
                 pb.OutputDirectory = NormPath(Platform.Header.OutputDirectory)\r
                 pb.FlashDefinition = NormPath(Platform.FlashDefinitionFile.FilePath)\r
                 pb.BuildNumber = Platform.Header.BuildNumber\r
-            \r
+\r
                 # SkuId\r
                 for Key in Platform.SkuInfos.SkuInfoList.keys():\r
                     pb.SkuIds[Key] = Platform.SkuInfos.SkuInfoList[Key]\r
-                \r
+\r
                 # Module\r
                 for Item in Platform.Modules.ModuleList:\r
                     if Arch in Item.SupArchList:\r
                         pb.Modules.append(NormPath(Item.FilePath))\r
-                    \r
+\r
                 # BuildOptions\r
                 for Item in Platform.BuildOptions.BuildOptionList:\r
                     if Arch in Item.SupArchList:\r
                         pb.BuildOptions[(Item.ToolChainFamily, Item.ToolChain)] = Item.Option\r
-                  \r
+\r
                 # LibraryClass\r
                 for Item in Platform.LibraryClasses.LibraryList:\r
                     SupModuleList = self.FindSupModuleListOfLibraryClass(Item, Platform.LibraryClasses.LibraryList)\r
                     if Arch in Item.SupArchList:\r
                         for ModuleType in SupModuleList:\r
                             pb.LibraryClasses[(Item.Name, ModuleType)] = NormPath(Item.FilePath)\r
-                    \r
+\r
                 # Pcds\r
                 for Item in Platform.DynamicPcdBuildDefinitions:\r
                     if Arch in Item.SupArchList:\r
@@ -303,52 +305,52 @@ class WorkspaceBuild(object):
                         MaxDatumSize = Item.MaxDatumSize\r
                         SkuInfoList = Item.SkuInfoList\r
                         pb.Pcds[(Name, Guid)] = PcdClassObject(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, False)\r
-                \r
+\r
                 # Add to database\r
                 self.Build[Arch].PlatformDatabase[Dsc] = pb\r
                 pb = None\r
-    \r
+\r
     #\r
     # Generate PackageDatabase\r
-    #    \r
+    #\r
     def GenPackageDatabase(self):\r
         for Dec in self.DecDatabase.keys():\r
             Package = self.DecDatabase[Dec].Package\r
-        \r
+\r
             for Arch in self.SupArchList:\r
                 pb = PackageBuildClassObject()\r
-                \r
+\r
                 # Defines\r
                 pb.DescFilePath = Dec\r
                 pb.PackageName = Package.Header.Name\r
                 pb.Guid = Package.Header.Guid\r
                 pb.Version = Package.Header.Version\r
-                \r
+\r
                 # Protocols\r
                 for Item in Package.ProtocolDeclarations:\r
                     if Arch in Item.SupArchList:\r
                         pb.Protocols[Item.CName] = Item.Guid\r
-                        \r
+\r
                 # Ppis\r
                 for Item in Package.PpiDeclarations:\r
                     if Arch in Item.SupArchList:\r
                         pb.Ppis[Item.CName] = Item.Guid\r
-                \r
+\r
                 # Guids\r
                 for Item in Package.GuidDeclarations:\r
                     if Arch in Item.SupArchList:\r
                         pb.Ppis[Item.CName] = Item.Guid\r
-                \r
+\r
                 # Includes\r
                 for Item in Package.Includes:\r
                     if Arch in Item.SupArchList:\r
                         pb.Includes.append(NormPath(Item.FilePath))\r
-                        \r
+\r
                 # LibraryClasses\r
                 for Item in Package.LibraryClassDeclarations:\r
                     if Arch in Item.SupArchList:\r
                         pb.LibraryClasses[Item.LibraryClass] = NormPath(Item.RecommendedInstance)\r
-                \r
+\r
                 # Pcds\r
                 for Item in Package.PcdDeclarations:\r
                     if Arch in Item.SupArchList:\r
@@ -361,24 +363,24 @@ class WorkspaceBuild(object):
                         MaxDatumSize = Item.MaxDatumSize\r
                         SkuInfoList = Item.SkuInfoList\r
                         pb.Pcds[(Name, Guid)] = PcdClassObject(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, False)\r
-                \r
+\r
                 # Add to database\r
                 self.Build[Arch].PackageDatabase[Dec] = pb\r
                 pb = None\r
-    \r
+\r
     #\r
     # Generate ModuleDatabase\r
     #\r
     def GenModuleDatabase(self, PcdsSet = {}):\r
         for Inf in self.InfDatabase.keys():\r
             Module = self.InfDatabase[Inf].Module\r
-            \r
+\r
             for Arch in self.SupArchList:\r
                 if not self.IsModuleDefinedInPlatform(Inf, Arch):\r
                     continue\r
-                \r
+\r
                 pb = ModuleBuildClassObject()\r
-                \r
+\r
                 # Defines\r
                 pb.DescFilePath = Inf\r
                 pb.BaseName = Module.Header.Name\r
@@ -388,12 +390,12 @@ class WorkspaceBuild(object):
                 pb.PcdIsDriver = Module.Header.PcdIsDriver\r
                 pb.BinaryModule = Module.Header.BinaryModule\r
                 pb.CustomMakefile = Module.Header.CustomMakefile\r
-                \r
+\r
                 # Specs os Defines\r
                 pb.Specification = Module.Header.Specification\r
                 pb.Specification[TAB_INF_DEFINES_EDK_RELEASE_VERSION] = Module.Header.EdkReleaseVersion\r
                 pb.Specification[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION] = Module.Header.EfiSpecificationVersion\r
-                \r
+\r
                 # LibraryClass of Defines\r
                 for Item in Module.Header.LibraryClass:\r
                     pb.LibraryClass.append(LibraryClassObject(Item.LibraryClass, Item.SupModuleList, None))\r
@@ -409,7 +411,7 @@ class WorkspaceBuild(object):
                         pb.ConstructorList.append(Item.Constructor)\r
                     if Item.Destructor != '':\r
                         pb.DestructorList.append(Item.Destructor)\r
-                \r
+\r
                 # Binaries\r
                 for Item in Module.Binaries:\r
                     if Arch in Item.SupArchList:\r
@@ -418,7 +420,7 @@ class WorkspaceBuild(object):
                         Target = Item.Target\r
                         FeatureFlag = Item.FeatureFlag\r
                         pb.Binaries.append(ModuleBinaryFileClass(FileName, FileType, Target, FeatureFlag))\r
-                \r
+\r
                 #Sources\r
                 for Item in Module.Sources:\r
                     if Arch in Item.SupArchList:\r
@@ -428,44 +430,44 @@ class WorkspaceBuild(object):
                         ToolChainFamily = Item.ToolChainFamily\r
                         FeatureFlag = Item.FeatureFlag\r
                         pb.Sources.append(ModuleSourceFileClass(SourceFile, TagName, ToolCode, ToolChainFamily, FeatureFlag))\r
-                \r
+\r
                 # Protocols\r
                 for Item in Module.Protocols:\r
                     if Arch in Item.SupArchList:\r
                         pb.Protocols.append(Item.CName)\r
-                        \r
+\r
                 # Ppis\r
                 for Item in Module.Ppis:\r
                     if Arch in Item.SupArchList:\r
                         pb.Ppis.append(Item.CName)\r
-                \r
+\r
                 # Guids\r
                 for Item in Module.Guids:\r
                     if Arch in Item.SupArchList:\r
                         pb.Ppis.append(Item.CName)\r
-                \r
+\r
                 # Includes\r
                 for Item in Module.Includes:\r
                     if Arch in Item.SupArchList:\r
-                        pb.Includes.append(NormPath(Item.FilePath))                \r
-                \r
+                        pb.Includes.append(NormPath(Item.FilePath))\r
+\r
                 # Packages\r
                 for Item in Module.PackageDependencies:\r
                     if Arch in Item.SupArchList:\r
-                        pb.Packages.append(NormPath(Item.FilePath))                        \r
+                        pb.Packages.append(NormPath(Item.FilePath))\r
 \r
                 # BuildOptions\r
                 for Item in Module.BuildOptions:\r
                     if Arch in Item.SupArchList:\r
                         pb.BuildOptions[(Item.ToolChainFamily, Item.ToolChain)] = Item.Option\r
                 self.FindBuildOptions(Arch, Inf, pb.BuildOptions)\r
-                \r
+\r
                 # Depex\r
                 for Item in Module.Depex:\r
                     if Arch in Item.SupArchList:\r
                         pb.Depex = pb.Depex + Item.Depex + ' '\r
                 pb.Depex = pb.Depex.strip()\r
-                \r
+\r
                 # LibraryClasses\r
                 for Item in Module.LibraryClasses:\r
                     if Arch in Item.SupArchList:\r
@@ -481,11 +483,11 @@ class WorkspaceBuild(object):
                                     pb.LibraryClasses[(Lib, Type)] = NormPath(Instance)\r
                         else:\r
                             # For Module\r
-                            Instance = self.FindLibraryClassInstanceOfModule(Lib, Arch, pb.ModuleType, Inf) \r
+                            Instance = self.FindLibraryClassInstanceOfModule(Lib, Arch, pb.ModuleType, Inf)\r
                             if Instance == None:\r
                                 Instance = RecommendedInstance\r
                             pb.LibraryClasses[(Lib, pb.ModuleType)] = NormPath(Instance)\r
-                \r
+\r
                 # Pcds\r
                 for Item in Module.PcdCodes:\r
                     if Arch in Item.SupArchList:\r
@@ -493,11 +495,11 @@ class WorkspaceBuild(object):
                         Guid = Item.TokenSpaceGuidCName\r
                         Type = Item.ItemType\r
                         pb.Pcds[(Name, Guid)] = self.FindPcd(Arch, Inf, Name, Guid, Type, PcdsSet)\r
-                \r
+\r
                 # Add to database\r
                 self.Build[Arch].ModuleDatabase[Inf] = pb\r
                 pb = None\r
-    \r
+\r
     #\r
     # Update Libraries Of Platform Database\r
     #\r
@@ -532,7 +534,7 @@ class WorkspaceBuild(object):
 \r
     def UpdateLibrariesOfModule(self, Module, Arch):\r
         ModuleDatabase = self.Build[Arch].ModuleDatabase\r
-        \r
+\r
         ModuleType = Module.ModuleType\r
         LibraryConsumerList = [Module]\r
 \r
@@ -651,8 +653,8 @@ class WorkspaceBuild(object):
         #\r
         for m in LibraryList:\r
             if ConsumedByList[m] != [] and m in Constructor:\r
-                errorMessage = 'Module library [%s] with constructors have a cycle:\n\t' % str(m)\r
-                errorMessage += "\n\tconsumed by ".join([str(l) for l in ConsumedByList[m]])\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
             if m not in SortedLibraryList:\r
                 SortedLibraryList.append(m)\r
@@ -705,7 +707,7 @@ class WorkspaceBuild(object):
     #\r
     def WorkspaceFile(self, Filename):\r
         return WorkspaceFile(self.WorkspaceDir, Filename)\r
-    \r
+\r
     #\r
     # If a module of a platform has its own override libraryclass but the libraryclass not defined in the module\r
     # Add this libraryclass to the module\r
@@ -728,7 +730,7 @@ class WorkspaceBuild(object):
             NewLib.LibraryClass = LibraryClass\r
             NewLib.SupModuleList = self.InfDatabase[NormPath(InstanceFilePath)].Module.Header.ModuleType.split()\r
             self.InfDatabase[NormPath(InstanceFilePath)].Module.Header.LibraryClass.append(NewLib)\r
-        \r
+\r
         #\r
         # Add it to LibraryClasses Section for the module which is using the library\r
         #\r
@@ -749,7 +751,7 @@ class WorkspaceBuild(object):
             Lib.LibraryClass = LibraryClass\r
             Lib.SupArchList = [Arch]\r
             self.InfDatabase[NormPath(InfFileName)].Module.LibraryClasses.append(Lib)\r
-            \r
+\r
     #\r
     # Create a Inf instance for input inf file and add it to InfDatabase\r
     #\r
@@ -761,10 +763,10 @@ class WorkspaceBuild(object):
                 self.InfDatabase[InfFileName] = Inf(File, True, True, self.WorkspaceDir)\r
         else:\r
             raise ParserError(FILE_NOT_FOUND, name = File)\r
-    \r
+\r
     #\r
     # Create a Dec instance for input dec file and add it to DecDatabase\r
-    #                \r
+    #\r
     def AddToDecDatabase(self, DecFileName):\r
         DecFileName = NormPath(DecFileName)\r
         File = self.WorkspaceFile(DecFileName)\r
@@ -773,7 +775,7 @@ class WorkspaceBuild(object):
                 self.DecDatabase[DecFileName] = Dec(File, True, True, self.WorkspaceDir)\r
         else:\r
             raise ParserError(FILE_NOT_FOUND, name = File)\r
-                \r
+\r
     #\r
     # Search PlatformBuildDatabase to find LibraryClass Instance for Module\r
     # Return the instance if found\r
@@ -791,10 +793,10 @@ class WorkspaceBuild(object):
                             if LibraryClass.Name == Lib:\r
                                 return NormPath(LibraryClass.FilePath)\r
         #\r
-        #Second find if exist in <LibraryClass> of <LibraryClasses> from dsc file            \r
+        #Second find if exist in <LibraryClass> of <LibraryClasses> from dsc file\r
         #\r
         return self.FindLibraryClassInstanceOfLibrary(Lib, Arch, ModuleType)\r
-            \r
+\r
     #\r
     # Search PlatformBuildDatabase to find LibraryClass Instance for Library\r
     # Return the instance if found\r
@@ -807,7 +809,7 @@ class WorkspaceBuild(object):
             elif (Lib, '') in self.Build[Arch].PlatformDatabase[Dsc].LibraryClasses:\r
                 return self.Build[Arch].PlatformDatabase[Dsc].LibraryClasses[(Lib, '')]\r
         return None\r
-            \r
+\r
     #\r
     # Search DscDatabase to find component definition of ModuleName\r
     # Override BuildOption if it is defined in component\r
@@ -824,7 +826,7 @@ class WorkspaceBuild(object):
                     if NormPath(Module.FilePath) == ModuleName:\r
                         for BuildOption in Module.ModuleSaBuildOption.BuildOptionList:\r
                             BuildOptions[(BuildOption.ToolChainFamily, BuildOption.ToolChain)] = BuildOption.Option\r
-                        \r
+\r
     #\r
     # Search platform database, package database, module database and PcdsSet from Fdf\r
     # Return found Pcd\r
@@ -853,7 +855,7 @@ class WorkspaceBuild(object):
                 IsOverrided = True\r
                 IsFoundInDsc = True\r
                 break\r
-        \r
+\r
         #\r
         # Second get information from package database\r
         #\r
@@ -866,9 +868,9 @@ class WorkspaceBuild(object):
                 IsFoundInDec = True\r
                 break\r
         if not IsFoundInDec:\r
-            ErrorMsg = "Pcd '%s' defined in module '%s' is not found in any package" % (Name, ModuleName) \r
+            ErrorMsg = "Pcd '%s' defined in module '%s' is not found in any package" % (Name, ModuleName)\r
             raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
-        \r
+\r
         #\r
         # Third get information from <Pcd> of <Compontents> from module database\r
         #\r
@@ -885,7 +887,7 @@ class WorkspaceBuild(object):
                                 IsFoundInDsc = True\r
                                 IsOverrided = True\r
                                 break\r
-        \r
+\r
         #\r
         # Last get information from PcdsSet defined by FDF\r
         #\r
@@ -893,16 +895,16 @@ class WorkspaceBuild(object):
             Value = PcdsSet[(Name, Guid)]\r
             IsFoundInDsc = True\r
             IsOverrided = True\r
-            \r
+\r
         #\r
         # Not found in any platform and fdf\r
         #\r
         if not IsFoundInDsc:\r
-            ErrorMsg = "Pcd '%s' defined in module '%s' is not found in any platform" % (Name, ModuleName) \r
+            ErrorMsg = "Pcd '%s' defined in module '%s' is not found in any platform" % (Name, ModuleName)\r
             raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
 \r
         return PcdClassObject(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, IsOverrided)\r
-    \r
+\r
     #\r
     # Search in InfDatabase, find the supmodulelist of the libraryclass\r
     #\r
@@ -910,7 +912,7 @@ class WorkspaceBuild(object):
         Name = LibraryClass.Name\r
         FilePath = NormPath(LibraryClass.FilePath)\r
         SupModuleList = copy.copy(LibraryClass.SupModuleList)\r
-        \r
+\r
         #\r
         # If the SupModuleList means all, remove overrided module types of platform\r
         #\r
@@ -940,7 +942,7 @@ class WorkspaceBuild(object):
                                     SupModuleList.remove(ModuleType)\r
 \r
         return SupModuleList\r
-    \r
+\r
     #\r
     # Check if the module is defined in <Compentent> of <Platform>\r
     #\r
@@ -956,7 +958,7 @@ class WorkspaceBuild(object):
                 for Item in Module.LibraryClasses.LibraryList:\r
                     if Inf == NormPath(Item.FilePath):\r
                         return True\r
-                \r
+\r
         return False\r
 \r
     #\r
@@ -969,83 +971,83 @@ class WorkspaceBuild(object):
         print 'SupArchList', ewb.SupArchList\r
         print 'BuildTarget', ewb.BuildTarget\r
         print 'SkuId', ewb.SkuId\r
-        \r
+\r
         for arch in ewb.SupArchList:\r
             print arch\r
             print 'Platform'\r
             for platform in ewb.Build[arch].PlatformDatabase.keys():\r
                 p = ewb.Build[arch].PlatformDatabase[platform]\r
-                print 'DescFilePath = ', p.DescFilePath     \r
-                print 'PlatformName = ', p.PlatformName     \r
-                print 'Guid = ', p.Guid                     \r
+                print 'DescFilePath = ', p.DescFilePath\r
+                print 'PlatformName = ', p.PlatformName\r
+                print 'Guid = ', p.Guid\r
                 print 'Version = ', p.Version\r
-                print 'OutputDirectory = ', p.OutputDirectory                \r
+                print 'OutputDirectory = ', p.OutputDirectory\r
                 print 'FlashDefinition = ', p.FlashDefinition\r
                 print 'SkuIds = ', p.SkuIds\r
                 print 'Modules = ', p.Modules\r
-                print 'LibraryClasses = ', p.LibraryClasses \r
+                print 'LibraryClasses = ', p.LibraryClasses\r
                 print 'Pcds = ', p.Pcds\r
                 for item in p.Pcds.keys():\r
                     print p.Pcds[item]\r
                 print 'BuildOptions = ', p.BuildOptions\r
-                print ''   \r
+                print ''\r
             # End of Platform\r
-        \r
+\r
             print 'package'\r
             for package in ewb.Build[arch].PackageDatabase.keys():\r
                 p = ewb.Build[arch].PackageDatabase[package]\r
-                print 'DescFilePath = ', p.DescFilePath    \r
-                print 'PackageName = ', p.PackageName     \r
-                print 'Guid = ', p.Guid                    \r
-                print 'Version = ', p.Version             \r
-                print 'Protocols = ', p.Protocols         \r
-                print 'Ppis = ', p.Ppis                    \r
-                print 'Guids = ', p.Guids                 \r
-                print 'Includes = ', p.Includes            \r
+                print 'DescFilePath = ', p.DescFilePath\r
+                print 'PackageName = ', p.PackageName\r
+                print 'Guid = ', p.Guid\r
+                print 'Version = ', p.Version\r
+                print 'Protocols = ', p.Protocols\r
+                print 'Ppis = ', p.Ppis\r
+                print 'Guids = ', p.Guids\r
+                print 'Includes = ', p.Includes\r
                 print 'LibraryClasses = ', p.LibraryClasses\r
                 print 'Pcds = ', p.Pcds\r
                 for item in p.Pcds.keys():\r
                     print p.Pcds[item]\r
-                print ''                    \r
+                print ''\r
             # End of Package\r
-            \r
+\r
             print 'module'\r
             for module in ewb.Build[arch].ModuleDatabase.keys():\r
                 p = ewb.Build[arch].ModuleDatabase[module]\r
-                print 'DescFilePath = ', p.DescFilePath                    \r
-                print 'BaseName = ', p.BaseName                         \r
-                print 'ModuleType = ', p.ModuleType                     \r
-                print 'Guid = ', p.Guid                                 \r
+                print 'DescFilePath = ', p.DescFilePath\r
+                print 'BaseName = ', p.BaseName\r
+                print 'ModuleType = ', p.ModuleType\r
+                print 'Guid = ', p.Guid\r
                 print 'Version = ', p.Version\r
                 print 'CustomMakefile = ', p.CustomMakefile\r
                 print 'Specification = ', p.Specification\r
                 print 'PcdIsDriver = ', p.PcdIsDriver\r
                 for Lib in p.LibraryClass:\r
                     print 'LibraryClassDefinition = ', Lib.LibraryClass, 'SupModList = ', Lib.SupModList\r
-                print 'ModuleEntryPointList = ', p.ModuleEntryPointList \r
+                print 'ModuleEntryPointList = ', p.ModuleEntryPointList\r
                 print 'ModuleUnloadImageList = ', p.ModuleUnloadImageList\r
-                print 'ConstructorList = ', p.ConstructorList            \r
-                print 'DestructorList = ', p.DestructorList             \r
-                                                                         \r
+                print 'ConstructorList = ', p.ConstructorList\r
+                print 'DestructorList = ', p.DestructorList\r
+\r
                 print 'Binaries = '\r
                 for item in p.Binaries:\r
                     print item.BinaryFile, item.FeatureFlag\r
                 print 'Sources = '\r
                 for item in p.Sources:\r
                     print item.SourceFile\r
-                print 'LibraryClasses = ', p.LibraryClasses             \r
-                print 'Protocols = ', p.Protocols                        \r
-                print 'Ppis = ', p.Ppis                                 \r
-                print 'Guids = ', p.Guids                                \r
-                print 'Includes = ', p.Includes                         \r
-                print 'Packages = ', p.Packages                         \r
+                print 'LibraryClasses = ', p.LibraryClasses\r
+                print 'Protocols = ', p.Protocols\r
+                print 'Ppis = ', p.Ppis\r
+                print 'Guids = ', p.Guids\r
+                print 'Includes = ', p.Includes\r
+                print 'Packages = ', p.Packages\r
                 print 'Pcds = ', p.Pcds\r
                 for item in p.Pcds.keys():\r
                     print p.Pcds[item]\r
                 print 'BuildOptions = ', p.BuildOptions\r
                 print 'Depex = ', p.Depex\r
                 print ''\r
-            # End of Module    \r
+            # End of Module\r
 \r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
index ba07998..7c5e206 100755 (executable)
@@ -17,6 +17,9 @@
 import os\r
 import sys\r
 import string\r
+import thread\r
+import threading\r
+import time\r
 \r
 ## callback routine for processing variable option\r
 #\r
@@ -93,17 +96,27 @@ def GuidStructureStringToGuidValueName(GuidValue):
             int(guidValueList[10], 16)\r
             )\r
 \r
-def SaveFileOnChange(file, content):\r
-    f = None\r
-    if os.path.exists(file):\r
-        f = open(file, "r")\r
-        if content == f.read():\r
-            f.close()\r
-            return\r
-        f.close()\r
-    f = open(file, "w")\r
-    f.write(content)\r
-    f.close()\r
+def CreateDirectory(Directory):\r
+    if not os.access(Directory, os.F_OK):\r
+        os.makedirs(Directory)\r
+\r
+def SaveFileOnChange(File, Content, IsBinaryFile=False):\r
+    if IsBinaryFile:\r
+        BinaryFlag = 'b'\r
+    else:\r
+        BinaryFlag = ''\r
+    Fd = None\r
+    if os.path.exists(File):\r
+        Fd = open(File, "r"+BinaryFlag)\r
+        if Content == Fd.read():\r
+            Fd.close()\r
+            return False\r
+        Fd.close()\r
+    CreateDirectory(os.path.dirname(File))\r
+    Fd = open(File, "w"+BinaryFlag)\r
+    Fd.write(Content)\r
+    Fd.close()\r
+    return True\r
 \r
 class TemplateString(object):\r
     def __init__(self):\r
@@ -115,39 +128,67 @@ class TemplateString(object):
     def Append(self, AppendString, Dictionary=None):\r
         if Dictionary == None:\r
             self.String += AppendString\r
-        else:\r
-            while AppendString.find('${BEGIN}') >= 0:\r
-                Start = AppendString.find('${BEGIN}')\r
-                End   = AppendString.find('${END}')\r
-                SubString = AppendString[AppendString.find('${BEGIN}'):AppendString.find('${END}')+6]\r
-\r
-                RepeatTime = -1\r
-                NewDict = {"BEGIN":"", "END":""}\r
-                for Key in Dictionary:\r
-                    if SubString.find('$' + Key) >= 0 or SubString.find('${' + Key + '}') >= 0:\r
-                        Value = Dictionary[Key]\r
-                        if type(Value) != type([]):\r
-                            NewDict[Key] = Value\r
-                            continue\r
-                        if RepeatTime < 0:\r
-                            RepeatTime = len(Value)\r
-                        elif RepeatTime != len(Value):\r
-                            raise AutoGenError(msg=Key + " has different repeat time from others!")\r
-                        NewDict[Key] = ""\r
-\r
-                NewString = ''\r
-                for Index in range(0, RepeatTime):\r
-                    for Key in NewDict:\r
-                        if Key == "BEGIN" or Key == "END" or type(Dictionary[Key]) != type([]):\r
-                            continue\r
-                        #print "###",Key\r
-                        NewDict[Key] = Dictionary[Key][Index]\r
-                    NewString += string.Template(SubString).safe_substitute(NewDict)\r
-                AppendString = AppendString[0:Start] + NewString + AppendString[End + 6:]\r
-\r
-            NewDict = {}\r
+            return\r
+\r
+        while AppendString.find('${BEGIN}') >= 0:\r
+            Start = AppendString.find('${BEGIN}')\r
+            End   = AppendString.find('${END}')\r
+            SubString = AppendString[AppendString.find('${BEGIN}'):AppendString.find('${END}')+6]\r
+\r
+            RepeatTime = -1\r
+            NewDict = {"BEGIN":"", "END":""}\r
             for Key in Dictionary:\r
-                if type(Dictionary[Key]) == type([]):\r
-                    continue\r
-                NewDict[Key] = Dictionary[Key]\r
-            self.String += string.Template(AppendString).safe_substitute(NewDict)\r
+                if SubString.find('$' + Key) >= 0 or SubString.find('${' + Key + '}') >= 0:\r
+                    Value = Dictionary[Key]\r
+                    if type(Value) != type([]):\r
+                        NewDict[Key] = Value\r
+                        continue\r
+                    if RepeatTime < 0:\r
+                        RepeatTime = len(Value)\r
+                    elif RepeatTime != len(Value):\r
+                        raise AutoGenError(msg=Key + " has different repeat time from others!")\r
+                    NewDict[Key] = ""\r
+\r
+            NewString = ''\r
+            for Index in range(0, RepeatTime):\r
+                for Key in NewDict:\r
+                    if Key == "BEGIN" or Key == "END" or type(Dictionary[Key]) != type([]):\r
+                        continue\r
+                    NewDict[Key] = Dictionary[Key][Index]\r
+                NewString += string.Template(SubString).safe_substitute(NewDict)\r
+            AppendString = AppendString[0:Start] + NewString + AppendString[End + 6:]\r
+\r
+        NewDict = {}\r
+        for Key in Dictionary:\r
+            if type(Dictionary[Key]) == type([]):\r
+                continue\r
+            NewDict[Key] = Dictionary[Key]\r
+        self.String += string.Template(AppendString).safe_substitute(NewDict)\r
+\r
+class Progressor:\r
+    def __init__(self, OpenMessage="", CloseMessage="", ProgressChar='.', Interval=1):\r
+        self.StopFlag = threading.Event()\r
+        self.StopFlag.clear()\r
+\r
+        self.ProgressThread = None\r
+        self.PromptMessage = OpenMessage\r
+        self.CodaMessage = CloseMessage\r
+        self.ProgressChar = ProgressChar\r
+        self.Interval = Interval\r
+\r
+    def Start(self):\r
+        self.ProgressThread = threading.Thread(target=self._ProgressThreadEntry)\r
+        self.ProgressThread.setDaemon(True)\r
+        self.ProgressThread.start()\r
+\r
+    def Stop(self):\r
+        self.StopFlag.set()\r
+        self.ProgressThread.join()\r
+        self.ProgressThread = None\r
+\r
+    def _ProgressThreadEntry(self):\r
+        print self.PromptMessage,\r
+        while not self.StopFlag.isSet():\r
+            time.sleep(self.Interval)\r
+            print self.ProgressChar,\r
+        print self.CodaMessage\r
index bbe395b..39a7991 100755 (executable)
 #\r
 \r
 import os\r
+import re\r
 import EdkLogger\r
 \r
 from Dictionary import *\r
 from BuildToolError import *\r
 from TargetTxtClassObject import *\r
 \r
+gMacroRefPattern = re.compile("(DEF\([^\(\)]+\))")\r
+gMacroDefPattern = re.compile("DEFINE\s+([^\s]+)")\r
+\r
 class ToolDefClassObject(object):\r
-    def __init__(self, filename = None):\r
+    def __init__(self, FileName = None):\r
         self.ToolsDefTxtDictionary = {}\r
-        \r
-        self.ToolsDefTxtDatabase = {\r
-            TAB_TOD_DEFINES_TARGET                                             : [],\r
-            TAB_TOD_DEFINES_TOOL_CHAIN_TAG                             : [],\r
-            TAB_TOD_DEFINES_TARGET_ARCH                                    : [],\r
-            TAB_TOD_DEFINES_COMMAND_TYPE                                 : []\r
-        }\r
-        if filename != None:\r
-            self.LoadToolDefFile(filename)\r
-\r
-    def LoadToolDefFile(self, filename):\r
-        #EdkLogger.info('LoadToolDefFile() Start')\r
-        if os.path.exists(filename) and os.path.isfile(filename):\r
-            if ConvertTextFileToDictionary(filename, self.ToolsDefTxtDictionary, '#', '=', False, None) == 1:\r
-                return 1\r
+        self.MacroDictionary = {}\r
+        self.EnvronDictionary = {}\r
+        for Env in os.environ:\r
+            self.EnvronDictionary["ENV(%s)" % Env] = os.environ[Env]\r
+\r
+        if FileName != None:\r
+            self.LoadToolDefFile(FileName)\r
+\r
+    def LoadToolDefFile(self, FileName):\r
+        FileContent = []\r
+        if os.path.isfile(FileName):\r
+            try:\r
+                F = open(FileName,'r')\r
+                FileContent = F.readlines()\r
+            except:\r
+                raise ParserError(FILE_OPEN_FAILURE, name=FileName)\r
         else:\r
-            raise ParseError('LoadTargetTxtFile() : No Target.txt file exist')\r
-            return 1\r
-        \r
+            raise ParserError(FILE_NOT_FOUND, name=FileName)\r
+\r
         self.ToolsDefTxtDatabase = {\r
-            TAB_TOD_DEFINES_TARGET                                             : [],\r
-            TAB_TOD_DEFINES_TOOL_CHAIN_TAG                             : [],\r
-            TAB_TOD_DEFINES_TARGET_ARCH                                    : [],\r
-            TAB_TOD_DEFINES_COMMAND_TYPE                                 : []\r
+            TAB_TOD_DEFINES_TARGET          :   [],\r
+            TAB_TOD_DEFINES_TOOL_CHAIN_TAG  :   [],\r
+            TAB_TOD_DEFINES_TARGET_ARCH     :   [],\r
+            TAB_TOD_DEFINES_COMMAND_TYPE    :   []\r
         }\r
 \r
-        for Key in dict(self.ToolsDefTxtDictionary):\r
-            List = Key.split('_')\r
+        for Index in range(len(FileContent)):\r
+            Line = FileContent[Index].strip()\r
+            if Line == "" or Line[0] == '#':\r
+                continue\r
+            NameValuePair = Line.split("=", 1)\r
+            if len(NameValuePair) != 2:\r
+                EdkLogger.warn("Line %d: not correct assignment statement, skipped" % (Index + 1))\r
+                continue\r
+\r
+            Name = NameValuePair[0].strip()\r
+            Value = NameValuePair[1].strip()\r
+\r
+            if Name == "IDENTIFIER":\r
+                EdkLogger.verbose("Line %d: Found identifier statement, skipped: %s" % ((Index + 1), Value))\r
+                continue\r
+\r
+            MacroDefinition = gMacroDefPattern.findall(Name)\r
+            if MacroDefinition != []:\r
+                MacroName = MacroDefinition[0].strip()\r
+                self.MacroDictionary["DEF(%s)" % MacroName] = Value\r
+                EdkLogger.verbose("Line %d: Found macro: %s = %s" % ((Index + 1), MacroName, Value))\r
+                continue\r
+\r
+            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
+                Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
+\r
+            List = Name.split('_')\r
             if len(List) != 5:\r
-                del self.ToolsDefTxtDictionary[Key]\r
+                EdkLogger.verbose("Line %d: Not a valid name of definition: %s" % ((Index + 1), Name))\r
+                continue\r
             elif List[4] == '*':\r
-                del self.ToolsDefTxtDictionary[Key]\r
+                EdkLogger.verbose("Line %d: '*' is not allowed in last field: %s" % ((Index + 1), Name))\r
+                continue\r
             else:\r
+                self.ToolsDefTxtDictionary[Name] = Value\r
                 if List[0] != '*':\r
                     self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] += [List[0]]\r
                 if List[1] != '*':\r
@@ -62,10 +97,12 @@ class ToolDefClassObject(object):
                     self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] += [List[2]]\r
                 if List[3] != '*':\r
                     self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] += [List[3]]\r
+\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]                 = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]))\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]))\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]        = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]))\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]     = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]))\r
+\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort()\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort()\r
         self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort()\r
@@ -85,8 +122,6 @@ class ToolDefClassObject(object):
                     del self.ToolsDefTxtDictionary[Key]\r
                 elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:\r
                     del self.ToolsDefTxtDictionary[Key]\r
-        return 0\r
-        #EdkLogger.info('LoadToolDefFile() End')\r
 \r
 def ToolDefDict(WorkSpace):\r
     Target = TargetTxtClassObject()\r
@@ -94,10 +129,10 @@ def ToolDefDict(WorkSpace):
     ToolDef = ToolDefClassObject()\r
     ToolDef.LoadToolDefFile(WorkSpace + '\\' + Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])\r
     return ToolDef\r
-        \r
+\r
 if __name__ == '__main__':\r
 ##    td = ToolDefClassObject('tool_def.txt')\r
 ##    print td.ToolsDefTxtDatabase\r
 \r
     ToolDef = ToolDefDict(os.getenv("WORKSPACE"))\r
-    pass
\ No newline at end of file
+    pass\r
index 86c2f77..bf89976 100644 (file)
@@ -105,6 +105,10 @@ def TrimPreprocessedFile(Source, Target, Convert):
         else:
             NewLines.append(Line)
 
+    # in case there's no line directive or linemarker found
+    if NewLines == []:
+        NewLines = Lines
+
     # save to file
     f = open (Target, 'w')
     f.writelines(NewLines)
index ac435bc..4806064 100644 (file)
@@ -237,7 +237,7 @@ class Build():
         FileNum = len(FileList)\r
         if FileNum > 0:\r
             self.SameTypeFileInDir(FileNum, 'makefile', DestDir)\r
-            self.Launch(["nmake", "/nologo", "-f", FileList[0], self.Args], os.path.dirname(FileList[0]))\r
+            self.Launch(["nmake", "/nologo", self.Args], os.path.dirname(FileList[0]))\r
         else:\r
             self.isexit(1)\r
 \r
@@ -245,16 +245,11 @@ class Build():
         try:\r
             AutoGenResult = AutoGen(ModuleFile, PlatformFile, ewb, Target, ToolChain, Arch)\r
             AutoGenResult.CreateAutoGenFile()\r
-            makefile = AutoGenResult.CreateMakefile()\r
+            AutoGenResult.CreateMakefile()\r
         except Exception, e:\r
             self.TrackInfo(e)\r
             self.isexit(1)\r
-        if makefile != "":\r
-            self.Launch(["nmake", "/nologo", "-f", makefile, 'all'], os.path.dirname(makefile))\r
-        else:\r
-            EdkLogger.quiet("ERROR: Can find Makefile: %s. % makefile")\r
-            self.isexit(1)\r
-\r
+        self.Launch(["nmake", "/nologo", 'all'], os.path.join(os.environ["WORKSPACE"], AutoGenResult.GetMakefileDir()))\r
 \r
     def Process(self, ModuleFile, PlatformFile, ewb):\r
         #\r
@@ -471,7 +466,6 @@ def main():
     build = Build(opt, args)\r
     StatusCode = build.CheckEnvVariable()\r
     build.isexit(StatusCode)\r
-\r
 #\r
 # Check target.txt and tools_def.txt and Init them\r
 #\r
@@ -479,15 +473,14 @@ def main():
         StatusCode = build.TargetTxt.LoadTargetTxtFile(os.path.normpath(os.path.join(build.WorkSpace, 'Conf\\target.txt')))\r
         build.isexit(StatusCode)\r
         if os.path.isfile(os.path.normpath(os.path.join(build.WorkSpace, build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]))) == True:\r
-            StatusCode = build.ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(build.WorkSpace, build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])))\r
+            build.ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(build.WorkSpace, build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])))\r
             build.isexit(StatusCode)\r
         else:\r
-            EdkLogger.quiet("ERROR: %s does not exist." % os.path.normpath(os.path.join(build.WorkSpace, build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])))\r
+            EdkLogger.info("ERROR: %s does not exist." % os.path.normpath(os.path.join(build.WorkSpace, build.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])))\r
             build.isexit(1)\r
     else:\r
-        EdkLogger.quiet("ERROR: %s does not exist." % os.path.normpath(os.path.join(build.WorkSpace, 'Conf\\target.txt')))\r
+        EdkLogger.info("ERROR: %s does not exist." % os.path.normpath(os.path.join(build.WorkSpace, 'Conf\\target.txt')))\r
         build.isexit(1)\r
-\r
 #\r
 # Merge the Build Options except input file(DSCFILE, FDFFILE)\r
 #\r