X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FMisc.py;h=af374d804d86b8a01a5fee2ae38b0c2968169eaf;hp=15ad9e4f2eca37851748f578708b3328c1d467dc;hb=4faf13222edead307109bf8c747200ea3fb617c0;hpb=7dbc50bd244d95fdc1741b9cfc561f0bfd724de1
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 15ad9e4f2e..af374d804d 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1,7 +1,7 @@
## @file
# Common routines used by all tools
#
-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -1443,21 +1443,26 @@ def ParseConsoleLog(Filename):
def AnalyzePcdExpression(Setting):
Setting = Setting.strip()
- # There might be escaped quote in a string: \", \\\"
- Data = Setting.replace('\\\\', '//').replace('\\\"', '\\\'')
+ # There might be escaped quote in a string: \", \\\" , \', \\\'
+ Data = Setting
# There might be '|' in string and in ( ... | ... ), replace it with '-'
NewStr = ''
- InStr = False
+ InSingleQuoteStr = False
+ InDoubleQuoteStr = False
Pair = 0
- for ch in Data:
- if ch == '"':
- InStr = not InStr
- elif ch == '(' and not InStr:
+ for Index, ch in enumerate(Data):
+ if ch == '"' and not InSingleQuoteStr:
+ if Data[Index - 1] != '\\':
+ InDoubleQuoteStr = not InDoubleQuoteStr
+ elif ch == "'" and not InDoubleQuoteStr:
+ if Data[Index - 1] != '\\':
+ InSingleQuoteStr = not InSingleQuoteStr
+ elif ch == '(' and not (InSingleQuoteStr or InDoubleQuoteStr):
Pair += 1
- elif ch == ')' and not InStr:
+ elif ch == ')' and not (InSingleQuoteStr or InDoubleQuoteStr):
Pair -= 1
- if (Pair > 0 or InStr) and ch == TAB_VALUE_SPLIT:
+ if (Pair > 0 or InSingleQuoteStr or InDoubleQuoteStr) and ch == TAB_VALUE_SPLIT:
NewStr += '-'
else:
NewStr += ch
@@ -1535,16 +1540,10 @@ def ParseFieldValue (Value):
if Value.startswith('GUID') and Value.endswith(')'):
Value = Value.split('(', 1)[1][:-1].strip()
if Value[0] == '{' and Value[-1] == '}':
- Value = Value[1:-1].strip()
- Value = Value.split('{', 1)
- Value = ['%02x' % int(Item, 16) for Item in (Value[0] + Value[1][:-1]).split(',')]
- if len(Value[0]) != 8:
- Value[0] = '%08X' % int(Value[0], 16)
- if len(Value[1]) != 4:
- Value[1] = '%04X' % int(Value[1], 16)
- if len(Value[2]) != 4:
- Value[2] = '%04X' % int(Value[2], 16)
- Value = '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '-' + ''.join(Value[5:11])
+ TmpValue = GuidStructureStringToGuidString(Value)
+ if len(TmpValue) == 0:
+ raise BadExpression("Invalid GUID value string %s" % Value)
+ Value = TmpValue
if Value[0] == '"' and Value[-1] == '"':
Value = Value[1:-1]
try:
@@ -1555,7 +1554,13 @@ def ParseFieldValue (Value):
return Value, 16
if Value.startswith('L"') and Value.endswith('"'):
# Unicode String
- List = list(Value[2:-1])
+ # translate escape character
+ Value = Value[1:]
+ try:
+ Value = eval(Value)
+ except:
+ Value = Value[1:-1]
+ List = list(Value)
List.reverse()
Value = 0
for Char in List:
@@ -1563,7 +1568,12 @@ def ParseFieldValue (Value):
return Value, (len(List) + 1) * 2
if Value.startswith('"') and Value.endswith('"'):
# ASCII String
- List = list(Value[1:-1])
+ # translate escape character
+ try:
+ Value = eval(Value)
+ except:
+ Value = Value[1:-1]
+ List = list(Value)
List.reverse()
Value = 0
for Char in List:
@@ -1571,7 +1581,15 @@ def ParseFieldValue (Value):
return Value, len(List) + 1
if Value.startswith("L'") and Value.endswith("'"):
# Unicode Character Constant
- List = list(Value[2:-1])
+ # translate escape character
+ Value = Value[1:]
+ try:
+ Value = eval(Value)
+ except:
+ Value = Value[1:-1]
+ List = list(Value)
+ if len(List) == 0:
+ raise BadExpression('Length %s is %s' % (Value, len(List)))
List.reverse()
Value = 0
for Char in List:
@@ -1579,7 +1597,14 @@ def ParseFieldValue (Value):
return Value, len(List) * 2
if Value.startswith("'") and Value.endswith("'"):
# Character constant
- List = list(Value[1:-1])
+ # translate escape character
+ try:
+ Value = eval(Value)
+ except:
+ Value = Value[1:-1]
+ List = list(Value)
+ if len(List) == 0:
+ raise BadExpression('Length %s is %s' % (Value, len(List)))
List.reverse()
Value = 0
for Char in List:
@@ -1599,7 +1624,8 @@ def ParseFieldValue (Value):
Value = (Value << 8) | ((ItemValue >> 8 * I) & 0xff)
return Value, RetSize
if Value.startswith('DEVICE_PATH(') and Value.endswith(')'):
- Value = Value.split('"')[1]
+ Value = Value.replace("DEVICE_PATH(", '').rstrip(')')
+ Value = Value.strip().strip('"')
return ParseDevPathValue(Value)
if Value.lower().startswith('0x'):
Value = int(Value, 16)
@@ -1818,10 +1844,10 @@ def CheckPcdDatum(Type, Value):
if Type == "VOID*":
ValueRe = re.compile(r'\s*L?\".*\"\s*$')
if not (((Value.startswith('L"') or Value.startswith('"')) and Value.endswith('"'))
- or (Value.startswith('{') and Value.endswith('}'))
+ or (Value.startswith('{') and Value.endswith('}')) or (Value.startswith("L'") or Value.startswith("'") and Value.endswith("'"))
):
return False, "Invalid value [%s] of type [%s]; must be in the form of {...} for array"\
- ", or \"...\" for string, or L\"...\" for unicode string" % (Value, Type)
+ ", \"...\" or \'...\' for string, L\"...\" or L\'...\' for unicode string" % (Value, Type)
elif ValueRe.match(Value):
# Check the chars in UnicodeString or CString is printable
if Value.startswith("L"):
@@ -2240,6 +2266,10 @@ class SkuClass():
GlobalData.gSkuids = (self.SkuIdSet)
if 'COMMON' in GlobalData.gSkuids:
GlobalData.gSkuids.remove('COMMON')
+ if self.SkuUsageType == self.SINGLE:
+ if len(GlobalData.gSkuids) != 1:
+ if 'DEFAULT' in GlobalData.gSkuids:
+ GlobalData.gSkuids.remove('DEFAULT')
if GlobalData.gSkuids:
GlobalData.gSkuids.sort()
@@ -2251,6 +2281,8 @@ class SkuClass():
return self.__SkuInherit.get(skuname,"DEFAULT")
def GetSkuChain(self,sku):
+ if sku == "DEFAULT":
+ return ["DEFAULT"]
skulist = [sku]
nextsku = sku
while 1:
@@ -2346,11 +2378,11 @@ def PackRegistryFormatGuid(Guid):
)
def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):
- if PcdDatumType == 'VOID*':
- if Value.startswith('L'):
+ if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']:
+ 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"{...}"')