Re: [edk2] [Patch] BaseTools: support PCD value to use expression in the DEC file

2016-10-18 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: Zhu, Yonghong
> Sent: Thursday, October 13, 2016 5:30 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [Patch] BaseTools: support PCD value to use expression in the DEC
> file
> 
> This patch add the support for Pcd value to use expression in the DEC file.
> 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Yonghong Zhu 
> ---
>  BaseTools/Source/Python/Common/Misc.py | 57 --
> 
>  .../Source/Python/Workspace/MetaFileParser.py  | 21 ++--
>  2 files changed, 49 insertions(+), 29 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/Common/Misc.py
> b/BaseTools/Source/Python/Common/Misc.py
> index c99716d..3be1f0f 100644
> --- a/BaseTools/Source/Python/Common/Misc.py
> +++ b/BaseTools/Source/Python/Common/Misc.py
> @@ -1410,36 +1410,11 @@ def ParseConsoleLog(Filename):
>  Opw.write('%s\n' % Line)
> 
>  Opr.close()
>  Opw.close()
> 
> -## AnalyzeDscPcd
> -#
> -#  Analyze DSC PCD value, since there is no data type info in DSC
> -#  This fuction is used to match functions (AnalyzePcdData,
> AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from
> database
> -#  1. Feature flag: TokenSpace.PcdCName|PcdValue
> -#  2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]
> -#  3. Dynamic default:
> -# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]
> -# TokenSpace.PcdCName|PcdValue
> -#  4. Dynamic VPD:
> -# TokenSpace.PcdCName|VpdOffset[|VpdValue]
> -# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]
> -#  5. Dynamic HII:
> -# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]
> -#  PCD value needs to be located in such kind of string, and the PCD value
> might be an expression in which
> -#there might have "|" operator, also in string value.
> -#
> -#  @param Setting: String contain information described above with
> "TokenSpace.PcdCName|" stripped
> -#  @param PcdType: PCD type: feature, fixed, dynamic default VPD HII
> -#  @param DataType: The datum type of PCD: VOID*, UNIT, BOOL
> -#  @retval:
> -#ValueList: A List contain fields described above
> -#IsValid:   True if conforming EBNF, otherwise False
> -#Index: The index where PcdValue is in ValueList
> -#
> -def AnalyzeDscPcd(Setting, PcdType, DataType=''):
> +def AnalyzePcdExpression(Setting):
>  Setting = Setting.strip()
>  # There might be escaped quote in a string: \", \\\"
>  Data = Setting.replace('', '//').replace('\\\"', '\\\'')
>  # There might be '|' in string and in ( ... | ... ), replace it with '-'
>  NewStr = ''
> @@ -1465,10 +1440,40 @@ def AnalyzeDscPcd(Setting, PcdType,
> DataType=''):
>  FieldList.append(Setting[StartPos:].strip())
>  break
>  FieldList.append(Setting[StartPos:Pos].strip())
>  StartPos = Pos + 1
> 
> +return FieldList
> +
> +## AnalyzeDscPcd
> +#
> +#  Analyze DSC PCD value, since there is no data type info in DSC
> +#  This fuction is used to match functions (AnalyzePcdData,
> AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from
> database
> +#  1. Feature flag: TokenSpace.PcdCName|PcdValue
> +#  2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]
> +#  3. Dynamic default:
> +# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]
> +# TokenSpace.PcdCName|PcdValue
> +#  4. Dynamic VPD:
> +# TokenSpace.PcdCName|VpdOffset[|VpdValue]
> +# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]
> +#  5. Dynamic HII:
> +#
> TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]
> +#  PCD value needs to be located in such kind of string, and the PCD value
> might be an expression in which
> +#there might have "|" operator, also in string value.
> +#
> +#  @param Setting: String contain information described above with
> "TokenSpace.PcdCName|" stripped
> +#  @param PcdType: PCD type: feature, fixed, dynamic default VPD HII
> +#  @param DataType: The datum type of PCD: VOID*, UNIT, BOOL
> +#  @retval:
> +#ValueList: A List contain fields described above
> +#IsValid:   True if conforming EBNF, otherwise False
> +#Index: The index where PcdValue is in ValueList
> +#
> +def AnalyzeDscPcd(Setting, PcdType, DataType=''):
> +FieldList = AnalyzePcdExpression(Setting)
> +
>  IsValid = True
>  if PcdType in (MODEL_PCD_FIXED_AT_BUILD,
> MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_FEATURE_FLAG):
>  Value = FieldList[0]
>  Size = ''
>  if len(FieldList) > 1:
> diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py
> b/BaseTools/Source/Python/Workspace/MetaFileParser.py
> index 82d874f..1a5fdf5 100644
> --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
> +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
> @@ -24,11 +24,11 @@ import Common.EdkLogger as EdkLogger
>  import Common.GlobalData as GlobalData
> 
>

