public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTool: Enhance error handling.
@ 2018-01-29  3:22 BobCF
  2018-01-30  9:27 ` Gao, Liming
  0 siblings, 1 reply; 4+ messages in thread
From: BobCF @ 2018-01-29  3:22 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 113 ++++++++++++---------
 .../Source/Python/Workspace/MetaFileParser.py      |   3 +
 2 files changed, 68 insertions(+), 48 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index bc77d1a2b4..bebd4feda0 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -856,11 +856,11 @@ class DscBuildData(PlatformBuildClassObject):
             if not Valid:
                 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
                                 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
             if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):
                 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():
-                    EdkLogger.error('build', FORMAT_INVALID, ErrStr , File=self.MetaFile, Line=LineNo,
+                    EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtype used in DSC file is not the same as its declaration in DEC file." , File=self.MetaFile, Line=LineNo,
                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
         return ValueList
 
     def _FilterPcdBySkuUsage(self,Pcds):
         available_sku = self.SkuIdMgr.AvailableSkuIdSet
@@ -1009,17 +1009,20 @@ class DscBuildData(PlatformBuildClassObject):
         StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)
         S_pcd_set = {}
         for str_pcd in StrPcdSet:
             str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
             str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
+            if not isinstance (str_pcd_dec, StructurePcd):
+                EdkLogger.error('build', PARSER_ERROR,
+                            "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
+                            File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
             if str_pcd_dec:
                 str_pcd_obj_str = StructurePcd()
                 str_pcd_obj_str.copy(str_pcd_dec)
                 if str_pcd_obj:
                     str_pcd_obj_str.copy(str_pcd_obj)
-                    if str_pcd_obj.DefaultValue:
-                        str_pcd_obj_str.DefaultFromDSC = str_pcd_obj.DefaultValue
+                str_pcd_obj_str.DefaultFromDSC = str_pcd_obj_str.DefaultValue
                 for str_pcd_data in StrPcdSet[str_pcd]:
                     if str_pcd_data[3] in SkuIds:
                         str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File,LineNo=str_pcd_data[5])
                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
             else:
@@ -1153,11 +1156,11 @@ class DscBuildData(PlatformBuildClassObject):
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
             if SkuName in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):
                 if "." not in TokenSpaceGuid:
-                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
+                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
                 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting
 
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:
             Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]
             if Setting == None:
@@ -1262,16 +1265,13 @@ class DscBuildData(PlatformBuildClassObject):
 
     def ExecuteCommand (self, Command):
         try:
             Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
         except:
-            print 'ERROR: Can not execute command:', Command
-            sys.exit(1)
+            EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)
         Result = Process.communicate()
-        if Process.returncode <> 0:
-            print 'ERROR: Can not collect output from command:', Command
-        return Result[0], Result[1]
+        return Process.returncode, Result[0], Result[1]
 
     def IntToCString(self, Value, ValueSize):
         Result = '"'
         if not isinstance (Value, str):
             for Index in range(0, ValueSize):
@@ -1383,11 +1383,11 @@ class DscBuildData(PlatformBuildClassObject):
                 for FieldName in FieldList:
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
                     try:
                         Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
                     except Exception:
-                        print FieldList[FieldName][0]
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
                     if isinstance(Value, str):
                         CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     elif IsArray:
                         #
                         # Use memcpy() to copy value into field
@@ -1421,11 +1421,11 @@ class DscBuildData(PlatformBuildClassObject):
                     for FieldName in FieldList:
                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
                         try:
                             Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
                         except Exception:
-                            print FieldList[FieldName][0]
+                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
                         if isinstance(Value, str):
                             CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                         elif IsArray:
                         #
                         # Use memcpy() to copy value into field
@@ -1597,54 +1597,71 @@ class DscBuildData(PlatformBuildClassObject):
         File.write(InitByteValue)
         File.close()
 
         Messages = ''
         if sys.platform == "win32":
-            StdOut, StdErr = self.ExecuteCommand ('nmake clean & nmake -f %s' % (MakeFileName))
+            MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
             Messages = StdOut
         else:
-            StdOut, StdErr = self.ExecuteCommand ('make clean & make -f %s' % (MakeFileName))
+            MakeCommand = 'make clean & make -f %s' % (MakeFileName)
+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
             Messages = StdErr
         Messages = Messages.split('\n')
-        for Message in Messages:
-            if " error" in Message:
-                FileInfo = Message.strip().split('(')
-                if len (FileInfo) > 1:
-                    FileName = FileInfo [0]
-                    FileLine = FileInfo [1].split (')')[0]
-                else:
-                    FileInfo = Message.strip().split(':')
-                    FileName = FileInfo [0]
-                    FileLine = FileInfo [1]
-
-                File = open (FileName, 'r')
-                FileData = File.readlines()
-                File.close()
-                error_line = FileData[int (FileLine) - 1]
-                if r"//" in error_line:
-                    c_line,dsc_line = error_line.split(r"//")
-                else:
-                    dsc_line = error_line
-
-                message_itmes = Message.split(":")
-                Index = 0
-                for item in message_itmes:
-                    if "PcdValueInit.c" in item:
-                        Index = message_itmes.index(item)
-                        message_itmes[Index] = dsc_line.strip()
-                        break
+        MessageGroup = []
+        if returncode <>0:
+            CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
+            File = open (CAppBaseFileName + '.c', 'r')
+            FileData = File.readlines()
+            File.close()
+            for Message in Messages:
+                if " error" in Message or "warning" in Message:
+                    FileInfo = Message.strip().split('(')
+                    if len (FileInfo) > 1:
+                        FileName = FileInfo [0]
+                        FileLine = FileInfo [1].split (')')[0]
+                    else:
+                        FileInfo = Message.strip().split(':')
+                        FileName = FileInfo [0]
+                        FileLine = FileInfo [1]
 
-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, ":".join(message_itmes[Index:]))
+                    error_line = FileData[int (FileLine) - 1]
+                    if r"//" in error_line:
+                        c_line,dsc_line = error_line.split(r"//")
+                    else:
+                        dsc_line = error_line
+
+                    message_itmes = Message.split(":")
+                    Index = 0
+                    if "PcdValueInit.c" not in Message:
+                        break
+                    else:
+                        for item in message_itmes:
+                            if "PcdValueInit.c" in item:
+                                Index = message_itmes.index(item)
+                                message_itmes[Index] = dsc_line.strip()
+                                break
+                        MessageGroup.append(":".join(message_itmes[Index:]).strip())
+                        continue
+            if MessageGroup:
+                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )
+            else:
+                EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)
 
         PcdValueInitExe = PcdValueInitName
         if not sys.platform == "win32":
             PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName)
 
-        StdOut, StdErr = self.ExecuteCommand (PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile))
-        File = open (OutputValueFile, 'r')
-        FileBuffer = File.readlines()
-        File.close()
+        Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)
+        returncode, StdOut, StdErr = self.ExecuteCommand (Command)
+        if returncode <> 0:
+            EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)
+            FileBuffer = []
+        else:
+            File = open (OutputValueFile, 'r')
+            FileBuffer = File.readlines()
+            File.close()
 
         StructurePcdSet = []
         for Pcd in FileBuffer:
             PcdValue = Pcd.split ('|')
             PcdInfo = PcdValue[0].split ('.')
@@ -1677,11 +1694,11 @@ class DscBuildData(PlatformBuildClassObject):
             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
             if "." not in TokenSpaceGuid:
-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
 
         # Remove redundant PCD candidates, per the ARCH and SKU
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
 
@@ -1833,11 +1850,11 @@ class DscBuildData(PlatformBuildClassObject):
                                             File=self.MetaFile, Line=Dummy5)
             if DefaultStore not in DefaultStoresDefine:
                 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore,
                                             File=self.MetaFile, Line=Dummy5)
             if "." not in TokenSpaceGuid:
-                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4))
+                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy5))
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] = Setting
 
 
         # Remove redundant PCD candidates, per the ARCH and SKU
         for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in PcdSet:
@@ -1985,11 +2002,11 @@ class DscBuildData(PlatformBuildClassObject):
             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
             if "." not in TokenSpaceGuid:
-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
 
         # Remove redundant PCD candidates, per the ARCH and SKU
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
             Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index d704809354..8f4b5e5cc1 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1913,10 +1913,13 @@ class DecParser(MetaFileParser):
                 PcdTockens = self._CurrentLine.split(TAB_VALUE_SPLIT)
                 PcdNames = PcdTockens[0].split(TAB_SPLIT)
                 if len(PcdNames) == 2:
                     self._CurrentStructurePcdName = ""
                 else:
+                    if self._CurrentStructurePcdName != TAB_SPLIT.join(PcdNames[:2]):
+                        EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does not match: %s and %s " % (self._CurrentStructurePcdName , TAB_SPLIT.join(PcdNames[:2])),
+                                File=self.MetaFile, Line=self._LineIndex + 1)
                     self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:])
                     self._ValueList[2] = PcdTockens[1]
         if not self._CurrentStructurePcdName:
             TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
             self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
-- 
2.14.3.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch] BaseTool: Enhance error handling.
  2018-01-29  3:22 BobCF
@ 2018-01-30  9:27 ` Gao, Liming
  0 siblings, 0 replies; 4+ messages in thread
