public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gao, Liming" <liming.gao@intel.com>
To: "Feng, Bob C" <bob.c.feng@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [Patch] BaseTool: Enhance error handling.
Date: Tue, 30 Jan 2018 09:27:21 +0000	[thread overview]
Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E1B9777@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <20180129032205.20132-1-bob.c.feng@intel.com>

+                    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



  reply	other threads:[~2018-01-30  9:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29  3:22 [Patch] BaseTool: Enhance error handling BobCF
2018-01-30  9:27 ` Gao, Liming [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-01-31  9:32 BobCF
2018-01-31 12:18 ` Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A89E2EF3DFEDB4C8BFDE51014F606A14E1B9777@SHSMSX104.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox