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.115; helo=mga14.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org 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 8A30522364884 for ; Wed, 31 Jan 2018 01:26:31 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 01:32:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,439,1511856000"; d="scan'208";a="200192830" Received: from shwdeopenpsi105.ccr.corp.intel.com ([10.239.9.129]) by fmsmga006.fm.intel.com with ESMTP; 31 Jan 2018 01:32:03 -0800 From: BobCF To: edk2-devel@lists.01.org Cc: Bob Feng , Liming Gao Date: Wed, 31 Jan 2018 17:32:01 +0800 Message-Id: <20180131093201.7384-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.14.3.windows.1 Subject: [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: Wed, 31 Jan 2018 09:26:33 -0000 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- 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