BaseTools: Fixed Pcd from command line issue.
authorBobCF <bob.c.feng@intel.com>
Thu, 8 Mar 2018 05:56:21 +0000 (13:56 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 9 Mar 2018 08:33:29 +0000 (16:33 +0800)
Save the pcd command line value in Pcd object

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/GenC.py
BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools/Source/Python/Workspace/BuildClassObject.py
BaseTools/Source/Python/Workspace/DscBuildData.py

index 3e98506cc80774b57e1accf978e5b00fb161ebe9..481c4dda1447d15a355b889beeebb35947ab4eca 100644 (file)
@@ -916,11 +916,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
     PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
     FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
 \r
-    if GlobalData.BuildOptionPcd:\r
-        for PcdItem in GlobalData.BuildOptionPcd:\r
-            if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
-                Pcd.DefaultValue = PcdItem[2]\r
-                break\r
+    if Pcd.PcdValueFromComm:\r
+        Pcd.DefaultValue = Pcd.PcdValueFromComm\r
     \r
     if Pcd.Type in gDynamicExPcd:\r
         TokenNumber = int(Pcd.TokenValue, 0)\r
@@ -1215,12 +1212,8 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
     PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
     PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
 \r
-    if GlobalData.BuildOptionPcd:\r
-        for PcdItem in GlobalData.BuildOptionPcd:\r
-            if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
-                Pcd.DefaultValue = PcdItem[2]\r
-                break\r
-\r
+    if Pcd.PcdValueFromComm:\r
+        Pcd.DefaultValue = Pcd.PcdValueFromComm\r
     #\r
     # Write PCDs\r
     #\r
index 1b0cf17e254f51dbdb691933fa66630b648f3ec7..60bd625cd2b1f7d88b2722b52cb05b51c8d70374 100644 (file)
@@ -1551,25 +1551,15 @@ class TopLevelMakefile(BuildFile):
         if GlobalData.gIgnoreSource:\r
             ExtraOption += " --ignore-sources"\r
 \r
-        for index, option in enumerate(GlobalData.gCommand):\r
-            if "--pcd" == option and GlobalData.gCommand[index+1]:\r
-                pcdName, pcdValue = GlobalData.gCommand[index+1].split('=')\r
-                for Item in GlobalData.BuildOptionPcd:\r
-                    if '.'.join(Item[0:2]) == pcdName:\r
-                        pcdValue = Item[2]\r
-                        if pcdValue.startswith('L') or pcdValue.startswith('"'):\r
-                            pcdValue, Size = ParseFieldValue(pcdValue)\r
-                            NewVal = '{'\r
-                            for S in range(Size):\r
-                                NewVal = NewVal + '0x%02X' % ((pcdValue >> S * 8) & 0xff)\r
-                                NewVal += ','\r
-                            pcdValue =  NewVal[:-1] + '}'\r
-                        break\r
-                if pcdValue.startswith('{'):\r
-                    pcdValue = 'H' + '"' + pcdValue + '"'\r
-                    ExtraOption += " --pcd " + pcdName + '=' + pcdValue\r
-                else:\r
-                    ExtraOption += " --pcd " + GlobalData.gCommand[index+1]\r
+        for pcd in GlobalData.BuildOptionPcd:\r
+            if pcd[2]:\r
+                pcdname = '.'.join(pcd[0:3])\r
+            else:\r
+                pcdname = '.'.join(pcd[0:2])\r
+            if pcd[3].startswith('{'):\r
+                ExtraOption += " --pcd " + pcdname + '=' + 'H' + '"' + pcd[3] + '"'\r
+            else:\r
+                ExtraOption += " --pcd " + pcdname + '=' + pcd[3]\r
 \r
         MakefileName = self._FILE_NAME_[self._FileType]\r
         SubBuildCommandList = []\r
index 711ba492efc4bdc9251f21fa0120fccf54467d56..1352fa21c819a58aa074f6ea6de8a30d8ca77d66 100644 (file)
@@ -68,6 +68,7 @@ class PcdClassObject(object):
         self.DscRawValue = None\r
         if IsDsc:\r
             self.DscDefaultValue = Value\r
+        self.PcdValueFromComm = ""\r
 \r
     ## Convert the class to a string\r
     #\r
@@ -129,7 +130,6 @@ class StructurePcd(PcdClassObject):
         self.PkgPath = ""\r
         self.DefaultValueFromDec = ""\r
         self.ValueChain = dict()\r
-        self.PcdValueFromComm = ""\r
         self.PcdFieldValueFromComm = collections.OrderedDict({})\r
     def __repr__(self):\r
         return self.TypeName\r
@@ -177,6 +177,7 @@ class StructurePcd(PcdClassObject):
         self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists\r
         self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions\r
         self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue\r
+        self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm\r
         if type(PcdObject) is StructurePcd:\r
             self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile\r
             self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs\r
@@ -190,7 +191,6 @@ class StructurePcd(PcdClassObject):
             self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo\r
             self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else self.PkgPath\r
             self.ValueChain = PcdObject.ValueChain if PcdObject.ValueChain else self.ValueChain\r
-            self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm\r
             self.PcdFieldValueFromComm = PcdObject.PcdFieldValueFromComm if PcdObject.PcdFieldValueFromComm else self.PcdFieldValueFromComm\r
 \r
 ## LibraryClassObject\r
index 9d787702c2e6624414234a1c55278d6e96152bb4..e72b7779cef364875a1a761f345d95c8b3c65ae2 100644 (file)
@@ -893,18 +893,18 @@ class DscBuildData(PlatformBuildClassObject):
         return Pcds\r
 \r
     def RecoverCommandLinePcd(self):\r
-        pcdset = []\r
-        if GlobalData.BuildOptionPcd:\r
-            for pcd in GlobalData.BuildOptionPcd:\r
-                if pcd[2] == "":\r
-                    pcdset.append((pcd[0],pcd[1],pcd[3]))\r
-                else:\r
-                    if (pcd[1],pcd[0]) not in self._Pcds:\r
-                        pcdvalue = pcd[3] if len(pcd) == 4 else pcd[2]\r
-                        pcdset.append((pcd[0],pcd[1],pcdvalue))\r
-                    #else:\r
-                        # remove the settings from command line since it has been handled.\r
-        GlobalData.BuildOptionPcd = pcdset\r
+        def UpdateCommandLineValue(pcd):\r
+            if pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
+                                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
+                pcd.PcdValueFromComm = pcd.DefaultValue\r
+            elif pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
+                pcd.PcdValueFromComm = pcd.SkuInfoList.get("DEFAULT").HiiDefaultValue\r
+            else:\r
+                pcd.PcdValueFromComm = pcd.SkuInfoList.get("DEFAULT").DefaultValue\r
+        for pcd in self._Pcds:\r
+            if isinstance(self._Pcds[pcd],StructurePcd) and (self._Pcds[pcd].PcdValueFromComm or self._Pcds[pcd].PcdFieldValueFromComm):\r
+                UpdateCommandLineValue(self._Pcds[pcd])\r
+\r
     def GetFieldValueFromComm(self,ValueStr,TokenSpaceGuidCName, TokenCName, FieldName):\r
         PredictedFieldType = "VOID*"\r
         if ValueStr.startswith('L'):\r
@@ -1242,6 +1242,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if isinstance(self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName), None),StructurePcd):\r
                     self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName)).PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]\r
                 else:\r
