git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@417 7335b...
[people/mcb30/basetools.git] / Source / Python / Common / EdkIIWorkspaceBuild.py
index 7a9561b..c97c74f 100644 (file)
 import os, string, copy, pdb\r
 import EdkLogger\r
 import DataType\r
-from EdkIIWorkspace import *\r
-from TargetTxtClassObject import *\r
-from ToolDefClassObject import *\r
 from InfClassObject import *\r
 from DecClassObject import *\r
 from DscClassObject import *\r
 from String import *\r
 from BuildToolError import *\r
-\r
+from CommonDataClass.CommonClass import *\r
 \r
 class ModuleSourceFilesClassObject(object):\r
     def __init__(self, SourceFile = '', PcdFeatureFlag = '', TagName = '', ToolCode = '', ToolChainFamily = '', String = ''):\r
@@ -188,8 +185,8 @@ class PlatformBuildClassObject(object):
         return hash(self.DescFilePath)\r
 \r
 class ItemBuild(object):\r
-    def __init__(self, arch, platform = None, package = None, module = None):\r
-        self.Arch                    = arch\r
+    def __init__(self, Arch, Platform = None, Package = None, Module = None):\r
+        self.Arch                    = Arch\r
         self.PlatformDatabase        = {}        #{ [DscFileName] : PlatformBuildClassObject, ...}\r
         self.PackageDatabase         = {}        #{ [DecFileName] : PacakgeBuildClassObject, ...}\r
         self.ModuleDatabase          = {}        #{ [InfFileName] : ModuleBuildClassObject, ...}\r
@@ -201,63 +198,80 @@ class WorkspaceBuild(object):
         self.BuildTarget             = []        #[ 'RELEASE', 'DEBUG']\r
         self.SkuId                   = ''\r
         self.Fdf                     = ''\r
+        self.TargetTxt               = None\r
+        self.ToolDef                 = None\r
         \r
         self.InfDatabase             = {}        #{ [InfFileName] : InfClassObject}\r
         self.DecDatabase             = {}        #{ [DecFileName] : DecClassObject}\r
         self.DscDatabase             = {}        #{ [DscFileName] : DscClassObject}\r
         \r
         self.Build                   = {}\r
-        for key in DataType.ARCH_LIST:\r
-            self.Build[key] = ItemBuild(key)\r
+        for Arch in DataType.ARCH_LIST:\r
+            self.Build[Arch] = ItemBuild(Arch)\r
         \r
+        #\r
         # Get active platform\r
-        dscFileName = NormPath(ActivePlatform)\r
-        File = self.WorkspaceFile(dscFileName)\r
+        #\r
+        DscFileName = ActivePlatform\r
+        File = self.WorkspaceFile(NormPath(DscFileName))\r
         if os.path.exists(File) and os.path.isfile(File):\r
-            self.DscDatabase[dscFileName] = Dsc(File, True)\r
+            self.DscDatabase[DscFileName] = Dsc(File, True, True)\r
         else:\r
             raise ParserError(FILE_NOT_FOUND, name = File)\r
         \r
+        #\r
         # parse platform to get module\r
-        for dsc in self.DscDatabase.keys():\r
-            dscObj = self.DscDatabase[dsc]\r
+        #\r
+        for DscFile in self.DscDatabase.keys():\r
+            Platform = self.DscDatabase[DscFile].Platform\r
             \r
             #\r
             # Get global information\r
             #\r
-            self.SupArchList = dscObj.Defines.DefinesDictionary[TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES]\r
-            self.BuildTarget = dscObj.Defines.DefinesDictionary[TAB_DSC_DEFINES_BUILD_TARGETS]\r
-            self.SkuId = dscObj.Defines.DefinesDictionary[TAB_DSC_DEFINES_SKUID_IDENTIFIER][0]\r
+            self.SupArchList = Platform.Header.SupArchList\r
+            self.BuildTarget = Platform.Header.BuildTargets\r
+            self.SkuId = Platform.Header.SkuIdName\r
+            self.Fdf = Platform.FlashDefinitionFile.FilePath\r
             \r
-            #Get all inf\r
-            for key in DataType.ARCH_LIST:\r
-                for index in range(len(dscObj.Contents[key].LibraryClasses)):\r
-                    self.AddToInfDatabase(dscObj.Contents[key].LibraryClasses[index][0].split(DataType.TAB_VALUE_SPLIT, 1)[1])\r
-                for index in range(len(dscObj.Contents[key].Components)):\r
-                    Module = dscObj.Contents[key].Components[index][0]\r
-                    LibList = dscObj.Contents[key].Components[index][1]\r
+            #\r
+            # Get all inf files\r
+            #\r
+            for Item in Platform.Libraries.LibraryList:\r
+                for Arch in Item.SupArchList:\r
+                    self.AddToInfDatabase(Item.FilePath)\r
+            \r
+            for Item in Platform.Modules.ModuleList:\r
+                for Arch in Item.SupArchList:\r
+                    #\r
+                    # Add modules\r
+                    #\r
+                    Module = Item.FilePath\r
                     self.AddToInfDatabase(Module)\r
-                    for indexOfLib in range(len(LibList)):\r
-                        Lib = LibList[indexOfLib]\r
-                        if len(Lib.split(DataType.TAB_VALUE_SPLIT)) == 2:\r
-                            self.AddToInfDatabase(CleanString(Lib.split(DataType.TAB_VALUE_SPLIT)[1]))\r
-                            self.UpdateInfDatabase(Module, CleanString(Lib.split(DataType.TAB_VALUE_SPLIT)[0]), key)\r
+                    #\r
+                    # Add library used in modules\r
+                    #\r
+                    for Lib in Item.LibraryClasses.LibraryList:\r
+                        self.AddToInfDatabase(Lib.FilePath)\r
+                        self.UpdateLibraryClassOfModule(Module, Lib.Name, Arch)\r
         #End For of Dsc\r
         \r
         #parse module to get package\r
-        for inf in self.InfDatabase.keys():\r
-            infObj = self.InfDatabase[inf]\r
+        for InfFile in self.InfDatabase.keys():\r
+            Module = self.InfDatabase[InfFile].Module\r
             #Get all dec\r
-            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
+            for Item in Module.PackageDependencies:\r
+                for Arch in Item.SupArchList:\r
+                    self.AddToDecDatabase(Item.FilePath)\r
+#            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
     #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
+        return os.path.join(os.path.normpath(self.WorkspaceDir), os.path.normpath(Filename))\r
     \r
     def GenBuildDatabase(self, PcdsSet = {}):\r
         #Build databases\r
@@ -276,7 +290,7 @@ class WorkspaceBuild(object):
                 pb.FlashDefinition = NormPath(dscObj.Defines.DefinesDictionary[DataType.TAB_DSC_DEFINES_FLASH_DEFINITION][0])\r
                 pb.BuildNumber = dscObj.Defines.DefinesDictionary[DataType.TAB_DSC_DEFINES_BUILD_NUMBER][0]\r
                 pb.MakefileName = NormPath(dscObj.Defines.DefinesDictionary[DataType.TAB_DSC_DEFINES_MAKEFILE_NAME][0])\r
-        \r
+                \r
                 #SkuId\r
                 for index in range(len(dscObj.Contents[key].SkuIds)):\r
                     SkuInfo = dscObj.Contents[key].SkuIds[index]\r
@@ -313,7 +327,6 @@ class WorkspaceBuild(object):
                 #LibraryClass\r
                 for index in range(len(dscObj.Contents[key].LibraryClasses)):\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][0]\r
                     pb.LibraryClasses[(list[0], type)] = NormPath(list[1])\r
@@ -339,12 +352,12 @@ class WorkspaceBuild(object):
                     pcd.append(None)\r
                     SkuName = dscObj.Contents[key].PcdsDynamicDefault[index][1]\r
                     SkuInfoList = []\r
-                    if SkuName == None:\r
-                        SkuName = 'DEFAULT'\r
-                    SkuNameList = map(lambda l: l.strip(), SkuName.split(DataType.TAB_VALUE_SPLIT))\r
+                    if SkuName == None or SkuName == [] or SkuName == ['']:\r
+                        SkuName = ['DEFAULT']\r
+                    SkuNameList = map(lambda l: l.strip(), SkuName[0].split(DataType.TAB_VALUE_SPLIT))\r
                     for Item in SkuNameList:\r
-                        SkuInfo = SkuInfoClassObject()\r
-                        SkuInfo.SkuId = pb.SkuIds[Item]\r
+                        SkuInfo = SkuInfoClass()\r
+                        SkuInfo.SkuId = Item[1]\r
                         SkuInfo.DefaultValue = pcd[2]\r
                         SkuInfoList.append(SkuInfo)\r
                     pb.Pcds[(pcd[0], pcd[1])] = PcdClassObject(pcd[0], pcd[1], DataType.TAB_PCDS_DYNAMIC_DEFAULT, None, None, None, pcd[3], SkuInfoList)\r
@@ -607,7 +620,7 @@ class WorkspaceBuild(object):
                 #LibraryClasses\r
                 for index in range(len(infObj.Contents[key].LibraryClasses)):\r
                     #Get LibraryClass name and default instance if existing\r
-                    list = infObj.Contents[key].LibraryClasses[index].split(DataType.TAB_VALUE_SPLIT)\r
+                    list = infObj.Contents[key].LibraryClasses[index][0].split(DataType.TAB_VALUE_SPLIT)\r
                     if len(list) < 2:\r
                         v = ''\r
                     else:\r
@@ -655,35 +668,52 @@ class WorkspaceBuild(object):
         \r
         #End of Inf Go Through\r
         \r
-        #End of build ModuleDatabase    \r
+        #End of build ModuleDatabase\r
     \r
-\r
-    \r
-    def UpdateInfDatabase(self, infFileName, LibraryClass, Arch):\r
-        infFileName = NormPath(infFileName)\r
-        LibList = self.InfDatabase[infFileName].Contents[Arch].LibraryClasses\r
+    def UpdateLibraryClassOfModule(self, InfFileName, LibraryClass, Arch):\r
+        LibList = self.InfDatabase[NormPath(InfFileName)].Module.LibraryClasses\r
         NotFound = True\r
-        for Item in LibList:\r
-            LibName = Item[0].split(DataType.TAB_VALUE_SPLIT)[0].strip()\r
-            if LibName == LibraryClass:\r
-                return\r
-        \r
+        for Lib in LibList:\r
+            #\r
+            # Find this LibraryClass\r
+            #\r
+            if Lib.LibraryClass == LibraryClass:\r
+                if Arch in Lib.SupArchList:\r
+                    return\r
+                else:\r
+                    Lib.SupArchList.append(Arch)\r
+                    return\r
         if NotFound:\r
-            self.InfDatabase[infFileName].Contents[Arch].LibraryClasses.extend([LibraryClass])\r
+            Lib = LibraryClassClass()\r
+            Lib.LibraryClass = LibraryClass\r
+            Lib.SupArchList = [Arch]\r
+                \r
     \r
-    def AddToInfDatabase(self, infFileName):\r
-        infFileName = NormPath(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
+#    def UpdateInfDatabase(self, InfFileName, LibraryClass, Arch):\r
+#        InfFileName = NormPath(InfFileName)\r
+#        LibList = self.InfDatabase[InfFileName].Contents[Arch].LibraryClasses\r
+#        LibList = self.InfDatabase[InfFileName].Module.LibraryClasses\r
+#        NotFound = True\r
+#        for Lib in LibList:\r
+#            if Lib.LibraryClass == LibraryClass and Arch in Lib.SupArchList:\r
+#                return\r
+#        \r
+#        if NotFound:\r
+#            self.InfDatabase[infFileName].Module.Contents[Arch].LibraryClasses.extend([LibraryClass])\r
+    \r
+    def AddToInfDatabase(self, InfFileName):\r
+        InfFileName = NormPath(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, True)\r
                 \r
-    def AddToDecDatabase(self, decFileName):\r
-        decFileName = NormPath(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
+    def AddToDecDatabase(self, DecFileName):\r
+        DecFileName = NormPath(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, True)\r
                 \r
     def FindLibraryClassInstanceOfModule(self, lib, arch, moduleType, moduleName):\r
         for dsc in self.DscDatabase.keys():\r
@@ -769,7 +799,8 @@ class WorkspaceBuild(object):
 if __name__ == '__main__':\r
 \r
     # Nothing to do here. Could do some unit tests.\r
-    ewb = WorkspaceBuild('EdkModulePkg/EdkModulePkg.dsc', 'C:/MyWorkspace')\r
+    w = os.getenv('WORKSPACE')\r
+    ewb = WorkspaceBuild('Nt32Pkg/Nt32Pkg.dsc', w)\r
     ewb.GenBuildDatabase()\r
     #print ewb.DscDatabase\r
     #print ewb.InfDatabase\r