diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-08-03 03:29:17 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-08-03 03:29:17 +0000 |
commit | 756ad8f8e9d3e345f1883546e2a3125203e234aa (patch) | |
tree | ebf62958cef3e28d31af0cbb265a1c64c212ab52 /BaseTools/Source/Python/AutoGen | |
parent | 934309d58ed2de3a41ec3fe577122d434615dd4c (diff) | |
download | edk2-platforms-756ad8f8e9d3e345f1883546e2a3125203e234aa.tar.xz |
Sync EDKII BaseTools to BaseTools project r2006.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10764 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/AutoGen')
-rw-r--r-- | BaseTools/Source/Python/AutoGen/GenC.py | 2 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/GenMake.py | 3 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/StrGather.py | 26 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/UniClassObject.py | 140 |
4 files changed, 102 insertions, 69 deletions
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index f0f92b0865..1db68ebec5 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -1888,7 +1888,7 @@ def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuff else: ShellMode = False - Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer) + Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer) if CompatibleMode or UniGenCFlag: AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n") AutoGenC.Append(Code) diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index e3f5c2b6ec..2e18f6771c 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -26,7 +26,7 @@ from BuildEngine import * import Common.GlobalData as GlobalData ## Regular expression for finding header file inclusions -gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:[\"<]?[ \t]*)([\w.\\/]+)(?:[ \t]*[\">]?)", re.MULTILINE|re.UNICODE) +gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:[\"<]?[ \t]*)([\w.\\/() \t]+)(?:[ \t]*[\">]?)", re.MULTILINE|re.UNICODE|re.IGNORECASE) ## Regular expression for matching macro used in header file inclusion gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE) @@ -754,6 +754,7 @@ cleanlib: CurrentFilePath = F.Dir for Inc in IncludedFileList: + Inc = Inc.strip() # if there's macro used to reference header file, expand it HeaderList = gMacroPattern.findall(Inc) if len(HeaderList) == 1 and len(HeaderList[0]) == 2: diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py index 1759da72dd..52ab439e9b 100644 --- a/BaseTools/Source/Python/AutoGen/StrGather.py +++ b/BaseTools/Source/Python/AutoGen/StrGather.py @@ -1,4 +1,4 @@ -# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# 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
@@ -168,6 +168,8 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag): Str = WriteLine(Str, Line)
Line = COMMENT_DEFINE_STR + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + PRINTABLE_LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(1, 4) + COMMENT_NOT_REFERENCED
Str = WriteLine(Str, Line)
+
+ #Group the referred STRING token together.
for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])):
StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index]
Name = StringItem.StringName
@@ -180,12 +182,22 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag): Line = DEFINE_STR + ' ' + Name + ' ' + DecToHexStr(Token, 4)
else:
Line = DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4)
- else:
+ Str = WriteLine(Str, Line)
+
+ #Group the unused STRING token together.
+ for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])):
+ StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index]
+ Name = StringItem.StringName
+ Token = StringItem.Token
+ Referenced = StringItem.Referenced
+ if Name != None:
+ Line = ''
+ if Referenced == False:
if (ValueStartPtr - len(DEFINE_STR + Name)) <= 0:
Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED
else:
Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED
- Str = WriteLine(Str, Line)
+ Str = WriteLine(Str, Line)
Str = WriteLine(Str, '')
if IsCompatibleMode or UniGenCFlag:
@@ -506,7 +518,7 @@ def SearchString(UniObjectClass, FileList, IsCompatibleMode): # This function is used for UEFI2.1 spec
#
#
-def GetStringFiles(UniFilList, SourceFileList, IncludeList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None):
+def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None):
Status = True
ErrorMessage = ''
@@ -515,15 +527,15 @@ def GetStringFiles(UniFilList, SourceFileList, IncludeList, SkipList, BaseName, #
# support ISO 639-2 codes in .UNI files of EDK Shell
#
- Uni = UniFileClassObject(UniFilList, True)
+ Uni = UniFileClassObject(sorted (UniFilList), True, IncludePathList)
else:
- Uni = UniFileClassObject(UniFilList, IsCompatibleMode)
+ Uni = UniFileClassObject(sorted (UniFilList), IsCompatibleMode, IncludePathList)
else:
EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, 'No unicode files given')
FileList = GetFileList(SourceFileList, IncludeList, SkipList)
- Uni = SearchString(Uni, FileList, IsCompatibleMode)
+ Uni = SearchString(Uni, sorted (FileList), IsCompatibleMode)
HFile = CreateHFile(BaseName, Uni, IsCompatibleMode, UniGenCFlag)
CFile = None
diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py index 8f929a33cb..76a0549a75 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -177,18 +177,24 @@ class StringDefClassObject(object): repr(self.StringValue) + ' ' + \
repr(self.UseOtherLangDef)
+ def UpdateValue(self, Value = None):
+ if Value != None:
+ self.StringValue = Value + u'\x00' # Add a NULL at string tail
+ self.StringValueByteList = UniToHexList(self.StringValue)
+ self.Length = len(self.StringValueByteList)
+
## UniFileClassObject
#
# A structure for .uni file definition
#
class UniFileClassObject(object):
- def __init__(self, FileList = [], IsCompatibleMode = False):
+ def __init__(self, FileList = [], IsCompatibleMode = False, IncludePathList = []):
self.FileList = FileList
self.Token = 2
self.LanguageDef = [] #[ [u'LanguageIdentifier', u'PrintableName'], ... ]
self.OrderedStringList = {} #{ u'LanguageIdentifier' : [StringDefClassObject] }
self.IsCompatibleMode = IsCompatibleMode
-
+ self.IncludePathList = IncludePathList
if len(self.FileList) > 0:
self.LoadUniFiles(FileList)
@@ -226,6 +232,21 @@ class UniFileClassObject(object): self.AddStringToList(u'$LANGUAGE_NAME', LangName, LangName, 0, True, Index=0)
self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', LangName, LangPrintName, 1, True, Index=1)
+ if not IsLangInDef:
+ #
+ # The found STRING tokens will be added into new language string list
+ # so that the unique STRING identifier is reserved for all languages in the package list.
+ #
+ FirstLangName = self.LanguageDef[0][0]
+ if LangName != FirstLangName:
+ for Index in range (2, len (self.OrderedStringList[FirstLangName])):
+ Item = self.OrderedStringList[FirstLangName][Index]
+ if Item.UseOtherLangDef != '':
+ OtherLang = Item.UseOtherLangDef
+ else:
+ OtherLang = FirstLangName
+ self.OrderedStringList[LangName].append (StringDefClassObject(Item.StringName, '', Item.Referenced, Item.Token, OtherLang))
+
return True
#
@@ -266,7 +287,6 @@ class UniFileClassObject(object): if not os.path.exists(File.Path) or not os.path.isfile(File.Path):
EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path)
- Dir = File.Dir
try:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf-16').readlines()
except UnicodeError, X:
@@ -309,7 +329,13 @@ class UniFileClassObject(object): IncList = gIncludePattern.findall(Line)
if len(IncList) == 1:
- Lines.extend(self.PreProcess(PathClass(str(IncList[0]), Dir)))
+ for Dir in [File.Dir] + self.IncludePathList:
+ IncFile = PathClass(str(IncList[0]), Dir)
+ if os.path.isfile(IncFile.Path):
+ Lines.extend(self.PreProcess(IncFile))
+ break
+ else:
+ EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, Message="Cannot find include file", ExtraData=str(IncList[0]))
continue
Lines.append(Line)
@@ -421,15 +447,30 @@ class UniFileClassObject(object): if Language not in self.OrderedStringList:
self.OrderedStringList[Language] = []
- IsAdded = False
+ IsAdded = True
for Item in self.OrderedStringList[Language]:
if Name == Item.StringName:
- IsAdded = True
+ IsAdded = False
+ if Value != None:
+ Item.UpdateValue(Value)
+ Item.UseOtherLangDef = ''
break
- if not IsAdded:
+
+ if IsAdded:
Token = len(self.OrderedStringList[Language])
if Index == -1:
self.OrderedStringList[Language].append(StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef))
+ for LangName in self.LanguageDef:
+ #
+ # New STRING token will be added into all language string lists.
+ # so that the unique STRING identifier is reserved for all languages in the package list.
+ #
+ if LangName[0] != Language:
+ if UseOtherLangDef != '':
+ OtherLangDef = UseOtherLangDef
+ else:
+ OtherLangDef = Language
+ self.OrderedStringList[LangName[0]].append(StringDefClassObject(Name, '', Referenced, Token, OtherLangDef))
else:
self.OrderedStringList[Language].insert(Index, StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef))
@@ -437,11 +478,15 @@ class UniFileClassObject(object): # Set the string as referenced
#
def SetStringReferenced(self, Name):
- for Lang in self.OrderedStringList:
- for Item in self.OrderedStringList[Lang]:
- if Name == Item.StringName:
- Item.Referenced = True
- break
+ #
+ # String stoken are added in the same order in all language string lists.
+ # So, only update the status of string stoken in first language string list.
+ #
+ Lang = self.LanguageDef[0][0]
+ for Item in self.OrderedStringList[Lang]:
+ if Name == Item.StringName:
+ Item.Referenced = True
+ break
#
# Search the string in language definition by Name
#
@@ -467,61 +512,36 @@ class UniFileClassObject(object): #
def ReToken(self):
#
- # Search each string to find if it is defined for each language
- # Use secondary language value to replace if missing in any one language
- #
- for IndexI in range(0, len(self.LanguageDef)):
- LangKey = self.LanguageDef[IndexI][0]
- for Item in self.OrderedStringList[LangKey]:
- Name = Item.StringName
- Value = Item.StringValue[0:-1]
- Referenced = Item.Referenced
- Index = self.OrderedStringList[LangKey].index(Item)
- for IndexJ in range(0, len(self.LanguageDef)):
- LangFind = self.LanguageDef[IndexJ][0]
- if self.FindStringValue(Name, LangFind) == None:
- EdkLogger.debug(EdkLogger.DEBUG_5, Name)
- Token = len(self.OrderedStringList[LangFind])
- self.AddStringToList(Name, LangFind, Value, Token, Referenced, LangKey, Index)
- #
- # Retoken
+ # Retoken all language strings according to the status of string stoken in the first language string.
#
- # First re-token the first language
- LangName = self.LanguageDef[0][0]
- ReferencedStringList = []
- NotReferencedStringList = []
- Token = 0
+ FirstLangName = self.LanguageDef[0][0]
#
- # Order UNI token by their String Name
+ # Use small token for all referred string stoken.
#
- StringNameList = []
- for Item in self.OrderedStringList[LangName]:
- StringNameList.append (Item.StringName)
- StringNameList.sort()
-
- for Name in StringNameList:
- Item = self.FindStringValue (Name, LangName)
- if Item.Referenced == True:
- Item.Token = Token
- ReferencedStringList.append(Item)
- Token = Token + 1
- else:
- NotReferencedStringList.append(Item)
- self.OrderedStringList[LangName] = ReferencedStringList
- for Index in range(len(NotReferencedStringList)):
- NotReferencedStringList[Index].Token = Token + Index
- self.OrderedStringList[LangName].append(NotReferencedStringList[Index])
+ RefToken = 0
+ for Index in range (0, len (self.OrderedStringList[FirstLangName])):
+ FirstLangItem = self.OrderedStringList[FirstLangName][Index]
+ if FirstLangItem.Referenced == True:
+ for LangNameItem in self.LanguageDef:
+ LangName = LangNameItem[0]
+ OtherLangItem = self.OrderedStringList[LangName][Index]
+ OtherLangItem.Referenced = True
+ OtherLangItem.Token = RefToken
+ RefToken = RefToken + 1
#
- # Adjust the orders of other languages
+ # Use big token for all unreferred string stoken.
#
- for IndexOfLanguage in range(1, len(self.LanguageDef)):
- for OrderedString in self.OrderedStringList[LangName]:
- for UnOrderedString in self.OrderedStringList[self.LanguageDef[IndexOfLanguage][0]]:
- if OrderedString.StringName == UnOrderedString.StringName:
- UnOrderedString.Token = OrderedString.Token
- break
+ UnRefToken = 0
+ for Index in range (0, len (self.OrderedStringList[FirstLangName])):
+ FirstLangItem = self.OrderedStringList[FirstLangName][Index]
+ if FirstLangItem.Referenced == False:
+ for LangNameItem in self.LanguageDef:
+ LangName = LangNameItem[0]
+ OtherLangItem = self.OrderedStringList[LangName][Index]
+ OtherLangItem.Token = RefToken + UnRefToken
+ UnRefToken = UnRefToken + 1
#
# Show the instance itself
|