+                    Pcd.PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]\r
                     Pcd.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0]\r
                     for sku in Pcd.SkuInfoList:\r
                         SkuInfo = Pcd.SkuInfoList[sku]\r
@@ -1266,9 +1267,8 @@ class DscBuildData(PlatformBuildClassObject):
                         Pcd.MaxDatumSize = str(MaxSize)\r
             else:\r
                 PcdInDec = self.DecPcds.get((Name,Guid))\r
-                if isinstance(PcdInDec,StructurePcd):\r
-                    PcdInDec.PcdValueFromComm = NoFiledValues[(Guid,Name)][0]\r
                 if PcdInDec:\r
+                    PcdInDec.PcdValueFromComm = NoFiledValues[(Guid,Name)][0]\r
                     if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
                                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
                         self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)\r
@@ -1711,6 +1711,7 @@ class DscBuildData(PlatformBuildClassObject):
             except BadExpression:\r
                 EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" %\r
                                 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec))\r
+        DefaultValueFromDec = StringToArray(DefaultValueFromDec)\r
         Value, ValueSize = ParseFieldValue (DefaultValueFromDec)\r
         if isinstance(Value, str):\r
             CApp = CApp + '  Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec)\r
@@ -1850,7 +1851,7 @@ class DscBuildData(PlatformBuildClassObject):
                     try:\r
                         FieldList = ValueExpressionEx(FieldList, "VOID*")(True)\r
                     except BadExpression:\r
-                        EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %\r
+                        EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from Command: %s" %\r
                                         (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
                 Value, ValueSize = ParseFieldValue (FieldList)\r
 \r