[edk2] [Patch] BaseTools: support PCD value to use expression in the DEC file

2016-10-13 Thread Yonghong Zhu
This patch add the support for Pcd value to use expression in the DEC file.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu 
---
 BaseTools/Source/Python/Common/Misc.py | 57 --
 .../Source/Python/Workspace/MetaFileParser.py  | 21 ++--
 2 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index c99716d..3be1f0f 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1410,36 +1410,11 @@ def ParseConsoleLog(Filename):
 Opw.write('%s\n' % Line)
 
 Opr.close()
 Opw.close()
 
-## AnalyzeDscPcd
-#
-#  Analyze DSC PCD value, since there is no data type info in DSC
-#  This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, 
AnalyzeVpdPcdData) used for retrieving PCD value from database
-#  1. Feature flag: TokenSpace.PcdCName|PcdValue
-#  2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]
-#  3. Dynamic default:
-# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]
-# TokenSpace.PcdCName|PcdValue
-#  4. Dynamic VPD:
-# TokenSpace.PcdCName|VpdOffset[|VpdValue]
-# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]
-#  5. Dynamic HII:
-# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]
-#  PCD value needs to be located in such kind of string, and the PCD value 
might be an expression in which
-#there might have "|" operator, also in string value.
-#
-#  @param Setting: String contain information described above with 
"TokenSpace.PcdCName|" stripped
-#  @param PcdType: PCD type: feature, fixed, dynamic default VPD HII
-#  @param DataType: The datum type of PCD: VOID*, UNIT, BOOL
-#  @retval:
-#ValueList: A List contain fields described above
-#IsValid:   True if conforming EBNF, otherwise False
-#Index: The index where PcdValue is in ValueList
-#
-def AnalyzeDscPcd(Setting, PcdType, DataType=''):
+def AnalyzePcdExpression(Setting):
 Setting = Setting.strip()
 # There might be escaped quote in a string: \", \\\"
 Data = Setting.replace('', '//').replace('\\\"', '\\\'')
 # There might be '|' in string and in ( ... | ... ), replace it with '-'
 NewStr = ''
@@ -1465,10 +1440,40 @@ def AnalyzeDscPcd(Setting, PcdType, DataType=''):
 FieldList.append(Setting[StartPos:].strip())
 break
 FieldList.append(Setting[StartPos:Pos].strip())
 StartPos = Pos + 1
 
+return FieldList
+
+## AnalyzeDscPcd
+#
+#  Analyze DSC PCD value, since there is no data type info in DSC
+#  This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, 
AnalyzeVpdPcdData) used for retrieving PCD value from database
+#  1. Feature flag: TokenSpace.PcdCName|PcdValue
+#  2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]
+#  3. Dynamic default:
+# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]
+# TokenSpace.PcdCName|PcdValue
+#  4. Dynamic VPD:
+# TokenSpace.PcdCName|VpdOffset[|VpdValue]
+# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]
+#  5. Dynamic HII:
+# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]
+#  PCD value needs to be located in such kind of string, and the PCD value 
might be an expression in which
+#there might have "|" operator, also in string value.
+#
+#  @param Setting: String contain information described above with 
"TokenSpace.PcdCName|" stripped
+#  @param PcdType: PCD type: feature, fixed, dynamic default VPD HII
+#  @param DataType: The datum type of PCD: VOID*, UNIT, BOOL
+#  @retval:
+#ValueList: A List contain fields described above
+#IsValid:   True if conforming EBNF, otherwise False
+#Index: The index where PcdValue is in ValueList
+#
+def AnalyzeDscPcd(Setting, PcdType, DataType=''):
+FieldList = AnalyzePcdExpression(Setting)
+
 IsValid = True
 if PcdType in (MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, 
MODEL_PCD_FEATURE_FLAG):
 Value = FieldList[0]
 Size = ''
 if len(FieldList) > 1:
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py 
b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 82d874f..1a5fdf5 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -24,11 +24,11 @@ import Common.EdkLogger as EdkLogger
 import Common.GlobalData as GlobalData
 
 from CommonDataClass.DataClass import *
 from Common.DataType import *
 from Common.String import *
-from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, 
PathClass, AnalyzePcdData, AnalyzeDscPcd
+from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, 
PathClass, AnalyzePcdData, AnalyzeDscPcd, AnalyzePcdExpression
 from Common.Expression import *
 from CommonDataClass.Exceptions import *
 from Common.LongFilePathSupport import O