git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@381 7335b...
authorhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 24 Jul 2007 06:09:27 +0000 (06:09 +0000)
committerhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 24 Jul 2007 06:09:27 +0000 (06:09 +0000)
Source/Python/Common/DscClassObject.py
Source/Python/Common/EdkIIWorkspaceBuild.py
Source/Python/Common/String.py

index d6e305d..d0364a4 100644 (file)
@@ -16,7 +16,8 @@ from String import *
 from DataType import *\r
 from Identification import *\r
 from Dictionary import *\r
-from ClassObjects.PlatformClassObject import *\r
+from CommonDataClass.PlatformClass import *\r
+from BuildToolError import *\r
 \r
 class DscObject(object):\r
     def __init__(self):\r
@@ -61,10 +62,12 @@ class DscContents(DscObject):
         self.BuildOptions = []\r
 \r
 class Dsc(DscObject):\r
-    def __init__(self, filename = None, isMergeAllArches = False):\r
+    def __init__(self, filename = None, isMergeAllArches = False, isToPlatform = False):\r
         self.identification = Identification()\r
         self.Defines = DscDefines()\r
         self.Contents = {}\r
+        self.UserExtensions = ''\r
+        self.Platform = PlatformClass()\r
 \r
         for key in DataType.ARCH_LIST_FULL:\r
             self.Contents[key] = DscContents()\r
@@ -83,6 +86,9 @@ class Dsc(DscObject):
         if isMergeAllArches:\r
             self.MergeAllArches()\r
         \r
+        if isToPlatform:\r
+            self.DscToPlatform()\r
+        \r
     def ParseDsc(self, Lines, Key, KeyField):\r
         newKey = SplitModuleType(Key)     \r
         if newKey[0].find(TAB_LIBRARY_CLASSES.upper()) != -1:\r
@@ -125,6 +131,18 @@ class Dsc(DscObject):
                             eval(Command)\r
                             continue\r
 \r
+    def DscToPlatform(self):\r
+        #\r
+        # Get value for Header\r
+        #\r
+        self.Module.Header.Name = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_PLATFORM_NAME][0]\r
+        self.Module.Header.Guid = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_PLATFORM_GUID][0]\r
+        self.Module.Header.Version = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_PLATFORM_VERSION][0]\r
+        self.Module.Header.FileName = self.Identification.FileName\r
+        self.Module.Header.FullPath = self.Identification.FileFullPath\r
+        self.Module.Header.InfVersion = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_DSC_SPECIFICATION][0]\r
+        \r
+        \r
     def showDsc(self):\r
         print TAB_SECTION_START + TAB_INF_DEFINES + TAB_SECTION_END\r
         printDict(self.Defines.DefinesDictionary)\r
index 35f1a04..7a9561b 100644 (file)
@@ -24,10 +24,8 @@ from InfClassObject import *
 from DecClassObject import *\r
 from DscClassObject import *\r
 from String import *\r
-from ClassObjects.CommonClassObject import *\r
-#from FdfParser import *\r
 from BuildToolError import *\r
-#from Region import *\r
+\r
 \r
 class ModuleSourceFilesClassObject(object):\r
     def __init__(self, SourceFile = '', PcdFeatureFlag = '', TagName = '', ToolCode = '', ToolChainFamily = '', String = ''):\r
@@ -39,6 +37,9 @@ class ModuleSourceFilesClassObject(object):
         self.PcdFeatureFlag     = PcdFeatureFlag\r
     \r
     def __str__(self):\r
+        return self.SourceFile\r
+    \r
+    def __repr__(self):\r
         rtn = self.SourceFile + DataType.TAB_VALUE_SPLIT + \\r
               self.PcdFeatureFlag + DataType.TAB_VALUE_SPLIT + \\r
               self.ToolChainFamily +  DataType.TAB_VALUE_SPLIT + \\r
@@ -86,7 +87,7 @@ class PcdClassObject(object):
         return rtn\r
 \r
     def __eq__(self, other):\r
-        return self.TokenCName == other.TokenCName and self.TokenSpaceGuidCName == other.TokenSpaceGuidCName\r
+        return other != None and self.TokenCName == other.TokenCName and self.TokenSpaceGuidCName == other.TokenSpaceGuidCName\r
 \r
     def __hash__(self):\r
         return hash((self.TokenCName, self.TokenSpaceGuidCName))\r
@@ -194,16 +195,12 @@ class ItemBuild(object):
         self.ModuleDatabase          = {}        #{ [InfFileName] : ModuleBuildClassObject, ...}\r
         \r
 class WorkspaceBuild(object):\r
-    def __init__(self, ActivePlatform = None):\r
-        self.Workspace               = EdkIIWorkspace()\r
-        self.PrintRunTime            = True\r
-        self.PlatformBuild           = True\r
-        self.TargetTxt               = TargetTxtClassObject()\r
-        self.ToolDef                 = ToolDefClassObject()\r
-\r
+    def __init__(self, ActivePlatform, WorkspaceDir):\r
+        self.WorkspaceDir            = NormPath(WorkspaceDir)\r
         self.SupArchList             = []        #[ 'IA32', 'X64', ...]\r
         self.BuildTarget             = []        #[ 'RELEASE', 'DEBUG']\r
         self.SkuId                   = ''\r
+        self.Fdf                     = ''\r
         \r
         self.InfDatabase             = {}        #{ [InfFileName] : InfClassObject}\r
         self.DecDatabase             = {}        #{ [DecFileName] : DecClassObject}\r
@@ -213,22 +210,15 @@ class WorkspaceBuild(object):
         for key in DataType.ARCH_LIST:\r
             self.Build[key] = ItemBuild(key)\r
         \r
-        self.TargetTxt.LoadTargetTxtFile(self.Workspace.WorkspaceFile('Conf/target.txt'))\r
-        self.ToolDef.LoadToolDefFile(self.Workspace.WorkspaceFile('Conf/tools_def.txt'))\r
-        \r
-        if ActivePlatform != None:\r
-            self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM][0] = ActivePlatform\r
-        \r
-        #get active platform\r
-        dscFileName = NormPath(self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM][0])\r
-        file = self.Workspace.WorkspaceFile(dscFileName)\r
-        if os.path.exists(file) and os.path.isfile(file):\r
-            self.DscDatabase[dscFileName] = Dsc(file, True)\r
+        # Get active platform\r
+        dscFileName = NormPath(ActivePlatform)\r
+        File = self.WorkspaceFile(dscFileName)\r
+        if os.path.exists(File) and os.path.isfile(File):\r
+            self.DscDatabase[dscFileName] = Dsc(File, True)\r
         else:\r
-            EdkLogger.verbose('No Active Platform')\r
-            return\r
+            raise ParserError(FILE_NOT_FOUND, name = File)\r
         \r
-        #parse platform to get module\r
+        # parse platform to get module\r
         for dsc in self.DscDatabase.keys():\r
             dscObj = self.DscDatabase[dsc]\r
             \r
@@ -261,7 +251,15 @@ class WorkspaceBuild(object):
             for key in DataType.ARCH_LIST:\r
                 for index in range(len(infObj.Contents[key].Packages)):\r
                     self.AddToDecDatabase(infObj.Contents[key].Packages[index])\r
-        \r
+    #End of self.Init()\r
+    \r
+    #\r
+    # Return a full path with workspace dir\r
+    #\r
+    def WorkspaceFile(self, Filename):\r
+        return os.path.join(self.WorkspaceDir, Filename)\r
+    \r
+    def GenBuildDatabase(self, PcdsSet = {}):\r
         #Build databases\r
         #Build PlatformDatabase\r
         for dsc in self.DscDatabase.keys():\r
@@ -314,9 +312,10 @@ class WorkspaceBuild(object):
                     \r
                 #LibraryClass\r
                 for index in range(len(dscObj.Contents[key].LibraryClasses)):\r
-                    #['DebugLib|MdePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf', 'DXE_CORE']\r
+                    #['DebugLib|MdePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf', ['DXE_CORE']]\r
+                    print dscObj.Contents[key].LibraryClasses[index]\r
                     list = dscObj.Contents[key].LibraryClasses[index][0].split(DataType.TAB_VALUE_SPLIT, 1)\r
