[edk2] [PATCH] BaseTools: Fix build argument --pcd for flexible format bugs

Feng, YunhuaX posted 1 patch 6 years, 8 months ago
Failed in applying to current master (apply log)
BaseTools/Source/Python/AutoGen/GenMake.py        |  2 +
BaseTools/Source/Python/Common/Misc.py            |  4 +-
BaseTools/Source/Python/Workspace/DscBuildData.py | 73 +++++++++++++++++++++--
3 files changed, 72 insertions(+), 7 deletions(-)
[edk2] [PATCH] BaseTools: Fix build argument --pcd for flexible format bugs
Posted by Feng, YunhuaX 6 years, 8 months ago
Build argument --pcd flexible format, like as:
1. VOID* type
gTokenSpaceGuid.Test=H"{flexible format}"
gTokenSpaceGuid.Test=L"string"
gTokenSpaceGuid.Test="string"
gTokenSpaceGuid.Test=L'string'
gTokenSpaceGuid.Test='string'
2. UINT8/UINT16/UINT32/UINT64 type
gTokenSpaceGuid.Test=H"{flexible format}"
gTokenSpaceGuid.Test=L"string"
gTokenSpaceGuid.Test="string"
gTokenSpaceGuid.Test=L'string'
gTokenSpaceGuid.Test='string'

In linux, single quotes need escape
gTokenSpaceGuid.Test=L\'string\'
gTokenSpaceGuid.Test=\'string\'

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/Python/AutoGen/GenMake.py        |  2 +
 BaseTools/Source/Python/Common/Misc.py            |  4 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 73 +++++++++++++++++++++--
 3 files changed, 72 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 7d3374a493..9df5d8e2d7 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -1554,6 +1554,8 @@ class TopLevelMakefile(BuildFile):
                     if pcdValue.startswith('H'):
                         pcdValue = 'H' + '"' + pcdValue[1:] + '"'
                         ExtraOption += " --pcd " + pcdName + '=' + pcdValue
+                    elif pcdValue.startswith("L'"):
+                        ExtraOption += "--pcd " + pcdName + '=' + pcdValue
                     elif pcdValue.startswith('L'):
                         pcdValue = 'L' + '"' + pcdValue[1:] + '"'
                         ExtraOption += " --pcd " + pcdName + '=' + pcdValue
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index d80f645d2e..b8c2ce1ddc 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -2353,10 +2353,10 @@ def PackRegistryFormatGuid(Guid):
 
 def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):
     if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']:
-        if Value.startswith('L'):
+        if Value.startswith('L') or Value.startswith('"'):
             if not Value[1]:
                 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"{...}"')
-            Value = Value[0] + '"' + Value[1:] + '"'
+            Value = Value
         elif Value.startswith('H'):
             if not Value[1]:
                 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"{...}"')
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 1da4f03ab8..d9165f2ac7 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -999,10 +999,39 @@ class DscBuildData(PlatformBuildClassObject):
                                     try:
                                         pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True)
                                     except BadExpression, Value:
-                                        if Value.result > 1:
-                                            EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
-                                                            (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
-                                    pcdvalue = 'H' + pcdvalue
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                    if PcdDatumType == "VOID*":
+                                        pcdvalue = 'H' + pcdvalue
+                                elif pcdvalue.startswith("L'"):
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                    if pcdvalue.startswith('{'):
+                                        pcdvalue = 'H' + pcdvalue
+                                elif pcdvalue.startswith("'"):
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                    if pcdvalue.startswith('{'):
+                                        pcdvalue = 'H' + pcdvalue
+                                elif pcdvalue.startswith('L'):
+                                    pcdvalue = 'L"' + pcdvalue[1:] + '"'
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                else:
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
                                 NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
                                 FoundFlag = True
                         else:
@@ -1018,7 +1047,41 @@ class DscBuildData(PlatformBuildClassObject):
                                             except BadExpression, Value:
                                                 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %
                                                                 (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
-                                            pcdvalue = 'H' + pcdvalue
+                                            if PcdDatumType == "VOID*":
+                                                pcdvalue = 'H' + pcdvalue
+                                        elif pcdvalue.startswith("L'"):
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(
+                                                    True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                            if pcdvalue.startswith('{'):
+                                                pcdvalue = 'H' + pcdvalue
+                                        elif pcdvalue.startswith("'"):
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(
+                                                    True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                            if pcdvalue.startswith('{'):
+                                                pcdvalue = 'H' + pcdvalue
+                                        elif pcdvalue.startswith('L'):
+                                            pcdvalue = 'L"' + pcdvalue[1:] + '"'
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(
+                                                    True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                        else:
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID,
+                                                                'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
                                         NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
                                         FoundFlag = True
                                     else:
-- 
2.12.2.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] BaseTools: Fix build argument --pcd for flexible format bugs
Posted by Zhu, Yonghong 6 years, 8 months ago
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Feng, YunhuaX 
Sent: Monday, February 05, 2018 11:43 AM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH] BaseTools: Fix build argument --pcd for flexible format bugs

Build argument --pcd flexible format, like as:
1. VOID* type
gTokenSpaceGuid.Test=H"{flexible format}"
gTokenSpaceGuid.Test=L"string"
gTokenSpaceGuid.Test="string"
gTokenSpaceGuid.Test=L'string'
gTokenSpaceGuid.Test='string'
2. UINT8/UINT16/UINT32/UINT64 type
gTokenSpaceGuid.Test=H"{flexible format}"
gTokenSpaceGuid.Test=L"string"
gTokenSpaceGuid.Test="string"
gTokenSpaceGuid.Test=L'string'
gTokenSpaceGuid.Test='string'

In linux, single quotes need escape
gTokenSpaceGuid.Test=L\'string\'
gTokenSpaceGuid.Test=\'string\'

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/Python/AutoGen/GenMake.py        |  2 +
 BaseTools/Source/Python/Common/Misc.py            |  4 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 73 +++++++++++++++++++++--
 3 files changed, 72 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 7d3374a493..9df5d8e2d7 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -1554,6 +1554,8 @@ class TopLevelMakefile(BuildFile):
                     if pcdValue.startswith('H'):
                         pcdValue = 'H' + '"' + pcdValue[1:] + '"'
                         ExtraOption += " --pcd " + pcdName + '=' + pcdValue
+                    elif pcdValue.startswith("L'"):
+                        ExtraOption += "--pcd " + pcdName + '=' + 
+ pcdValue
                     elif pcdValue.startswith('L'):
                         pcdValue = 'L' + '"' + pcdValue[1:] + '"'
                         ExtraOption += " --pcd " + pcdName + '=' + pcdValue diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index d80f645d2e..b8c2ce1ddc 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -2353,10 +2353,10 @@ def PackRegistryFormatGuid(Guid):
 
 def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):
     if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']:
-        if Value.startswith('L'):
+        if Value.startswith('L') or Value.startswith('"'):
             if not Value[1]:
                 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"{...}"')
-            Value = Value[0] + '"' + Value[1:] + '"'
+            Value = Value
         elif Value.startswith('H'):
             if not Value[1]:
                 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"{...}"') diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 1da4f03ab8..d9165f2ac7 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -999,10 +999,39 @@ class DscBuildData(PlatformBuildClassObject):
                                     try:
                                         pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True)
                                     except BadExpression, Value:
-                                        if Value.result > 1:
-                                            EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
-                                                            (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
-                                    pcdvalue = 'H' + pcdvalue
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                    if PcdDatumType == "VOID*":
+                                        pcdvalue = 'H' + pcdvalue
+                                elif pcdvalue.startswith("L'"):
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                    if pcdvalue.startswith('{'):
+                                        pcdvalue = 'H' + pcdvalue
+                                elif pcdvalue.startswith("'"):
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                    if pcdvalue.startswith('{'):
+                                        pcdvalue = 'H' + pcdvalue
+                                elif pcdvalue.startswith('L'):
+                                    pcdvalue = 'L"' + pcdvalue[1:] + '"'
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                else:
+                                    try:
+                                        pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                    except BadExpression, Value:
+                                        EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                        
+ (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
                                 NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
                                 FoundFlag = True
                         else:
@@ -1018,7 +1047,41 @@ class DscBuildData(PlatformBuildClassObject):
                                             except BadExpression, Value:
                                                 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %
                                                                 (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
-                                            pcdvalue = 'H' + pcdvalue
+                                            if PcdDatumType == "VOID*":
+                                                pcdvalue = 'H' + pcdvalue
+                                        elif pcdvalue.startswith("L'"):
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(
+                                                    True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                            if pcdvalue.startswith('{'):
+                                                pcdvalue = 'H' + pcdvalue
+                                        elif pcdvalue.startswith("'"):
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(
+                                                    True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                            if pcdvalue.startswith('{'):
+                                                pcdvalue = 'H' + pcdvalue
+                                        elif pcdvalue.startswith('L'):
+                                            pcdvalue = 'L"' + pcdvalue[1:] + '"'
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(
+                                                    True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s",  %s' %
+                                                                (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
+                                        else:
+                                            try:
+                                                pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True)
+                                            except BadExpression, Value:
+                                                EdkLogger.error('Parser', FORMAT_INVALID,
+                                                                'PCD [%s.%s] Value "%s",  %s' %
+                                                                
+ (TokenSpaceGuidCName, TokenCName, pcdvalue, Value))
                                         NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
                                         FoundFlag = True
                                     else:
--
2.12.2.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel