From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D7A632215BDAD for ; Tue, 30 Jan 2018 01:21:50 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2018 01:27:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,434,1511856000"; d="scan'208";a="13647089" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga007.jf.intel.com with ESMTP; 30 Jan 2018 01:27:24 -0800 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 30 Jan 2018 01:27:24 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 30 Jan 2018 01:27:23 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.127]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.145]) with mapi id 14.03.0319.002; Tue, 30 Jan 2018 17:27:22 +0800 From: "Gao, Liming" To: "Feng, Bob C" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] BaseTool: Enhance error handling. Thread-Index: AQHTmLBfVSDOqpC6OkSX1Fnao4/tgqOMJ2xQ Date: Tue, 30 Jan 2018 09:27:21 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E1B9777@SHSMSX104.ccr.corp.intel.com> References: <20180129032205.20132-1-bob.c.feng@intel.com> In-Reply-To: <20180129032205.20132-1-bob.c.feng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] BaseTool: Enhance error handling. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jan 2018 09:21:51 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable + error_line =3D FileData[int (FileLine) - 1] Please check FileLine is digit or not. If it is not digit, you need to skip= this statement.=20 >-----Original Message----- >From: Feng, Bob C >Sent: Monday, January 29, 2018 11:22 AM >To: edk2-devel@lists.01.org >Cc: Feng, Bob C ; Gao, Liming >Subject: [Patch] BaseTool: Enhance error handling. > >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Bob Feng >Cc: Liming Gao >--- > 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=3Ds= elf.MetaFile, >Line=3DLineNo, > ExtraData=3D"%s.%s" % (TokenSpaceGuid, Pc= dCName)) > if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, >MODEL_PCD_DYNAMIC_EX_DEFAULT): > if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.stri= p() !=3D >ValueList[1].strip(): >- EdkLogger.error('build', FORMAT_INVALID, ErrStr , >File=3Dself.MetaFile, Line=3DLineNo, >+ EdkLogger.error('build', FORMAT_INVALID, "Pcd datumty= pe used >in DSC file is not the same as its declaration in DEC file." , File=3Dself= .MetaFile, >Line=3DLineNo, > ExtraData=3D"%s.%s|%s" % (TokenSpaceGuid,= PcdCName, >Setting)) > return ValueList > > def _FilterPcdBySkuUsage(self,Pcds): > available_sku =3D self.SkuIdMgr.AvailableSkuIdSet >@@ -1009,17 +1009,20 @@ class DscBuildData(PlatformBuildClassObject): > StrPcdSet =3D self.GetStructurePcdInfo(S_PcdSet) > S_pcd_set =3D {} > for str_pcd in StrPcdSet: > str_pcd_obj =3D Pcds.get((str_pcd[1], str_pcd[0]), None) > str_pcd_dec =3D self._DecPcds.get((str_pcd[1], str_pcd[0]), N= one) >+ 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=3Dself.MetaFile,Line =3D StrPcdSet[str_p= cd][0][5]) > if str_pcd_dec: > str_pcd_obj_str =3D 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 =3D str_pcd_obj.De= faultValue >+ str_pcd_obj_str.DefaultFromDSC =3D str_pcd_obj_str.Defaul= tValue > 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] =3D=3D 'COMMON' else >str_pcd_data[3],'STANDARD' if str_pcd_data[4] =3D=3D 'COMMON' else >str_pcd_data[4], self.MetaFile.File,LineNo=3Dstr_pcd_data[5]) > S_pcd_set[str_pcd[1], str_pcd[0]] =3D 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 n= ot defined >in [SkuIds] section' % SkuName, > File=3Dself.MetaFile, Line=3D= 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] =3D Sett= ing > > for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet: > Setting =3D PcdDict[self._Arch, PcdCName, TokenSpaceGuid, Sku= Name] > if Setting =3D=3D None: >@@ -1262,16 +1265,13 @@ class DscBuildData(PlatformBuildClassObject): > > def ExecuteCommand (self, Command): > try: > Process =3D subprocess.Popen(Command, stdout=3Dsubprocess.PIP= E, >stderr=3Dsubprocess.PIPE, shell=3DTrue) > except: >- print 'ERROR: Can not execute command:', Command >- sys.exit(1) >+ EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute >command: %s' % Command) > Result =3D 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 =3D '"' > if not isinstance (Value, str): > for Index in range(0, ValueSize): >@@ -1383,11 +1383,11 @@ class DscBuildData(PlatformBuildClassObject): > for FieldName in FieldList: > IsArray =3D self.IsFieldValueAnArray(FieldList[FieldN= ame][0]) > try: > Value, ValueSize =3D ParseFieldValue (FieldList[F= ieldName][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 =3D CApp + ' Pcd->%s =3D %s; // From %s Lin= e %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 =3D self.IsFieldValueAnArray(FieldList[Fi= eldName][0]) > try: > Value, ValueSize =3D ParseFieldValue (FieldLi= st[FieldName][0]) > except Exception: >- print FieldList[FieldName][0] >+ EdkLogger.error('Build', FORMAT_INVALID, "Inv= alid 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 =3D CApp + ' Pcd->%s =3D %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 =3D '' > if sys.platform =3D=3D "win32": >- StdOut, StdErr =3D self.ExecuteCommand ('nmake clean & nmake = -f %s' % >(MakeFileName)) >+ MakeCommand =3D 'nmake clean & nmake -f %s' % (MakeFileName) >+ returncode, StdOut, StdErr =3D self.ExecuteCommand (MakeComma= nd) > Messages =3D StdOut > else: >- StdOut, StdErr =3D self.ExecuteCommand ('make clean & make -f= %s' % >(MakeFileName)) >+ MakeCommand =3D 'make clean & make -f %s' % (MakeFileName) >+ returncode, StdOut, StdErr =3D self.ExecuteCommand (MakeComma= nd) > Messages =3D StdErr > Messages =3D Messages.split('\n') >- for Message in Messages: >- if " error" in Message: >- FileInfo =3D Message.strip().split('(') >- if len (FileInfo) > 1: >- FileName =3D FileInfo [0] >- FileLine =3D FileInfo [1].split (')')[0] >- else: >- FileInfo =3D Message.strip().split(':') >- FileName =3D FileInfo [0] >- FileLine =3D FileInfo [1] >- >- File =3D open (FileName, 'r') >- FileData =3D File.readlines() >- File.close() >- error_line =3D FileData[int (FileLine) - 1] >- if r"//" in error_line: >- c_line,dsc_line =3D error_line.split(r"//") >- else: >- dsc_line =3D error_line >- >- message_itmes =3D Message.split(":") >- Index =3D 0 >- for item in message_itmes: >- if "PcdValueInit.c" in item: >- Index =3D message_itmes.index(item) >- message_itmes[Index] =3D dsc_line.strip() >- break >+ MessageGroup =3D [] >+ if returncode <>0: >+ CAppBaseFileName =3D os.path.join(self.OutputPath, PcdValueIn= itName) >+ File =3D open (CAppBaseFileName + '.c', 'r') >+ FileData =3D File.readlines() >+ File.close() >+ for Message in Messages: >+ if " error" in Message or "warning" in Message: >+ FileInfo =3D Message.strip().split('(') >+ if len (FileInfo) > 1: >+ FileName =3D FileInfo [0] >+ FileLine =3D FileInfo [1].split (')')[0] >+ else: >+ FileInfo =3D Message.strip().split(':') >+ FileName =3D FileInfo [0] >+ FileLine =3D FileInfo [1] > >- EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, >":".join(message_itmes[Index:])) >+ error_line =3D FileData[int (FileLine) - 1] >+ if r"//" in error_line: >+ c_line,dsc_line =3D error_line.split(r"//") >+ else: >+ dsc_line =3D error_line >+ >+ message_itmes =3D Message.split(":") >+ Index =3D 0 >+ if "PcdValueInit.c" not in Message: >+ break >+ else: >+ for item in message_itmes: >+ if "PcdValueInit.c" in item: >+ Index =3D message_itmes.index(item) >+ message_itmes[Index] =3D 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 execut= e >command: %s' % MakeCommand) > > PcdValueInitExe =3D PcdValueInitName > if not sys.platform =3D=3D "win32": > PcdValueInitExe =3D os.path.join(os.getenv("EDK_TOOLS_PATH"), >'Source', 'C', 'bin', PcdValueInitName) > >- StdOut, StdErr =3D self.ExecuteCommand (PcdValueInitExe + ' -i %s= -o %s' % >(InputValueFile, OutputValueFile)) >- File =3D open (OutputValueFile, 'r') >- FileBuffer =3D File.readlines() >- File.close() >+ Command =3D PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, >OutputValueFile) >+ returncode, StdOut, StdErr =3D self.ExecuteCommand (Command) >+ if returncode <> 0: >+ EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect out= put >from command: %s' % Command) >+ FileBuffer =3D [] >+ else: >+ File =3D open (OutputValueFile, 'r') >+ FileBuffer =3D File.readlines() >+ File.close() > > StructurePcdSet =3D [] > for Pcd in FileBuffer: > PcdValue =3D Pcd.split ('|') > PcdInfo =3D PcdValue[0].split ('.') >@@ -1677,11 +1694,11 @@ class DscBuildData(PlatformBuildClassObject): > SkuName =3D 'DEFAULT' if SkuName =3D=3D 'COMMON' else SkuName > if SkuName not in AvailableSkuIdSet: > EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is no= t defined >in [SkuIds] section' % SkuName, > File=3Dself.MetaFile, Line=3D= Dummy5) > if "." not in TokenSpaceGuid: >- PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4= )) >+ PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5= )) > PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] =3D 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=3Dself.MetaFile, Line=3D= Dummy5) > if DefaultStore not in DefaultStoresDefine: > EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStore= s %s is >not defined in [DefaultStores] section' % DefaultStore, > File=3Dself.MetaFile, Line=3D= Dummy5) > if "." not in TokenSpaceGuid: >- PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStor= e, >Dummy4)) >+ PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStor= e, >Dummy5)) > PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore]= =3D >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 =3D 'DEFAULT' if SkuName =3D=3D 'COMMON' else SkuName > if SkuName not in AvailableSkuIdSet: > EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is no= t defined >in [SkuIds] section' % SkuName, > File=3Dself.MetaFile, Line=3D= Dummy5) > if "." not in TokenSpaceGuid: >- PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4= )) >+ PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5= )) > PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] =3D Setting > > # Remove redundant PCD candidates, per the ARCH and SKU > for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList: > Setting =3D PcdDict[self._Arch, SkuName, PcdCName, TokenSpace= Guid] >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 =3D self._CurrentLine.split(TAB_VALUE_SPLIT) > PcdNames =3D PcdTockens[0].split(TAB_SPLIT) > if len(PcdNames) =3D=3D 2: > self._CurrentStructurePcdName =3D "" > else: >+ if self._CurrentStructurePcdName !=3D >TAB_SPLIT.join(PcdNames[:2]): >+ EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Na= me does >not match: %s and %s " % (self._CurrentStructurePcdName , >TAB_SPLIT.join(PcdNames[:2])), >+ File=3Dself.MetaFile, Line=3Dself._LineIn= dex + 1) > self._ValueList[1] =3D TAB_SPLIT.join(PcdNames[2:]) > self._ValueList[2] =3D PcdTockens[1] > if not self._CurrentStructurePcdName: > TokenList =3D GetSplitValueList(self._CurrentLine, TAB_VALUE_= SPLIT, 1) > self._ValueList[0:1] =3D GetSplitValueList(TokenList[0], TAB_= SPLIT) >-- >2.14.3.windows.1