BaseTools: Update --pcd parser to support flexible pcd format
authorYonghong Zhu <yonghong.zhu@intel.com>
Wed, 7 Mar 2018 06:14:43 +0000 (14:14 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 9 Mar 2018 08:34:37 +0000 (16:34 +0800)
This patch update --pcd parser to support flexible pcd format.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/Common/Expression.py
BaseTools/Source/Python/Common/Misc.py
BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools/Source/Python/GenFds/FfsInfStatement.py
BaseTools/Source/Python/GenFds/GenFds.py
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/Workspace/MetaFileParser.py
BaseTools/Source/Python/build/BuildReport.py

index 5a0ade9e7ecad6d1fa6cbeb2dec09f7d4ef26eae..79dc83efc3d5670d9dc278bc06d488402d359a56 100644 (file)
@@ -15,7 +15,7 @@
 from Common.GlobalData import *\r
 from CommonDataClass.Exceptions import BadExpression\r
 from CommonDataClass.Exceptions import WrnExpression\r
-from Misc import GuidStringToGuidStructureString, ParseFieldValue\r
+from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueAnArray\r
 import Common.EdkLogger as EdkLogger\r
 import copy\r
 \r
@@ -125,6 +125,25 @@ def IsValidCString(Str):
         return False\r
     return True\r
 \r
+def BuildOptionValue(PcdValue, GuidDict):\r
+    IsArray = False\r
+    if PcdValue.startswith('H'):\r
+        InputValue = PcdValue[1:]\r
+    elif PcdValue.startswith("L'") or PcdValue.startswith("'"):\r
+        InputValue = PcdValue\r
+    elif PcdValue.startswith('L'):\r
+        InputValue = 'L"' + PcdValue[1:] + '"'\r
+    else:\r
+        InputValue = PcdValue\r
+    if IsFieldValueAnArray(InputValue):\r
+        IsArray = True\r
+    if IsArray:\r
+        try:\r
+            PcdValue = ValueExpressionEx(InputValue, 'VOID*', GuidDict)(True)\r
+        except:\r
+            pass\r
+    return PcdValue\r
+\r
 ## ReplaceExprMacro\r
 #\r
 def ReplaceExprMacro(String, Macros, ExceptionList = None):\r
index af374d804d86b8a01a5fee2ae38b0c2968169eaf..2086b4c69d17e1d167722fc616d7f0de3f8f24fd 100644 (file)
@@ -1441,6 +1441,22 @@ def ParseConsoleLog(Filename):
     Opr.close()\r
     Opw.close()\r
 \r
+def IsFieldValueAnArray (Value):\r
+    Value = Value.strip()\r
+    if Value.startswith('GUID') and Value.endswith(')'):\r
+        return True\r
+    if Value.startswith('L"') and Value.endswith('"')  and len(list(Value[2:-1])) > 1:\r
+        return True\r
+    if Value[0] == '"' and Value[-1] == '"' and len(list(Value[1:-1])) > 1:\r
+        return True\r
+    if Value[0] == '{' and Value[-1] == '}':\r
+        return True\r
+    if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1:\r
+        return True\r
+    if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1:\r
+        return True\r
+    return False\r
+\r
 def AnalyzePcdExpression(Setting):\r
     Setting = Setting.strip()\r
     # There might be escaped quote in a string: \", \\\" , \', \\\'\r
@@ -2377,31 +2393,6 @@ def PackRegistryFormatGuid(Guid):
                 int(Guid[4][-2:], 16)\r
                 )\r
 \r
-def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):\r
-    if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']:\r
-        if Value.startswith('L') or Value.startswith('"'):\r
-            if not Value[1]:\r
-                EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
-            Value = Value\r
-        elif Value.startswith('H'):\r
-            if not Value[1]:\r
-                EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
-            Value = Value[1:]\r
-        else:\r
-            if not Value[0]:\r
-                EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
-            Value = '"' + Value + '"'\r
-\r
-    IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)\r
-    if not IsValid:\r
-        EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
-    if PcdDatumType == 'BOOLEAN':\r
-        Value = Value.upper()\r
-        if Value == 'TRUE' or Value == '1':\r
-            Value = '1'\r
-        elif Value == 'FALSE' or Value == '0':\r
-            Value = '0'\r
-    return  Value\r
 ##  Get the integer value from string like "14U" or integer like 2\r
 #\r
 #   @param      Input   The object that may be either a integer value or a string\r