-                    type = dscObj.Contents[key].LibraryClasses[index][1]\r
+                    type = dscObj.Contents[key].LibraryClasses[index][1][0]\r
                     pb.LibraryClasses[(list[0], type)] = NormPath(list[1])\r
 \r
                 #Pcds\r
@@ -658,14 +657,14 @@ class WorkspaceBuild(object):
         \r
         #End of build ModuleDatabase    \r
     \r
-    #End of self.Init\r
+\r
     \r
     def UpdateInfDatabase(self, infFileName, LibraryClass, Arch):\r
         infFileName = NormPath(infFileName)\r
         LibList = self.InfDatabase[infFileName].Contents[Arch].LibraryClasses\r
         NotFound = True\r
         for Item in LibList:\r
-            LibName = Item.split(DataType.TAB_VALUE_SPLIT)[0].strip()\r
+            LibName = Item[0].split(DataType.TAB_VALUE_SPLIT)[0].strip()\r
             if LibName == LibraryClass:\r
                 return\r
         \r
@@ -674,14 +673,14 @@ class WorkspaceBuild(object):
     \r
     def AddToInfDatabase(self, infFileName):\r
         infFileName = NormPath(infFileName)\r
-        file = self.Workspace.WorkspaceFile(infFileName)\r
+        file = self.WorkspaceFile(infFileName)\r
         if os.path.exists(file) and os.path.isfile(file):\r
             if infFileName not in self.InfDatabase:\r
                 self.InfDatabase[infFileName] = Inf(file, True)\r
                 \r
     def AddToDecDatabase(self, decFileName):\r
         decFileName = NormPath(decFileName)\r
-        file = self.Workspace.WorkspaceFile(decFileName)\r
+        file = self.WorkspaceFile(decFileName)\r
         if os.path.exists(file) and os.path.isfile(file):\r
             if decFileName not in self.DecDatabase:\r
                 self.DecDatabase[decFileName] = Dec(file, True)\r
@@ -770,12 +769,11 @@ class WorkspaceBuild(object):
 if __name__ == '__main__':\r
 \r
     # Nothing to do here. Could do some unit tests.\r
-    ewb = WorkspaceBuild()\r
-    #printDict(ewb.TargetTxt.TargetTxtDictionary)\r
-    #printDict(ewb.ToolDef.ToolsDefTxtDictionary)\r
-#    print ewb.DscDatabase\r
-#    print ewb.InfDatabase\r
-#    print ewb.DecDatabase\r
+    ewb = WorkspaceBuild('EdkModulePkg/EdkModulePkg.dsc', 'C:/MyWorkspace')\r
+    ewb.GenBuildDatabase()\r
+    #print ewb.DscDatabase\r
+    #print ewb.InfDatabase\r
+    #print ewb.DecDatabase\r
     print 'SupArchList', ewb.SupArchList\r
     print 'BuildTarget', ewb.BuildTarget\r
     print 'SkuId', ewb.SkuId\r
index 43e9cd7..ab00c1e 100644 (file)
@@ -231,11 +231,11 @@ def CleanString(Line, CommentCharacter = DataType.TAB_COMMENT_SPLIT):
     #remove comments\r
     Line = Line.split(CommentCharacter, 1)[0];\r
     #replace '\\', '\' with '/'\r
-    #Line = Line.replace('\\', '/')\r
-    #Line = Line.replace('//', '/')\r
+    Line = Line.replace('\\', '/')\r
+    Line = Line.replace('//', '/')\r
     #remove ${WORKSPACE}\r
-    #Line = Line.replace(DataType.TAB_WORKSPACE1, '')\r
-    #Line = Line.replace(DataType.TAB_WORKSPACE2, '')\r
+    Line = Line.replace(DataType.TAB_WORKSPACE1, '')\r
+    Line = Line.replace(DataType.TAB_WORKSPACE2, '')\r
     \r
     #remove whitespace again\r
     Line = Line.strip();\r