From nobody Fri Nov 1 10:40:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1517196133138873.8183308871487; Sun, 28 Jan 2018 19:22:13 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E31932232BE04; Sun, 28 Jan 2018 19:16:37 -0800 (PST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 B5ACC2222C223 for ; Sun, 28 Jan 2018 19:16:36 -0800 (PST) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2018 19:22:09 -0800 Received: from shwdeopenpsi105.ccr.corp.intel.com ([10.239.9.129]) by orsmga007.jf.intel.com with ESMTP; 28 Jan 2018 19:22:07 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,429,1511856000"; d="scan'208";a="13307631" From: BobCF To: edk2-devel@lists.01.org Date: Mon, 29 Jan 2018 11:22:05 +0800 Message-Id: <20180129032205.20132-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.14.3.windows.1 Subject: [edk2] [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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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=3Dse= lf.MetaFile, Line=3DLineNo, ExtraData=3D"%s.%s" % (TokenSpaceGuid, Pcd= CName)) if PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX= _DEFAULT): if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip= () !=3D ValueList[1].strip(): - EdkLogger.error('build', FORMAT_INVALID, ErrStr , File= =3Dself.MetaFile, Line=3DLineNo, + EdkLogger.error('build', FORMAT_INVALID, "Pcd datumtyp= e 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 =20 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]), No= ne) + 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_pc= d][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.Def= aultValue + str_pcd_obj_str.DefaultFromDSC =3D str_pcd_obj_str.Default= Value 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_dat= a[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 no= t defined in [SkuIds] section' % SkuName, File=3Dself.MetaFile, Line=3DD= ummy5) 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 Setti= ng =20 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet: Setting =3D PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuN= ame] if Setting =3D=3D None: @@ -1262,16 +1265,13 @@ class DscBuildData(PlatformBuildClassObject): =20 def ExecuteCommand (self, Command): try: Process =3D subprocess.Popen(Command, stdout=3Dsubprocess.PIPE= , stderr=3Dsubprocess.PIPE, shell=3DTrue) except: - print 'ERROR: Can not execute command:', Command - sys.exit(1) + EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute com= mand: %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] =20 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[FieldNa= me][0]) try: Value, ValueSize =3D ParseFieldValue (FieldList[Fi= eldName][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 =3D CApp + ' Pcd->%s =3D %s; // From %s Line= %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[Fie= ldName][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[Fie= ldName][0]) try: Value, ValueSize =3D ParseFieldValue (FieldLis= t[FieldName][0]) except Exception: - print FieldList[FieldName][0] + EdkLogger.error('Build', FORMAT_INVALID, "Inva= lid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidC= Name,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldNam= e][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() =20 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 (MakeComman= d) 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 (MakeComman= d) 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, PcdValueIni= tName) + 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] =20 - 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".joi= n(MessageGroup) ) + else: + EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute= command: %s' % MakeCommand) =20 PcdValueInitExe =3D PcdValueInitName if not sys.platform =3D=3D "win32": PcdValueInitExe =3D os.path.join(os.getenv("EDK_TOOLS_PATH"), = 'Source', 'C', 'bin', PcdValueInitName) =20 - 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, Ou= tputValueFile) + returncode, StdOut, StdErr =3D self.ExecuteCommand (Command) + if returncode <> 0: + EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect outp= ut from command: %s' % Command) + FileBuffer =3D [] + else: + File =3D open (OutputValueFile, 'r') + FileBuffer =3D File.readlines() + File.close() =20 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 not= defined in [SkuIds] section' % SkuName, File=3Dself.MetaFile, Line=3DD= ummy5) if "." not in TokenSpaceGuid: - PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4)) + PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5)) PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] =3D Setting =20 # Remove redundant PCD candidates, per the ARCH and SKU for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList: =20 @@ -1833,11 +1850,11 @@ class DscBuildData(PlatformBuildClassObject): File=3Dself.MetaFile, Line=3DD= ummy5) if DefaultStore not in DefaultStoresDefine: EdkLogger.error('build', PARAMETER_INVALID, 'DefaultStores= %s is not defined in [DefaultStores] section' % DefaultStore, File=3Dself.MetaFile, Line=3DD= ummy5) if "." not in TokenSpaceGuid: - PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore= , Dummy4)) + PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,DefaultStore= , Dummy5)) PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] = =3D Setting =20 =20 # Remove redundant PCD candidates, per the ARCH and SKU for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in PcdS= et: @@ -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 not= defined in [SkuIds] section' % SkuName, File=3Dself.MetaFile, Line=3DD= ummy5) if "." not in TokenSpaceGuid: - PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy4)) + PcdList.append((PcdCName, TokenSpaceGuid, SkuName, Dummy5)) PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] =3D Setting =20 # Remove redundant PCD candidates, per the ARCH and SKU for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList: Setting =3D PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceG= uid] diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/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(P= cdNames[:2]): + EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Nam= e does not match: %s and %s " % (self._CurrentStructurePcdName , TAB_SPLIT.= join(PcdNames[:2])), + File=3Dself.MetaFile, Line=3Dself._LineInd= ex + 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_S= PLIT, 1) self._ValueList[0:1] =3D GetSplitValueList(TokenList[0], TAB_S= PLIT) --=20 2.14.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel