Please remove the trailing whitespace when commit.

Reviewed-by: Yonghong Zhu <yonghong....@intel.com> 


Best Regards,
Zhu Yonghong


-----Original Message-----
From: Chen, Hesheng 
Sent: Friday, July 29, 2016 10:31 AM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong <yonghong....@intel.com>
Subject: [patch 2/2] BaseTool/Upt: Add support for Private

Support new syntax in package DEC file as below:
[Includes.Common.Private]
[Ppis.Common.Private]
[Guids.Common.Private]
[Protocols.Common.Private]

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: hesschen <hesheng.c...@intel.com>
---
 .../Source/Python/UPT/GenMetaFile/GenDecFile.py    |  9 +++++++-
 BaseTools/Source/Python/UPT/Library/DataType.py    |  4 +++-
 .../Source/Python/UPT/Library/UniClassObject.py    | 16 +++++++-------
 BaseTools/Source/Python/UPT/Parser/DecParser.py    | 25 ++++++++++++++++++++--
 .../Python/UPT/PomAdapter/DecPomAlignment.py       | 11 +++++++++-
 5 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py 
b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
index f22363b..31abd23 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
@@ -2,7 +2,7 @@
 #
 # This file contained the logical of transfer package object to DEC files.
 #
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2016, 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 @@ 
-63,6 +63,7 @@ from Library.DataType import TAB_PCD_ERROR  from 
Library.DataType import TAB_SECTION_START  from Library.DataType import 
TAB_SECTION_END  from Library.DataType import TAB_SPLIT
+import Library.DataType as DT
 from Library.UniClassObject import FormatUniEntry
 
 def GenPcd(Package, Content):
@@ -487,6 +488,12 @@ def PackageToDec(Package, DistHeader = None):
         if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID and \
             UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER:
             continue
+
+        # Generate Private Section first
+        if UserExtension.GetUserID() == DT.TAB_INTEL and 
UserExtension.GetIdentifier() == DT.TAB_PRIVATE:
+            Content += '\n' + UserExtension.GetStatement()
+            continue
+
         Statement = UserExtension.GetStatement()
         if not Statement:
             continue
diff --git a/BaseTools/Source/Python/UPT/Library/DataType.py 
b/BaseTools/Source/Python/UPT/Library/DataType.py
index 8449dc8..c151be3 100644
--- a/BaseTools/Source/Python/UPT/Library/DataType.py
+++ b/BaseTools/Source/Python/UPT/Library/DataType.py
@@ -1,7 +1,7 @@
 ## @file
 # This file is used to define class for data type structure  # -# Copyright 
(c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2016, 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 @@ 
-680,6 +680,8 @@ TAB_DEFINE = 'DEFINE'
 TAB_NMAKE = 'Nmake'
 TAB_USER_EXTENSIONS = 'UserExtensions'
 TAB_INCLUDE = '!include'
+TAB_PRIVATE = 'Private'
+TAB_INTEL = 'Intel'
 
 #
 # Common Define
diff --git a/BaseTools/Source/Python/UPT/Library/UniClassObject.py 
b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
index 1e73d3e..27804cc 100644
--- a/BaseTools/Source/Python/UPT/Library/UniClassObject.py
+++ b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
@@ -328,11 +328,11 @@ class UniFileClassObject(object):
         Lang = distutils.util.split_quoted((Line.split(u"//")[0]))
         if len(Lang) != 3:
             try:
-                FileIn = codecs.open(File.Path, mode='rb', 
encoding='utf_8').read()
+                FileIn = codecs.open(File.Path, mode='rb', 
+ encoding='utf_8').readlines()
             except UnicodeError, Xstr:
-                FileIn = codecs.open(File.Path, mode='rb', 
encoding='utf_16').read()
+                FileIn = codecs.open(File.Path, mode='rb', 
+ encoding='utf_16').readlines()
             except UnicodeError, Xstr:
-                FileIn = codecs.open(File.Path, mode='rb', 
encoding='utf_16_le').read()
+                FileIn = codecs.open(File.Path, mode='rb', 
+ encoding='utf_16_le').readlines()
             except:
                 EdkLogger.Error("Unicode File Parser", 
                                 ToolError.FILE_OPEN_FAILURE, @@ -437,7 +437,7 
@@ class UniFileClassObject(object):
 #                             ExtraData='The file %s is either invalid 
UTF-16LE or it is missing the BOM.' % File.Path)
 
         try:
-            FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').read()
+            FileIn = codecs.open(File.Path, mode='rb', 
+ encoding='utf_8').readlines()
         except UnicodeError, Xstr:
             FileIn = codecs.open(File.Path, mode='rb', 
encoding='utf_16').readlines()
         except UnicodeError:
@@ -579,9 +579,9 @@ class UniFileClassObject(object):
             #
             if Line.startswith(u'"'):
                 if StringEntryExistsFlag == 2:
-                    EdkLogger.Error("Unicode File Parser", 
ToolError.FORMAT_INVALID, 
+                    EdkLogger.Error("Unicode File Parser", 
+ ToolError.FORMAT_INVALID,
                                     Message=ST.ERR_UNIPARSE_LINEFEED_UP_EXIST 
% Line, ExtraData=File.Path)
-                     
+
                 StringEntryExistsFlag = 1
                 if not Line.endswith('"'):
                     EdkLogger.Error("Unicode File Parser", 
ToolError.FORMAT_INVALID, @@ -589,7 +589,7 @@ class UniFileClassObject(object):
                                               % (LineCount, File.Path))
             elif Line.startswith(u'#language'):
                 if StringEntryExistsFlag == 2:
-                    EdkLogger.Error("Unicode File Parser", 
ToolError.FORMAT_INVALID, 
+                    EdkLogger.Error("Unicode File Parser", 
+ ToolError.FORMAT_INVALID,
                                     Message=ST.ERR_UNI_MISS_STRING_ENTRY % 
Line, ExtraData=File.Path)
                 StringEntryExistsFlag = 0
             else:
@@ -1050,7 +1050,7 @@ class UniFileClassObject(object):
                              ToolError.FILE_NOT_FOUND,
                              ExtraData=FilaPath)
         try:
-            FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_8').read()
+            FileIn = codecs.open(FilaPath, mode='rb', 
+ encoding='utf_8').readlines()
         except UnicodeError, Xstr:
             FileIn = codecs.open(FilaPath, mode='rb', 
encoding='utf_16').readlines()
         except UnicodeError:
diff --git a/BaseTools/Source/Python/UPT/Parser/DecParser.py 
b/BaseTools/Source/Python/UPT/Parser/DecParser.py
index 23d1ed4..e6658a9 100644
--- a/BaseTools/Source/Python/UPT/Parser/DecParser.py
+++ b/BaseTools/Source/Python/UPT/Parser/DecParser.py
@@ -1,7 +1,7 @@
 ## @file
 # This file is used to parse DEC file. It will consumed by DecParser  # -# 
Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2016, 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 @@ 
-742,7 +742,26 @@ class Dec(_DecBase, _DecComments):
         except BaseException:
             Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile,
                          ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile)
-        RawData = FileContent(DecFile, Content)
+        
+        #
+        # Pre-parser for Private section
+        #
+        self._Private = ''
+        __IsFoundPrivate = False
+        NewContent = []
+        for Line in Content:
+            Line = Line.strip()
+            if Line.startswith(DT.TAB_SECTION_START) and 
Line.endswith(DT.TAB_PRIVATE + DT.TAB_SECTION_END):
+                __IsFoundPrivate = True
+            if Line.startswith(DT.TAB_SECTION_START) and 
Line.endswith(DT.TAB_SECTION_END)\
+               and not Line.endswith(DT.TAB_PRIVATE + DT.TAB_SECTION_END):
+                __IsFoundPrivate = False
+            if __IsFoundPrivate:
+                self._Private += Line + '\r'
+            if not __IsFoundPrivate:
+                NewContent.append(Line + '\r')
+        
+        RawData = FileContent(DecFile, NewContent)
         
         _DecComments.__init__(self)
         _DecBase.__init__(self, RawData) @@ -1060,3 +1079,5 @@ class 
Dec(_DecBase, _DecComments):
         return self._Define.GetDataObject().GetPackageVersion()
     def GetPackageUniFile(self):
         return self._Define.GetDataObject().GetPackageUniFile()
+    def GetPrivateSections(self):
+        return self._Private
diff --git a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py 
b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
index 11b0359..88edf35 100644
--- a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
+++ b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
@@ -1,7 +1,7 @@
 ## @file DecPomAlignment.py
 # This file contained the adapter for convert INF parser object to POM Object  
# -# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2016, 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 @@ 
-63,6 +63,7 @@ from Library.DataType import TAB_STR_TOKENHELP  from 
Library.DataType import TAB_STR_TOKENERR  from Library.DataType import 
TAB_HEX_START  from Library.DataType import TAB_SPLIT
+import Library.DataType as DT
 from Library.CommentParsing import ParseHeaderCommentSection  from 
Library.CommentParsing import ParseGenericComment  from Library.CommentParsing 
import ParseDecPcdGenericComment @@ -221,6 +222,14 @@ class 
DecPomAlignment(PackageObject):
             self.SetUserExtensionList(
                 self.GetUserExtensionList() + [UserExtension]
             )
+        
+        # Add Private sections to UserExtension
+        if self.DecParser.GetPrivateSections():
+            PrivateUserExtension = UserExtensionObject()
+            
PrivateUserExtension.SetStatement(self.DecParser.GetPrivateSections())
+            PrivateUserExtension.SetIdentifier(DT.TAB_PRIVATE)
+            PrivateUserExtension.SetUserID(DT.TAB_INTEL)
+            self.SetUserExtensionList(self.GetUserExtensionList() + 
+ [PrivateUserExtension])
             
     ## Generate miscellaneous files on DEC file
     #
--
2.7.2.windows.1

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

Reply via email to