index fc2b409847be5b24a5e774a055ae6214089d4f59..76d7e6ac1903493c5c73edde44b6b15a3c6f0fd3 100644 (file)
@@ -928,6 +928,7 @@ class FdfParser:
         if GlobalData.BuildOptionPcd:\r
             for Item in GlobalData.BuildOptionPcd:\r
                 PcdName, TmpValue = Item.split("=")\r
+                TmpValue = BuildOptionValue(TmpValue, {})\r
                 MacroDict[PcdName.strip()] = TmpValue\r
         # Highest priority\r
 \r
index dfff892e21491e51c251c4a88dc3b6906bb44800..a348233911718de64e1890b81b1156f427e6248e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # process FFS generation from INF statement\r
 #\r
-#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #  Copyright (c) 2014-2016 Hewlett-Packard Development Company, L.P.<BR>\r
 #\r
 #  This program and the accompanying materials\r
@@ -274,7 +274,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
             if GlobalData.BuildOptionPcd:\r
                 for pcd in GlobalData.BuildOptionPcd:\r
                     if PcdKey == (pcd[1], pcd[0]):\r
-                        DefaultValue = pcd[2]\r
+                        if pcd[2]:\r
+                            continue\r
+                        DefaultValue = pcd[3]\r
                         BuildOptionOverride = True\r
                         break\r
 \r
@@ -288,15 +290,15 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 except BadExpression:\r
                     EdkLogger.error("GenFds", GENFDS_ERROR, 'PCD [%s.%s] Value "%s"' %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValue), File=self.InfFileName)\r
 \r
-            if Pcd.DefaultValue:\r
+            if Pcd.InfDefaultValue:\r
                 try:\r
-                    Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, Platform._GuidDict)(True)\r
+                    Pcd.InfDefaultValue = ValueExpressionEx(Pcd.InfDefaultValue, Pcd.DatumType, Platform._GuidDict)(True)\r
                 except BadExpression:\r
                     EdkLogger.error("GenFds", GENFDS_ERROR, 'PCD [%s.%s] Value "%s"' %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.DefaultValue),File=self.InfFileName)\r
 \r
             # Check value, if value are equal, no need to patch\r
             if Pcd.DatumType == "VOID*":\r
-                if Pcd.DefaultValue == DefaultValue or DefaultValue in [None, '']:\r
+                if Pcd.InfDefaultValue == DefaultValue or DefaultValue in [None, '']:\r
                     continue\r
                 # Get the string size from FDF or DSC\r
                 if DefaultValue[0] == 'L':\r
@@ -310,15 +312,15 @@ class FfsInfStatement(FfsInfStatementClassObject):
                     Pcd.MaxDatumSize = PatchPcd.MaxDatumSize\r
                 # If no defined the maximum size in DSC, try to get current size from INF\r
                 if Pcd.MaxDatumSize in ['', None]:\r
-                    Pcd.MaxDatumSize = str(len(Pcd.DefaultValue.split(',')))\r
+                    Pcd.MaxDatumSize = str(len(Pcd.InfDefaultValue.split(',')))\r
             else:\r
                 Base1 = Base2 = 10\r
-                if Pcd.DefaultValue.upper().startswith('0X'):\r
+                if Pcd.InfDefaultValue.upper().startswith('0X'):\r
                     Base1 = 16\r
                 if DefaultValue.upper().startswith('0X'):\r
                     Base2 = 16\r
                 try:\r
-                    PcdValueInImg = int(Pcd.DefaultValue, Base1)\r
+                    PcdValueInImg = int(Pcd.InfDefaultValue, Base1)\r
                     PcdValueInDscOrFdf = int(DefaultValue, Base2)\r
                     if PcdValueInImg == PcdValueInDscOrFdf:\r
                         continue\r
index 9ca7c8706a9a7c69d2c2a83a1b1cce04039d32a3..4c56cbb02a8e9a089080aa8fce70b43170ea1802 100644 (file)
@@ -38,8 +38,6 @@ from Common.Misc import DirCache, PathClass
 from Common.Misc import SaveFileOnChange\r
 from Common.Misc import ClearDuplicatedInf\r
 from Common.Misc import GuidStructureStringToGuidString\r
-from Common.Misc import CheckPcdDatum\r
-from Common.Misc import BuildOptionPcdValueFormat\r
 from Common.BuildVersion import gBUILD_VERSION\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 import FfsFileStatement\r
@@ -369,53 +367,6 @@ def SingleCheckCallback(option, opt_str, value, parser):
     else:\r
         parser.error("Option %s only allows one instance in command line!" % option)\r
 \r
-def CheckBuildOptionPcd():\r
-    for Arch in GenFdsGlobalVariable.ArchList:\r
-        PkgList  = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag)\r
-        for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
-            if type(pcd) is tuple:\r
-                continue\r
-            (pcdname, pcdvalue) = pcd.split('=')\r
-            if not pcdvalue:\r
-                EdkLogger.error('GenFds', OPTION_MISSING, "No Value specified for the PCD %s." % (pcdname))\r
-            if '.' in pcdname:\r
-                (TokenSpaceGuidCName, TokenCName) = pcdname.split('.')\r
-                HasTokenSpace = True\r
-            else:\r
-                TokenCName = pcdname\r
-                TokenSpaceGuidCName = ''\r
-                HasTokenSpace = False\r
-            TokenSpaceGuidCNameList = []\r
-            FoundFlag = False\r
-            PcdDatumType = ''\r
-            NewValue = ''\r
-            for package in PkgList:\r
-                for key in package.Pcds:\r
-                    PcdItem = package.Pcds[key]\r
-                    if HasTokenSpace:\r
-                        if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):\r
-                            PcdDatumType = PcdItem.DatumType\r
-                            NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
-                            FoundFlag = True\r
-                    else:\r
-                        if PcdItem.TokenCName == TokenCName:\r
-                            if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
-                                if len (TokenSpaceGuidCNameList) < 1:\r
-                                    TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
-                                    PcdDatumType = PcdItem.DatumType\r
-                                    TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
-                                    NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
-                                    FoundFlag = True\r
-                                else:\r
-                                    EdkLogger.error(\r
-                                            'GenFds',\r
-                                            PCD_VALIDATION_INFO_ERROR,\r
-                                            "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
-                                            )\r
-\r
-            GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)\r
-\r
-\r
 ## FindExtendTool()\r
 #\r
 #  Find location of tools to process data\r
index e72b7779cef364875a1a761f345d95c8b3c65ae2..91b3a2737d9d895b2931d4852370397e42d6250e 100644 (file)
@@ -21,7 +21,7 @@ from Common.String import *
 from Common.DataType import *\r
 from Common.Misc import *\r
 from types import *\r
-\r
+from Common.Expression import *\r
 from CommonDataClass.CommonClass import SkuInfoClass\r
 from Common.TargetTxtClassObject import *\r
 from Common.ToolDefClassObject import *\r
@@ -905,36 +905,6 @@ class DscBuildData(PlatformBuildClassObject):
             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