From: Gao, Liming @ 2018-01-30  9:27 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

+                    error_line = FileData[int (FileLine) - 1]
Please check FileLine is digit or not. If it is not digit, you need to skip this statement. 

>-----Original Message-----
>From: Feng, Bob C
>Sent: Monday, January 29, 2018 11:22 AM
>To: edk2-devel@lists.01.org
>Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
>Subject: [Patch] BaseTool: Enhance error handling.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Bob Feng <bob.c.feng@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>---
> BaseTools/Source/Python/Workspace/DscBuildData.py  | 113
>++++++++++++---------
> .../Source/Python/Workspace/MetaFileParser.py      |   3 +
> 2 files changed, 68 insertions(+), 48 deletions(-)
>
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index bc77d1a2b4..bebd4feda0 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -856,11 +856,11 @@ class DscBuildData(PlatformBuildClassObject):
>             if not Valid:
>                 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile,
>Line=LineNo,
>                                 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
>             if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT,
>MODEL_PCD_DYNAMIC_EX_DEFAULT):
>                 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() !=
>ValueList[1].strip():
>-                    EdkLogger.error('build', FORMAT_INVALID, ErrStr ,
>File=self.MetaFile, Line=LineNo,
>+                    EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtype used
>in DSC file is not the same as its declaration in DEC file." , File=self.MetaFile,
>Line=LineNo,
>                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName,
>Setting))
>         return ValueList
>
>     def _FilterPcdBySkuUsage(self,Pcds):
>         available_sku = self.SkuIdMgr.AvailableSkuIdSet
>@@ -1009,17 +1009,20 @@ class DscBuildData(PlatformBuildClassObject):
>         StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)
>         S_pcd_set = {}
>         for str_pcd in StrPcdSet:
>             str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
>             str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
>+            if not isinstance (str_pcd_dec, StructurePcd):
>+                EdkLogger.error('build', PARSER_ERROR,
>+                            "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch:
>['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
>+                            File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
>             if str_pcd_dec:
>                 str_pcd_obj_str = StructurePcd()
>                 str_pcd_obj_str.copy(str_pcd_dec)
>                 if str_pcd_obj:
>                     str_pcd_obj_str.copy(str_pcd_obj)
>-                    if str_pcd_obj.DefaultValue:
>-                        str_pcd_obj_str.DefaultFromDSC = str_pcd_obj.DefaultValue
>+                str_pcd_obj_str.DefaultFromDSC = str_pcd_obj_str.DefaultValue
>                 for str_pcd_data in StrPcdSet[str_pcd]:
>                     if str_pcd_data[3] in SkuIds:
>                         str_pcd_obj_str.AddOverrideValue(str_pcd_data[2],
>str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else
>str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else
>str_pcd_data[4], self.MetaFile.File,LineNo=str_pcd_data[5])
>                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
>             else:
>@@ -1153,11 +1156,11 @@ class DscBuildData(PlatformBuildClassObject):
>             if SkuName not in AvailableSkuIdSet:
>                 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined
>in [SkuIds] section' % SkuName,
>                                             File=self.MetaFile, Line=Dummy5)
>             if SkuName in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):
>                 if "." not in TokenSpaceGuid:
>-                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
>+                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
>                 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting
>
>         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:
>             Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]
>             if Setting == None:
>@@ -1262,16 +1265,13 @@ class DscBuildData(PlatformBuildClassObject):
>
>     def ExecuteCommand (self, Command):
>         try:
>             Process = subprocess.Popen(Command, stdout=subprocess.PIPE,
>stderr=subprocess.PIPE, shell=True)
>         except:
>-            print 'ERROR: Can not execute command:', Command
>-            sys.exit(1)
>+            EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute
>command: %s' % Command)
>         Result = Process.communicate()
>-        if Process.returncode <> 0:
>-            print 'ERROR: Can not collect output from command:', Command
>-        return Result[0], Result[1]
>+        return Process.returncode, Result[0], Result[1]
>
>     def IntToCString(self, Value, ValueSize):
>         Result = '"'
>         if not isinstance (Value, str):
>             for Index in range(0, ValueSize):
>@@ -1383,11 +1383,11 @@ class DscBuildData(PlatformBuildClassObject):
>                 for FieldName in FieldList:
>                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
>                     try:
>                         Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
>                     except Exception:
>-                        print FieldList[FieldName][0]
>+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format
>for %s. From %s Line %d " %
>(".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldLis
>t[FieldName][1], FieldList[FieldName][2]))
>                     if isinstance(Value, str):
>                         CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' %
>(FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>                     elif IsArray:
>                         #
>                         # Use memcpy() to copy value into field
>@@ -1421,11 +1421,11 @@ class DscBuildData(PlatformBuildClassObject):
>                     for FieldName in FieldList:
>                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
>                         try:
>                             Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
>                         except Exception:
>-                            print FieldList[FieldName][0]
>+                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value
>format for %s. From %s Line %d " %
>(".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldLis
>t[FieldName][1], FieldList[FieldName][2]))
>                         if isinstance(Value, str):
>                             CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' %
>(FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>                         elif IsArray:
>                         #
>                         # Use memcpy() to copy value into field
>@@ -1597,54 +1597,71 @@ class DscBuildData(PlatformBuildClassObject):
>         File.write(InitByteValue)
>         File.close()
>
>         Messages = ''
>         if sys.platform == "win32":
>-            StdOut, StdErr = self.ExecuteCommand ('nmake clean & nmake -f %s' %
>(MakeFileName))
>+            MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
>+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
>             Messages = StdOut
>         else:
>-            StdOut, StdErr = self.ExecuteCommand ('make clean & make -f %s' %
>(MakeFileName))
>+            MakeCommand = 'make clean & make -f %s' % (MakeFileName)
>+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
>             Messages = StdErr
>         Messages = Messages.split('\n')
>-        for Message in Messages:
>-            if " error" in Message:
>-                FileInfo = Message.strip().split('(')
>-                if len (FileInfo) > 1:
>-                    FileName = FileInfo [0]
>-                    FileLine = FileInfo [1].split (')')[0]
>-                else:
>-                    FileInfo = Message.strip().split(':')
>-                    FileName = FileInfo [0]
>-                    FileLine = FileInfo [1]
>-
>-                File = open (FileName, 'r')
>-                FileData = File.readlines()
>-                File.close()
>-                error_line = FileData[int (FileLine) - 1]
>-                if r"//" in error_line:
>-                    c_line,dsc_line = error_line.split(r"//")
>-                else:
>-                    dsc_line = error_line
>-
>-                message_itmes = Message.split(":")
>-                Index = 0
>-                for item in message_itmes:
>-                    if "PcdValueInit.c" in item:
>-                        Index = message_itmes.index(item)
>-                        message_itmes[Index] = dsc_line.strip()
>-                        break
>+        MessageGroup = []
>+        if returncode <>0:
>+            CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
>+            File = open (CAppBaseFileName + '.c', 'r')
>+            FileData = File.readlines()
>+            File.close()
>+            for Message in Messages:
>+                if " error" in Message or "warning" in Message:
>+                    FileInfo = Message.strip().split('(')
>+                    if len (FileInfo) > 1:
>+                        FileName = FileInfo [0]
>+                        FileLine = FileInfo [1].split (')')[0]
>+                    else:
>+                        FileInfo = Message.strip().split(':')
>+                        FileName = FileInfo [0]
>+                        FileLine = FileInfo [1]
>
>-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR,
>":".join(message_itmes[Index:]))
>+                    error_line = FileData[int (FileLine) - 1]
>+                    if r"//" in error_line:
>+                        c_line,dsc_line = error_line.split(r"//")
>+                    else:
>+                        dsc_line = error_line
>+
>+                    message_itmes = Message.split(":")
>+                    Index = 0
>+                    if "PcdValueInit.c" not in Message:
>+                        break
>+                    else:
>+                        for item in message_itmes:
>+                            if "PcdValueInit.c" in item:
>+                                Index = message_itmes.index(item)
>+                                message_itmes[Index] = dsc_line.strip()
>+                                break
>+                        MessageGroup.append(":".join(message_itmes[Index:]).strip())
>+                        continue
>+            if MessageGroup:
>+                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR,
>"\n".join(MessageGroup) )
>+            else:
>+                EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute
>command: %s' % MakeCommand)
>
>         PcdValueInitExe = PcdValueInitName
>         if not sys.platform == "win32":
>             PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"),
>'Source', 'C', 'bin', PcdValueInitName)
>
>-        StdOut, StdErr = self.ExecuteCommand (PcdValueInitExe + ' -i %s -o %s' %
>(InputValueFile, OutputValueFile))
>-        File = open (OutputValueFile, 'r')
>-        FileBuffer = File.readlines()
>-        File.close()
>+        Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile,
>OutputValueFile)
>+        returncode, StdOut, StdErr = self.ExecuteCommand (Command)
>+        if returncode <> 0:
>+            EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output
>from command: %s' % Command)
>+            FileBuffer = []
>+        else:
>+            File = open (OutputValueFile, 'r')
>+            FileBuffer = File.readlines()
>+            File.close()
>
>         StructurePcdSet = []
>         for Pcd in FileBuffer:
>             PcdValue = Pcd.split ('|')
>             PcdInfo = PcdValue[0].split ('.')
>@@ -1677,11 +1694,11 @@ class DscBuildData(PlatformBuildClassObject):
>             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
>             if SkuName not in AvailableSkuIdSet:
>                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined
>in [SkuIds] section' % SkuName,
>                                             File=self.MetaFile, Line=Dummy5)
>             if "." not in TokenSpaceGuid:
>-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
>+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
>             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
>
>         # Remove redundant PCD candidates, per the ARCH and SKU
>         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
>
>@@ -1833,11 +1850,11 @@ class DscBuildData(PlatformBuildClassObject):
>                                             File=self.MetaFile, Line=Dummy5)
>             if DefaultStore not in DefaultStoresDefine:
>                 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is
>not defined in [DefaultStores] section' % DefaultStore,
>                                             File=self.MetaFile, Line=Dummy5)
>             if "." not in TokenSpaceGuid:
>-                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore,
>Dummy4))
>+                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore,
>Dummy5))
>             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] =
>Setting
>
>
>         # Remove redundant PCD candidates, per the ARCH and SKU
>         for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in
>PcdSet:
>@@ -1985,11 +2002,11 @@ class DscBuildData(PlatformBuildClassObject):
>             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
>             if SkuName not in AvailableSkuIdSet:
>                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined
>in [SkuIds] section' % SkuName,
>                                             File=self.MetaFile, Line=Dummy5)
>             if "." not in TokenSpaceGuid:
>-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
>+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
>             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
>
>         # Remove redundant PCD candidates, per the ARCH and SKU
>         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
>             Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
>diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>index d704809354..8f4b5e5cc1 100644
>--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>@@ -1913,10 +1913,13 @@ class DecParser(MetaFileParser):
>                 PcdTockens = self._CurrentLine.split(TAB_VALUE_SPLIT)
>                 PcdNames = PcdTockens[0].split(TAB_SPLIT)
>                 if len(PcdNames) == 2:
>                     self._CurrentStructurePcdName = ""
>                 else:
>+                    if self._CurrentStructurePcdName !=
>TAB_SPLIT.join(PcdNames[:2]):
>+                        EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does
>not match: %s and %s " % (self._CurrentStructurePcdName ,
>TAB_SPLIT.join(PcdNames[:2])),
>+                                File=self.MetaFile, Line=self._LineIndex + 1)
>                     self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:])
>                     self._ValueList[2] = PcdTockens[1]
>         if not self._CurrentStructurePcdName:
>             TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
>             self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
>--
>2.14.3.windows.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Patch] BaseTool: Enhance error handling.
@ 2018-01-31  9:32 BobCF
  2018-01-31 12:18 ` Gao, Liming
  0 siblings, 1 reply; 4+ messages in thread
From: BobCF @ 2018-01-31  9:32 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 116 ++++++++++++---------
 .../Source/Python/Workspace/MetaFileParser.py      |   3 +
 2 files changed, 70 insertions(+), 49 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index bc77d1a2b4..9d8da6ed85 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -856,11 +856,11 @@ class DscBuildData(PlatformBuildClassObject):
             if not Valid:
                 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
                                 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
             if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):
                 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():
-                    EdkLogger.error('build', FORMAT_INVALID, ErrStr , File=self.MetaFile, Line=LineNo,
+                    EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtype used in DSC file is not the same as its declaration in DEC file." , File=self.MetaFile, Line=LineNo,
                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
         return ValueList
 
     def _FilterPcdBySkuUsage(self,Pcds):
         available_sku = self.SkuIdMgr.AvailableSkuIdSet
@@ -1009,17 +1009,20 @@ class DscBuildData(PlatformBuildClassObject):
         StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)
         S_pcd_set = {}
         for str_pcd in StrPcdSet:
             str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
             str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
+            if not isinstance (str_pcd_dec, StructurePcd):
+                EdkLogger.error('build', PARSER_ERROR,
+                            "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
+                            File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
             if str_pcd_dec:
                 str_pcd_obj_str = StructurePcd()
                 str_pcd_obj_str.copy(str_pcd_dec)
                 if str_pcd_obj:
                     str_pcd_obj_str.copy(str_pcd_obj)
-                    if str_pcd_obj.DefaultValue:
-                        str_pcd_obj_str.DefaultFromDSC = str_pcd_obj.DefaultValue
+                str_pcd_obj_str.DefaultFromDSC = str_pcd_obj_str.DefaultValue
                 for str_pcd_data in StrPcdSet[str_pcd]:
                     if str_pcd_data[3] in SkuIds:
                         str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File,LineNo=str_pcd_data[5])
                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
             else:
@@ -1153,11 +1156,11 @@ class DscBuildData(PlatformBuildClassObject):
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
             if SkuName in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):
                 if "." not in TokenSpaceGuid:
-                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
+                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
                 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting
 
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:
             Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]
             if Setting == None:
@@ -1262,16 +1265,13 @@ class DscBuildData(PlatformBuildClassObject):
 
     def ExecuteCommand (self, Command):
         try:
             Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
         except:
-            print 'ERROR: Can not execute command:', Command
-            sys.exit(1)
+            EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)
         Result = Process.communicate()
-        if Process.returncode <> 0:
-            print 'ERROR: Can not collect output from command:', Command
-        return Result[0], Result[1]
+        return Process.returncode, Result[0], Result[1]
 
     def IntToCString(self, Value, ValueSize):
         Result = '"'
         if not isinstance (Value, str):
             for Index in range(0, ValueSize):
@@ -1383,11 +1383,11 @@ class DscBuildData(PlatformBuildClassObject):
                 for FieldName in FieldList:
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
                     try:
                         Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
                     except Exception:
-                        print FieldList[FieldName][0]
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
                     if isinstance(Value, str):
                         CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     elif IsArray:
                         #
                         # Use memcpy() to copy value into field
@@ -1421,11 +1421,11 @@ class DscBuildData(PlatformBuildClassObject):
                     for FieldName in FieldList:
                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
                         try:
                             Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
                         except Exception:
-                            print FieldList[FieldName][0]
+                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))
                         if isinstance(Value, str):
                             CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                         elif IsArray:
                         #
                         # Use memcpy() to copy value into field
@@ -1597,54 +1597,72 @@ class DscBuildData(PlatformBuildClassObject):
         File.write(InitByteValue)
         File.close()
 
         Messages = ''
         if sys.platform == "win32":
-            StdOut, StdErr = self.ExecuteCommand ('nmake clean & nmake -f %s' % (MakeFileName))
+            MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
             Messages = StdOut
         else:
-            StdOut, StdErr = self.ExecuteCommand ('make clean & make -f %s' % (MakeFileName))
+            MakeCommand = 'make clean & make -f %s' % (MakeFileName)
+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
             Messages = StdErr
         Messages = Messages.split('\n')
-        for Message in Messages:
-            if " error" in Message:
-                FileInfo = Message.strip().split('(')
-                if len (FileInfo) > 1:
-                    FileName = FileInfo [0]
-                    FileLine = FileInfo [1].split (')')[0]
-                else:
-                    FileInfo = Message.strip().split(':')
-                    FileName = FileInfo [0]
-                    FileLine = FileInfo [1]
-
-                File = open (FileName, 'r')
-                FileData = File.readlines()
-                File.close()
-                error_line = FileData[int (FileLine) - 1]
-                if r"//" in error_line:
-                    c_line,dsc_line = error_line.split(r"//")
-                else:
-                    dsc_line = error_line
-
-                message_itmes = Message.split(":")
-                Index = 0
-                for item in message_itmes:
-                    if "PcdValueInit.c" in item:
-                        Index = message_itmes.index(item)
-                        message_itmes[Index] = dsc_line.strip()
-                        break
-
-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, ":".join(message_itmes[Index:]))
+        MessageGroup = []
+        if returncode <>0:
+            CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
+            File = open (CAppBaseFileName + '.c', 'r')
+            FileData = File.readlines()
+            File.close()
+            for Message in Messages:
+                if " error" in Message or "warning" in Message:
+                    FileInfo = Message.strip().split('(')
+                    if len (FileInfo) > 1:
+                        FileName = FileInfo [0]
+                        FileLine = FileInfo [1].split (')')[0]
+                    else:
+                        FileInfo = Message.strip().split(':')
+                        FileName = FileInfo [0]
+                        FileLine = FileInfo [1]
+                    if FileLine.isdigit():
+                        error_line = FileData[int (FileLine) - 1]
+                        if r"//" in error_line:
+                            c_line,dsc_line = error_line.split(r"//")
+                        else:
+                            dsc_line = error_line
+                        message_itmes = Message.split(":")
+                        Index = 0
+                        if "PcdValueInit.c" not in Message:
+                            break
+                        else:
+                            for item in message_itmes:
+                                if "PcdValueInit.c" in item:
+                                    Index = message_itmes.index(item)
+                                    message_itmes[Index] = dsc_line.strip()
+                                    break
+                            MessageGroup.append(":".join(message_itmes[Index:]).strip())
+                            continue
+                    else:
+                        MessageGroup.append(Message)
+            if MessageGroup:
+                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) )
+            else:
+                EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)
 
         PcdValueInitExe = PcdValueInitName
         if not sys.platform == "win32":
             PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName)
 
-        StdOut, StdErr = self.ExecuteCommand (PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile))
-        File = open (OutputValueFile, 'r')
-        FileBuffer = File.readlines()
-        File.close()
+        Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)
+        returncode, StdOut, StdErr = self.ExecuteCommand (Command)
+        if returncode <> 0:
+            EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)
+            FileBuffer = []
+        else:
+            File = open (OutputValueFile, 'r')
+            FileBuffer = File.readlines()
+            File.close()
 
         StructurePcdSet = []
         for Pcd in FileBuffer:
             PcdValue = Pcd.split ('|')
             PcdInfo = PcdValue[0].split ('.')
@@ -1677,11 +1695,11 @@ class DscBuildData(PlatformBuildClassObject):
             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
             if "." not in TokenSpaceGuid:
-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
 
         # Remove redundant PCD candidates, per the ARCH and SKU
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
 
@@ -1833,11 +1851,11 @@ class DscBuildData(PlatformBuildClassObject):
                                             File=self.MetaFile, Line=Dummy5)
             if DefaultStore not in DefaultStoresDefine:
                 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is not defined in [DefaultStores] section' % DefaultStore,
                                             File=self.MetaFile, Line=Dummy5)
             if "." not in TokenSpaceGuid:
-                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4))
+                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy5))
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] = Setting
 
 
         # Remove redundant PCD candidates, per the ARCH and SKU
         for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in PcdSet:
@@ -1985,11 +2003,11 @@ class DscBuildData(PlatformBuildClassObject):
             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
             if "." not in TokenSpaceGuid:
-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
 
         # Remove redundant PCD candidates, per the ARCH and SKU
         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
             Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index d704809354..8f4b5e5cc1 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1913,10 +1913,13 @@ class DecParser(MetaFileParser):
                 PcdTockens = self._CurrentLine.split(TAB_VALUE_SPLIT)
                 PcdNames = PcdTockens[0].split(TAB_SPLIT)
                 if len(PcdNames) == 2:
                     self._CurrentStructurePcdName = ""
                 else:
+                    if self._CurrentStructurePcdName != TAB_SPLIT.join(PcdNames[:2]):
+                        EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does not match: %s and %s " % (self._CurrentStructurePcdName , TAB_SPLIT.join(PcdNames[:2])),
+                                File=self.MetaFile, Line=self._LineIndex + 1)
                     self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:])
                     self._ValueList[2] = PcdTockens[1]
         if not self._CurrentStructurePcdName:
             TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
             self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
-- 
2.14.3.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch] BaseTool: Enhance error handling.
  2018-01-31  9:32 [Patch] BaseTool: Enhance error handling BobCF
@ 2018-01-31 12:18 ` Gao, Liming
  0 siblings, 0 replies; 4+ messages in thread
From: Gao, Liming @ 2018-01-31 12:18 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>BobCF
>Sent: Wednesday, January 31, 2018 5:32 PM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming <liming.gao@intel.com>
>Subject: [edk2] [Patch] BaseTool: Enhance error handling.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Bob Feng <bob.c.feng@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>---
> BaseTools/Source/Python/Workspace/DscBuildData.py  | 116
>++++++++++++---------
> .../Source/Python/Workspace/MetaFileParser.py      |   3 +
> 2 files changed, 70 insertions(+), 49 deletions(-)
>
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index bc77d1a2b4..9d8da6ed85 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -856,11 +856,11 @@ class DscBuildData(PlatformBuildClassObject):
>             if not Valid:
>                 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile,
>Line=LineNo,
>                                 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
>             if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT,
>MODEL_PCD_DYNAMIC_EX_DEFAULT):
>                 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() !=
>ValueList[1].strip():
>-                    EdkLogger.error('build', FORMAT_INVALID, ErrStr ,
>File=self.MetaFile, Line=LineNo,
>+                    EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtype used
>in DSC file is not the same as its declaration in DEC file." , File=self.MetaFile,
>Line=LineNo,
>                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName,
>Setting))
>         return ValueList
>
>     def _FilterPcdBySkuUsage(self,Pcds):
>         available_sku = self.SkuIdMgr.AvailableSkuIdSet
>@@ -1009,17 +1009,20 @@ class DscBuildData(PlatformBuildClassObject):
>         StrPcdSet = self.GetStructurePcdInfo(S_PcdSet)
>         S_pcd_set = {}
>         for str_pcd in StrPcdSet:
>             str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
>             str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
>+            if not isinstance (str_pcd_dec, StructurePcd):
>+                EdkLogger.error('build', PARSER_ERROR,
>+                            "Pcd (%s.%s) is not declared as Structure PCD in DEC files. Arch:
>['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
>+                            File=self.MetaFile,Line = StrPcdSet[str_pcd][0][5])
>             if str_pcd_dec:
>                 str_pcd_obj_str = StructurePcd()
>                 str_pcd_obj_str.copy(str_pcd_dec)
>                 if str_pcd_obj:
>                     str_pcd_obj_str.copy(str_pcd_obj)
>-                    if str_pcd_obj.DefaultValue:
>-                        str_pcd_obj_str.DefaultFromDSC = str_pcd_obj.DefaultValue
>+                str_pcd_obj_str.DefaultFromDSC = str_pcd_obj_str.DefaultValue
>                 for str_pcd_data in StrPcdSet[str_pcd]:
>                     if str_pcd_data[3] in SkuIds:
>                         str_pcd_obj_str.AddOverrideValue(str_pcd_data[2],
>str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else
>str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else
>str_pcd_data[4], self.MetaFile.File,LineNo=str_pcd_data[5])
>                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
>             else:
>@@ -1153,11 +1156,11 @@ class DscBuildData(PlatformBuildClassObject):
>             if SkuName not in AvailableSkuIdSet:
>                 EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined
>in [SkuIds] section' % SkuName,
>                                             File=self.MetaFile, Line=Dummy5)
>             if SkuName in (self.SkuIdMgr.SystemSkuId, 'DEFAULT', 'COMMON'):
>                 if "." not in TokenSpaceGuid:
>-                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
>+                    PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
>                 PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting
>
>         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet:
>             Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName]
>             if Setting == None:
>@@ -1262,16 +1265,13 @@ class DscBuildData(PlatformBuildClassObject):
>
>     def ExecuteCommand (self, Command):
>         try:
>             Process = subprocess.Popen(Command, stdout=subprocess.PIPE,
>stderr=subprocess.PIPE, shell=True)
>         except:
>-            print 'ERROR: Can not execute command:', Command
>-            sys.exit(1)
>+            EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute
>command: %s' % Command)
>         Result = Process.communicate()
>-        if Process.returncode <> 0:
>-            print 'ERROR: Can not collect output from command:', Command
>-        return Result[0], Result[1]
>+        return Process.returncode, Result[0], Result[1]
>
>     def IntToCString(self, Value, ValueSize):
>         Result = '"'
>         if not isinstance (Value, str):
>             for Index in range(0, ValueSize):
>@@ -1383,11 +1383,11 @@ class DscBuildData(PlatformBuildClassObject):
>                 for FieldName in FieldList:
>                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
>                     try:
>                         Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
>                     except Exception:
>-                        print FieldList[FieldName][0]
>+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format
>for %s. From %s Line %d " %
>(".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldLis
>t[FieldName][1], FieldList[FieldName][2]))
>                     if isinstance(Value, str):
>                         CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' %
>(FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>                     elif IsArray:
>                         #
>                         # Use memcpy() to copy value into field
>@@ -1421,11 +1421,11 @@ class DscBuildData(PlatformBuildClassObject):
>                     for FieldName in FieldList:
>                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])
>                         try:
>                             Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
>                         except Exception:
>-                            print FieldList[FieldName][0]
>+                            EdkLogger.error('Build', FORMAT_INVALID, "Invalid value
>format for %s. From %s Line %d " %
>(".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldLis
>t[FieldName][1], FieldList[FieldName][2]))
>                         if isinstance(Value, str):
>                             CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' %
>(FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2],
>FieldList[FieldName][0])
>                         elif IsArray:
>                         #
>                         # Use memcpy() to copy value into field
>@@ -1597,54 +1597,72 @@ class DscBuildData(PlatformBuildClassObject):
>         File.write(InitByteValue)
>         File.close()
>
>         Messages = ''
>         if sys.platform == "win32":
>-            StdOut, StdErr = self.ExecuteCommand ('nmake clean & nmake -f %s' %
>(MakeFileName))
>+            MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName)
>+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
>             Messages = StdOut
>         else:
>-            StdOut, StdErr = self.ExecuteCommand ('make clean & make -f %s' %
>(MakeFileName))
>+            MakeCommand = 'make clean & make -f %s' % (MakeFileName)
>+            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
>             Messages = StdErr
>         Messages = Messages.split('\n')
>-        for Message in Messages:
>-            if " error" in Message:
>-                FileInfo = Message.strip().split('(')
>-                if len (FileInfo) > 1:
>-                    FileName = FileInfo [0]
>-                    FileLine = FileInfo [1].split (')')[0]
>-                else:
>-                    FileInfo = Message.strip().split(':')
>-                    FileName = FileInfo [0]
>-                    FileLine = FileInfo [1]
>-
>-                File = open (FileName, 'r')
>-                FileData = File.readlines()
>-                File.close()
>-                error_line = FileData[int (FileLine) - 1]
>-                if r"//" in error_line:
>-                    c_line,dsc_line = error_line.split(r"//")
>-                else:
>-                    dsc_line = error_line
>-
>-                message_itmes = Message.split(":")
>-                Index = 0
>-                for item in message_itmes:
>-                    if "PcdValueInit.c" in item:
>-                        Index = message_itmes.index(item)
>-                        message_itmes[Index] = dsc_line.strip()
>-                        break
>-
>-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR,
>":".join(message_itmes[Index:]))
>+        MessageGroup = []
>+        if returncode <>0:
>+            CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
>+            File = open (CAppBaseFileName + '.c', 'r')
>+            FileData = File.readlines()
>+            File.close()
>+            for Message in Messages:
>+                if " error" in Message or "warning" in Message:
>+                    FileInfo = Message.strip().split('(')
>+                    if len (FileInfo) > 1:
>+                        FileName = FileInfo [0]
>+                        FileLine = FileInfo [1].split (')')[0]
>+                    else:
>+                        FileInfo = Message.strip().split(':')
>+                        FileName = FileInfo [0]
>+                        FileLine = FileInfo [1]
>+                    if FileLine.isdigit():
>+                        error_line = FileData[int (FileLine) - 1]
>+                        if r"//" in error_line:
>+                            c_line,dsc_line = error_line.split(r"//")
>+                        else:
>+                            dsc_line = error_line
>+                        message_itmes = Message.split(":")
>+                        Index = 0
>+                        if "PcdValueInit.c" not in Message:
>+                            break
>+                        else:
>+                            for item in message_itmes:
>+                                if "PcdValueInit.c" in item:
>+                                    Index = message_itmes.index(item)
>+                                    message_itmes[Index] = dsc_line.strip()
>+                                    break
>+
>MessageGroup.append(":".join(message_itmes[Index:]).strip())
>+                            continue
>+                    else:
>+                        MessageGroup.append(Message)
>+            if MessageGroup:
>+                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR,
>"\n".join(MessageGroup) )
>+            else:
>+                EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute
>command: %s' % MakeCommand)
>
>         PcdValueInitExe = PcdValueInitName
>         if not sys.platform == "win32":
>             PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"),
>'Source', 'C', 'bin', PcdValueInitName)
>
>-        StdOut, StdErr = self.ExecuteCommand (PcdValueInitExe + ' -i %s -o %s' %
>(InputValueFile, OutputValueFile))
>-        File = open (OutputValueFile, 'r')
>-        FileBuffer = File.readlines()
>-        File.close()
>+        Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile,
>OutputValueFile)
>+        returncode, StdOut, StdErr = self.ExecuteCommand (Command)
>+        if returncode <> 0:
>+            EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output
>from command: %s' % Command)
>+            FileBuffer = []
>+        else:
>+            File = open (OutputValueFile, 'r')
>+            FileBuffer = File.readlines()
>+            File.close()
>
>         StructurePcdSet = []
>         for Pcd in FileBuffer:
>             PcdValue = Pcd.split ('|')
>             PcdInfo = PcdValue[0].split ('.')
>@@ -1677,11 +1695,11 @@ class DscBuildData(PlatformBuildClassObject):
>             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
>             if SkuName not in AvailableSkuIdSet:
>                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined
>in [SkuIds] section' % SkuName,
>                                             File=self.MetaFile, Line=Dummy5)
>             if "." not in TokenSpaceGuid:
>-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
>+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
>             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
>
>         # Remove redundant PCD candidates, per the ARCH and SKU
>         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
>
>@@ -1833,11 +1851,11 @@ class DscBuildData(PlatformBuildClassObject):
>                                             File=self.MetaFile, Line=Dummy5)
>             if DefaultStore not in DefaultStoresDefine:
>                 EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores %s is
>not defined in [DefaultStores] section' % DefaultStore,
>                                             File=self.MetaFile, Line=Dummy5)
>             if "." not in TokenSpaceGuid:
>-                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore,
>Dummy4))
>+                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore,
>Dummy5))
>             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] =
>Setting
>
>
>         # Remove redundant PCD candidates, per the ARCH and SKU
>         for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in
>PcdSet:
>@@ -1985,11 +2003,11 @@ class DscBuildData(PlatformBuildClassObject):
>             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
>             if SkuName not in AvailableSkuIdSet:
>                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined
>in [SkuIds] section' % SkuName,
>                                             File=self.MetaFile, Line=Dummy5)
>             if "." not in TokenSpaceGuid:
>-                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4))
>+                PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5))
>             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
>
>         # Remove redundant PCD candidates, per the ARCH and SKU
>         for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
>             Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
>diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>index d704809354..8f4b5e5cc1 100644
>--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>@@ -1913,10 +1913,13 @@ class DecParser(MetaFileParser):
>                 PcdTockens = self._CurrentLine.split(TAB_VALUE_SPLIT)
>                 PcdNames = PcdTockens[0].split(TAB_SPLIT)
>                 if len(PcdNames) == 2:
>                     self._CurrentStructurePcdName = ""
>                 else:
>+                    if self._CurrentStructurePcdName !=
>TAB_SPLIT.join(PcdNames[:2]):
>+                        EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does
>not match: %s and %s " % (self._CurrentStructurePcdName ,
>TAB_SPLIT.join(PcdNames[:2])),
>+                                File=self.MetaFile, Line=self._LineIndex + 1)
>                     self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:])
>                     self._ValueList[2] = PcdTockens[1]
>         if not self._CurrentStructurePcdName:
>             TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
>             self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
>--
>2.14.3.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-31 12:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-31  9:32 [Patch] BaseTool: Enhance error handling BobCF
2018-01-31 12:18 ` Gao, Liming
  -- strict thread matches above, loose matches on Subject: below --
2018-01-29  3:22 BobCF
2018-01-30  9:27 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox