Modify GenFds related files.
[people/mcb30/basetools.git] / Source / Python / GenFds / FfsInfStatement.py
index 3b91098..d25b705 100644 (file)
@@ -7,6 +7,8 @@ import sys
 import Section\r
 import RuleSimpleFile\r
 import RuleComplexFile\r
+import Common.TargetTxtClassObject\r
+\r
 #from String import *\r
 \r
 class FfsInfStatement(Ffs.Ffs):\r
@@ -18,7 +20,6 @@ class FfsInfStatement(Ffs.Ffs):
         self.InfFileName = None\r
         self.BuildNum = ''\r
         self.KeyStringList = []\r
-        self.RuleOverride = None\r
 \r
     def __infParse__(self):\r
         #\r
@@ -69,7 +70,7 @@ class FfsInfStatement(Ffs.Ffs):
         # Get the rule of how to generate Ffs file\r
         #\r
         Rule = self.__GetRule__()\r
-                                                       \r
+\r
         FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]\r
         #\r
         # For the rule only has simpleFile\r
@@ -105,57 +106,90 @@ class FfsInfStatement(Ffs.Ffs):
         return String\r
 \r
     def __GetRule__ (self) :\r
-        currentArch = 'IA32'\r
+        currentArchList = self.__GetCurrentArch__()\r
+        \r
         #for item in GenFdsGlobalVariable.FdfParser.profile.RuleDict :\r
         #    print item\r
+        for currentArch in currentArchList:\r
+            RuleName = 'RULE'              + \\r
+                       '.'                 + \\r
+                       currentArch.upper() + \\r
+                       '.'                 + \\r
+                       self.ModuleType.upper()\r
+            if self.Rule != None:\r
+                RuleName = RuleName + \\r
+                           '.'      + \\r
+                           self.Rule.upper()\r
+                           \r
+            Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)\r
+            if Rule != None:\r
+                print "Want To Find Rule Name is : " + RuleName\r
+                return Rule\r
+            \r
         RuleName = 'RULE'      + \\r
                    '.'         + \\r
-                   currentArch + \\r
+                   'COMMON'    + \\r
                    '.'         + \\r
                    self.ModuleType.upper()\r
-        \r
+        if self.Rule != None:\r
+            RuleName = RuleName + \\r
+                       '.'      + \\r
+                       self.Rule.upper()\r
+                       \r
         Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)\r
-        if Rule == None :\r
-            RuleName = 'RULE'      + \\r
-                       '.'         + \\r
-                       'COMMON'    + \\r
-                       '.'         + \\r
-                       self.ModuleType.upper()\r
+        if Rule != None:\r
             print "Want To Find Rule Name is : " + RuleName\r
-            Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)\r
-            if Rule == None :\r
-                print 'Dont Find Related Rule, Using Default Rule !!!'\r
-                if GenFdsGlobalVariable.DefaultRule == None:\r
-                    raise Exception ("Default Rule doesn't exist!!")\r
+            return Rule\r
+\r
+        if Rule == None :\r
+            print 'Dont Find Related Rule, Using Default Rule !!!'\r
+            if GenFdsGlobalVariable.DefaultRule == None:\r
+                raise Exception ("Default Rule doesn't exist!!")\r
+            else:\r
                 return GenFdsGlobalVariable.DefaultRule\r
-        print "Want To Find Rule Name is : " + RuleName\r
-        return Rule\r
+\r
+    def __GetCurrentArch__(self):\r
+        Target = Common.TargetTxtClassObject.TargetTxtDict(GenFdsGlobalVariable.WorkSpaceDir)\r
+        targetArchList = Target.TargetTxtDictionary['TARGET_ARCH']\r
+        #targetArchList = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["TARGET_ARCH"]\r
+        if len(targetArchList) == 0:\r
+            targetArchList = GenFdsGlobalVariable.WorkSpace.SupArchList\r
+        else:\r
+            targetArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(targetArchList)\r
+            \r
+        #activePlatform = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary.get('ACTIVE_PLATFORM')[0]\r
+        dscArchList = []\r
+        if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('IA32').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):\r
+            dscArchList.append ('IA32')\r
+        if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('X64').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):\r
+            dscArchList.append ('X64')\r
+        if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('IPF').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):\r
+            dscArchList.append ('IPF')\r
+\r
+        curArchList = set (targetArchList) & set (dscArchList)\r
+        print "Valid target architecture(s) is", " ".join(curArchList)\r
+        return curArchList\r
     \r
     def __GetEFIOutPutPath__(self):\r
-        Flag = False\r
         Arch = ''\r
         OutputPath = ''\r
         (ModulePath, fileName) = os.path.split(self.InfFileName)\r
         index = fileName.find('.')\r
         fileName = fileName[0:index]\r
-        Platform = os.path.normpath(GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0])\r
-        targetArchList = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["TARGET_ARCH"]\r
-        if len(targetArchList) == 0:\r
-            myArchList = GenFdsGlobalVariable.WorkSpace.SupArchList\r
-        else:\r
-            myArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(targetArchList)\r
-            print "Valid target architecture(s) is", " ".join(myArchList)\r
 \r
-        if len(myArchList) > 1 :\r
+        curArchList = self.__GetCurrentArch__()\r
+        if len(curArchList) > 1 :\r
             for Key in self.KeyStringList:\r
                 Target, Tag, Arch = Key.split('_')\r
                 ArchList = set (ArchList) & Arch\r
-                if ArchList == 1:\r
-                    Arch = ArchList[0]\r
-                else:\r
-                    raise Exception("Module %s has too many bulid Arch !" %self.InfFileNames)\r
-        elif len(myArchList) == 1 :\r
-            Arch = myArchList.pop()\r
+            if len(ArchList) == 1:\r
+                Arch = ArchList[0]\r
+            elif len(ArchList) > 1:\r
+                raise Exception("Module %s has too many bulid Arch !" %self.InfFileNames)\r
+            else:\r
+                raise Exception("Don't find legal Arch in Module %s !" %self.InfFileNames)\r
+        elif len(curArchList) == 1 :\r
+            Arch = curArchList.pop()\r
             \r
         OutputPath = os.path.join(GenFdsGlobalVariable.OuputDir,\r
                                   Arch ,\r
@@ -163,7 +197,8 @@ class FfsInfStatement(Ffs.Ffs):
                                   fileName,\r
                                   'OUTPUT'\r
                                   )\r
-        OutputPath = os.path.normcase(OutputPath)\r
+                                  \r
+        OutputPath = os.path.realpath(OutputPath)\r
         return OutputPath\r
         \r
     def __GenSimpleFileSection__(self, Rule):\r
@@ -230,7 +265,10 @@ class FfsInfStatement(Ffs.Ffs):
         for Sect in Rule.SectionList:\r
            #print 'GenSection: %s %s :' %(self.OutputPath ,self.ModuleGuid)\r
            secName = ''\r
-           secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, self.KeyStringList, self)\r
+           if Rule.KeyStringList != []:\r
+               secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, Rule.KeyStringList, self)\r
+           else :\r
+               secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, self.KeyStringList, self)\r
            if secName != '':\r
                SectFiles = SectFiles    + \\r
                            ' -i '       + \\r