-            if not ValueStr[1]:\r
-                EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
-            ValueStr = ValueStr[0] + '"' + ValueStr[1:] + '"'\r
-            PredictedFieldType = "VOID*"\r
-        elif ValueStr.startswith('H') or ValueStr.startswith('{'):\r
-            EdkLogger.error("build", FORMAT_INVALID, 'Currently we do not support assign H"{...}" format for Pcd field.', ExtraData="%s.%s.%s from command line" % (TokenSpaceGuidCName, TokenCName, FieldName))\r
-            ValueStr = ValueStr[1:]\r
-            PredictedFieldType = "VOID*"\r
-        elif ValueStr.upper() in ['TRUE', '0X1', '0X01', '1', 'FALSE', '0X0', '0X00', '0']:\r
-            PredictedFieldType = "BOOLEAN"\r
-        elif ValueStr.isdigit() or ValueStr.upper().startswith('0X'):\r
-            PredictedFieldType = TAB_UINT16\r
-        else:\r
-            if not ValueStr[0]:\r
-                EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
-            ValueStr = '"' + ValueStr + '"'\r
-            PredictedFieldType = "VOID*"\r
-        IsValid, Cause = CheckPcdDatum(PredictedFieldType, ValueStr)\r
-        if not IsValid:\r
-            EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s.%s from command line" % (TokenSpaceGuidCName, TokenCName, FieldName))\r
-        if PredictedFieldType == 'BOOLEAN':\r
-            ValueStr = ValueStr.upper()\r
-            if ValueStr == 'TRUE' or ValueStr == '1':\r
-                ValueStr = '1'\r
-            elif ValueStr == 'FALSE' or ValueStr == '0':\r
-                ValueStr = '0'\r
-        return  ValueStr\r
     def __ParsePcdFromCommandLine(self):\r
         if GlobalData.BuildOptionPcd:\r
             for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
@@ -975,148 +945,118 @@ class DscBuildData(PlatformBuildClassObject):
                 TokenSpaceGuidCNameList = []\r
                 FoundFlag = False\r
                 PcdDatumType = ''\r
-                NewValue = ''\r
+                DisplayName = TokenCName\r
+                if FieldName:\r
+                    DisplayName = TokenCName + '.' + FieldName\r
                 if not HasTokenSpace:\r
                     for key in self.DecPcds:\r
-                        if TokenCName == key[0]:\r
-                            if TokenSpaceGuidCName:\r
-                                EdkLogger.error(\r
-                                                'build',\r
-                                                 AUTOGEN_ERROR,\r
-                                                "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, TokenSpaceGuidCName, key[1])\r
-                                                )\r
-                            else:\r
-                                TokenSpaceGuidCName = key[1]\r
-                                FoundFlag = True\r
+                        PcdItem = self.DecPcds[key]\r
+                        if TokenCName == PcdItem.TokenCName:\r
+                            if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
+                                if len (TokenSpaceGuidCNameList) < 1:\r
+                                    TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
+                                    TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
+                                    PcdDatumType = PcdItem.DatumType\r
+                                    FoundFlag = True\r
+                                else:\r
+                                    EdkLogger.error(\r
+                                            'build',\r
+                                             AUTOGEN_ERROR,\r
+                                            "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
+                                            )\r
                 else:\r
                     if (TokenCName, TokenSpaceGuidCName) in self.DecPcds:\r
                         FoundFlag = True\r
-                if FieldName:\r
-                    NewValue = self.GetFieldValueFromComm(pcdvalue, TokenSpaceGuidCName, TokenCName, FieldName)\r
-                    GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName,NewValue,("build command options",1))\r
-                else:\r
-                    # Replace \' to ', \\\' to \'\r
-                    pcdvalue = pcdvalue.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")\r
-                    for key in self.DecPcds:\r
-                        PcdItem = self.DecPcds[key]\r
-                        if HasTokenSpace:\r
-                            if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):\r
-                                PcdDatumType = PcdItem.DatumType\r
-                                if pcdvalue.startswith('H'):\r
-                                    try:\r
-                                        pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True)\r
-                                    except BadExpression, Value:\r
-                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                    if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']:\r
-                                        pcdvalue = 'H' + pcdvalue\r
-                                elif pcdvalue.startswith("L'"):\r
-                                    try:\r
-                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                    except BadExpression, Value:\r
-                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                    if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']:\r
-                                        pcdvalue = 'H' + pcdvalue\r
-                                elif pcdvalue.startswith("'"):\r
-                                    try:\r
-                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                    except BadExpression, Value:\r
-                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                    if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']:\r
-                                        pcdvalue = 'H' + pcdvalue\r
-                                elif pcdvalue.startswith('L'):\r
-                                    pcdvalue = 'L"' + pcdvalue[1:] + '"'\r
-                                    try:\r
-                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                    except BadExpression, Value:\r
-                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                else:\r
-                                    try:\r
-                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                    except BadExpression, Value:\r
-                                        try:\r
-                                            pcdvalue = '"' + pcdvalue + '"'\r
-                                            pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                        except BadExpression, Value:\r
-                                            EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                            (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
-                                FoundFlag = True\r
-                        else:\r
-                            if PcdItem.TokenCName == TokenCName:\r
-                                if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
-                                    if len (TokenSpaceGuidCNameList) < 1:\r
-                                        TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
-                                        PcdDatumType = PcdItem.DatumType\r
-                                        TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
-                                        if pcdvalue.startswith('H'):\r
-                                            try:\r
-                                                pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True)\r
-                                            except BadExpression, Value:\r
-                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %\r
-                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                            if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']:\r
-                                                pcdvalue = 'H' + pcdvalue\r
-                                        elif pcdvalue.startswith("L'"):\r
-                                            try:\r
-                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(\r
-                                                    True)\r
-                                            except BadExpression, Value:\r
-                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                            if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']:\r
-                                                pcdvalue = 'H' + pcdvalue\r
-                                        elif pcdvalue.startswith("'"):\r
-                                            try:\r
-                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(\r
-                                                    True)\r
-                                            except BadExpression, Value:\r
-                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                            if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']:\r
-                                                pcdvalue = 'H' + pcdvalue\r
-                                        elif pcdvalue.startswith('L'):\r
-                                            pcdvalue = 'L"' + pcdvalue[1:] + '"'\r
-                                            try:\r
-                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(\r
-                                                    True)\r
-                                            except BadExpression, Value:\r
-                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                        else:\r
-                                            try:\r
-                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                            except BadExpression, Value:\r
-                                                try:\r
-                                                    pcdvalue = '"' + pcdvalue + '"'\r
-                                                    pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)\r
-                                                except BadExpression, Value:\r
-                                                    EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
-                                                                    (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))\r
-                                        NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
-                                        FoundFlag = True\r
-                                    else:\r
-                                        EdkLogger.error(\r
-                                                'build',\r
-                                                 AUTOGEN_ERROR,\r
-                                                "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
-                                                )\r
-                    GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName,NewValue,("build command options",1))\r
                 if not FoundFlag:\r
                     if HasTokenSpace:\r
-                        EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))\r
+                        EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, DisplayName))\r
                     else:\r
-                        EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))\r
+                        EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (DisplayName))\r
+                pcdvalue = pcdvalue.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")\r
+                if FieldName:\r
+                    pcdvalue = self.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict, FieldName)\r
+                else:\r
+                    pcdvalue = self.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict)\r
+                    IsValid, Cause = CheckPcdDatum(PcdDatumType, pcdvalue)\r
+                    if not IsValid:\r
+                        EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
+                GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName, pcdvalue,("build command options",1))\r
+\r
                 for BuildData in self._Bdb._CACHE_.values():\r
                     if BuildData.MetaFile.Ext == '.dec' or BuildData.MetaFile.Ext == '.dsc':\r
                         continue\r
                     for key in BuildData.Pcds:\r
                         PcdItem = BuildData.Pcds[key]\r
                         if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName) and FieldName =="":\r
-                            PcdItem.DefaultValue = NewValue\r
+                            PcdItem.DefaultValue = pcdvalue\r
+\r
+    def HandleFlexiblePcd(self, TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''):\r
+        if FieldName:\r
+            IsArray = False\r
+            TokenCName += '.' + FieldName\r
+        if PcdValue.startswith('H'):\r
+            if FieldName and IsFieldValueAnArray(PcdValue[1:]):\r
+                PcdDatumType = 'VOID*'\r
+                IsArray = True\r
+            if FieldName and not IsArray:\r
+                return PcdValue\r
+            try:\r
+                PcdValue = ValueExpressionEx(PcdValue[1:], PcdDatumType, GuidDict)(True)\r
+            except BadExpression, Value:     \r
+                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
+                                (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
+        elif PcdValue.startswith("L'") or PcdValue.startswith("'"):\r
+            if FieldName and IsFieldValueAnArray(PcdValue):\r
+                PcdDatumType = 'VOID*'\r
+                IsArray = True\r
+            if FieldName and not IsArray:\r
+                return PcdValue\r
+            try:\r
+                PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True)\r
+            except BadExpression, Value:\r
+                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
+                                (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
+        elif PcdValue.startswith('L'):\r
+            PcdValue = 'L"' + PcdValue[1:] + '"'\r
+            if FieldName and IsFieldValueAnArray(PcdValue):\r
+                PcdDatumType = 'VOID*'\r
+                IsArray = True\r
+            if FieldName and not IsArray:\r
+                return PcdValue\r
+            try:\r
+                PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True)\r
+            except BadExpression, Value:\r
+                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
+                                (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
+        else:\r
+            if PcdValue.upper() == 'FALSE':\r
+                PcdValue = str(0)\r
+            if PcdValue.upper() == 'TRUE':\r
+                PcdValue = str(1)\r
+            if not FieldName:\r
+                if PcdDatumType not in ['UINT8','UINT16','UINT32','UINT64','BOOLEAN']:\r
+                    PcdValue = '"' + PcdValue + '"'\r
+            else:\r
+                IsArray = False\r
+                Base = 10\r
+                if PcdValue.upper().startswith('0X'):\r
+                    Base = 16\r
+                try:\r
+                    Num = int(PcdValue, Base)\r
+                except:\r
+                    PcdValue = '"' + PcdValue + '"'\r
+                if IsFieldValueAnArray(PcdValue):\r
+                    PcdDatumType = 'VOID*'\r
+                    IsArray = True\r
+                if not IsArray:\r
+                    return PcdValue\r
+            try:\r
+                PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True)\r
+            except BadExpression, Value:\r
+                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %\r
+                                (TokenSpaceGuidCName, TokenCName, PcdValue, Value))\r
+        return PcdValue\r
+\r
     ## Retrieve all PCD settings in platform\r
     def _GetPcds(self):\r
         if self._Pcds == None:\r
@@ -1555,22 +1495,6 @@ class DscBuildData(PlatformBuildClassObject):
 \r
         return str(max([pcd_size for pcd_size in [get_length(item) for item in sku_values]]))\r
 \r
-    def IsFieldValueAnArray (self, Value):\r
-        Value = Value.strip()\r
-        if Value.startswith('GUID') and Value.endswith(')'):\r
-            return True\r
-        if Value.startswith('L"') and Value.endswith('"')  and len(list(Value[2:-1])) > 1:\r
-            return True\r
-        if Value[0] == '"' and Value[-1] == '"' and len(list(Value[1:-1])) > 1:\r
-            return True\r
-        if Value[0] == '{' and Value[-1] == '}':\r
-            return True\r
-        if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1:\r
-            return True\r
-        if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1:\r
-            return True\r
-        return False\r
-\r
     def ExecuteCommand (self, Command):\r
         try:\r
             Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\r
@@ -1617,7 +1541,7 @@ class DscBuildData(PlatformBuildClassObject):
                 continue\r
             for FieldName in FieldList:\r
                 FieldName = "." + FieldName\r
-                IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
+                IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
                 if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):\r
                     try:\r
                         Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)\r
@@ -1647,7 +1571,7 @@ class DscBuildData(PlatformBuildClassObject):
                         continue\r
                     for FieldName in FieldList:\r
                         FieldName = "." + FieldName\r
-                        IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
+                        IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
                         if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):\r
                             try:\r
                                 Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)\r
@@ -1671,7 +1595,7 @@ class DscBuildData(PlatformBuildClassObject):
             CApp = CApp + "// From Command Line \n"\r
         for FieldName in Pcd.PcdFieldValueFromComm:\r
             FieldName = "." + FieldName\r
-            IsArray = self.IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0])\r
+            IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0])\r
             if IsArray and not (Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].endswith('}')):\r
                 try:\r
                     Value = ValueExpressionEx(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True)\r
@@ -1704,7 +1628,7 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + '  UINT32  FieldSize;\n'\r
         CApp = CApp + '  CHAR8   *Value;\n'\r
         DefaultValueFromDec = Pcd.DefaultValueFromDec\r
-        IsArray = self.IsFieldValueAnArray(Pcd.DefaultValueFromDec)\r
+        IsArray = IsFieldValueAnArray(Pcd.DefaultValueFromDec)\r
         if IsArray:\r
             try:\r
                 DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, "VOID*")(True)\r
@@ -1725,7 +1649,7 @@ class DscBuildData(PlatformBuildClassObject):
             if not FieldList:\r
                 continue\r
             for FieldName in FieldList:\r
-                IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
+                IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
                 if IsArray:\r
                     try:\r
                         FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)\r
@@ -1775,7 +1699,7 @@ class DscBuildData(PlatformBuildClassObject):
             if not FieldList:\r
                 continue\r
             if pcddefaultvalue and FieldList == pcddefaultvalue:\r
-                IsArray = self.IsFieldValueAnArray(FieldList)\r
+                IsArray = IsFieldValueAnArray(FieldList)\r
                 if IsArray:\r
                     try:\r
                         FieldList = ValueExpressionEx(FieldList, "VOID*")(True)\r
@@ -1805,7 +1729,7 @@ class DscBuildData(PlatformBuildClassObject):
                 continue\r
             if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD') or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )):\r
                 for FieldName in FieldList:\r
-                    IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
+                    IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
                     if IsArray:\r
                         try:\r
                             FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)\r
@@ -1846,7 +1770,7 @@ class DscBuildData(PlatformBuildClassObject):
             if not FieldList:\r
                 continue\r
             if pcddefaultvalue and FieldList == pcddefaultvalue:\r
-                IsArray = self.IsFieldValueAnArray(FieldList)\r
+                IsArray = IsFieldValueAnArray(FieldList)\r
                 if IsArray:\r
                     try:\r
                         FieldList = ValueExpressionEx(FieldList, "VOID*")(True)\r
@@ -1865,7 +1789,7 @@ class DscBuildData(PlatformBuildClassObject):
                     CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
                 continue\r
             for FieldName in FieldList:\r
-                IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
+                IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
                 if IsArray:\r
                     try:\r
                         FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True)\r
index 6809003d984691c0b906fed0b16092652d6baac4..69bdf2161bec808410231458538cd6cdeba18cfa 100644 (file)
@@ -1246,6 +1246,7 @@ class DscParser(MetaFileParser):
         if GlobalData.BuildOptionPcd:\r
             for Item in GlobalData.BuildOptionPcd:\r
                 PcdName, TmpValue = Item.split("=")\r
+                TmpValue = BuildOptionValue(TmpValue, self._GuidDict)\r
                 Macros[PcdName.strip()] = TmpValue\r
         return Macros\r
 \r
index 89bdfa1d864288e69db0ccdbffc3e90db40f6222..d555dce9b3bc3f15dfda855868520e4b3f4168e0 100644 (file)
@@ -977,7 +977,9 @@ class PcdReport(object):
                     if GlobalData.BuildOptionPcd:\r
                         for pcd in GlobalData.BuildOptionPcd:\r
                             if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (pcd[0], pcd[1]):\r
-                                PcdValue = pcd[2]\r
+                                if pcd[2]:\r
+                                    continue\r
+                                PcdValue = pcd[3]\r
                                 Pcd.DefaultValue = PcdValue\r
                                 BuildOptionMatch = True\r
                                 break\r