From nobody Thu May 2 01:09:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+41471+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41471+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1559035960; cv=none; d=zoho.com; s=zohoarc; b=RzsMQr5uAOvA50bGXvGBQCFP6aJ9ertSpaQuBiMp5tGMcyPJ/iLCcmz7mY9QWrfy1CYMKE4Zjg0d3ZotRuzntbnGTmKaCf/Q87BY0xz2ad6gqBTqmBG4/G/Ws9iLvbMWEQXRjpDkegHkOg1tO0ypF2PNBHB6Z1v+KnQdoKpNgsw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559035960; h=Content-Type:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=+3Kd0Rlxri9dAihGi1mRB6wIPTOWA5wuuwU71R9pCaY=; b=Hlj5gL5avstjhLFd9GvnQhaeyd0nwAE0fSjr8eo65FR9WErFoYsl31Synskyvl3FtY6BT5jSS3Gu3W6XA92VPd7w7U2daGrulNAyi9qE0taGx/T/BAx0loOOYFPLXsaczgB16BsM9ESnBEP+pAfWzn2r3AnMFLdpk/GIHnfniDM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41471+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 155903595993774.81624966762888; Tue, 28 May 2019 02:32:39 -0700 (PDT) Return-Path: X-Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by groups.io with SMTP; Tue, 28 May 2019 02:32:38 -0700 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 May 2019 02:32:38 -0700 X-ExtLoop1: 1 X-Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga004.jf.intel.com with ESMTP; 28 May 2019 02:32:37 -0700 X-Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 28 May 2019 02:32:37 -0700 X-Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 28 May 2019 02:32:36 -0700 X-Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.129]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.33]) with mapi id 14.03.0415.000; Tue, 28 May 2019 17:32:35 +0800 From: "Fan, ZhijuX" To: "devel@edk2.groups.io" CC: "Gao, Liming" , "Feng, Bob C" Subject: [edk2-devel] [PATCH] BaseTools:Add DetectNotUsedItem.py to Edk2\BaseTools\Scripts Thread-Topic: [PATCH] BaseTools:Add DetectNotUsedItem.py to Edk2\BaseTools\Scripts Thread-Index: AdUVODvoQioEnMiHSEKe1Y9pnbE06Q== Date: Tue, 28 May 2019 09:32:35 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhijux.fan@intel.com Content-Type: multipart/mixed; boundary="_000_FAD0D7E0AE0FA54D987F6E72435CAFD50AF62DAASHSMSX101ccrcor_" Content-Language: en-US DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1559035959; bh=g/1BhLS70JtMLoQ8UobluA6iMwdMi527nW4Hc0TzciY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MdHYUnxnC4iDvBgRLcSRKe9ze0ni/6jG8Dhf8ZkyeXOH1+Nk3CzmAwdjkiRHjw2RE0e jxB/5jlNG66b1gtdxSQ/f5fav57eZn3ydi/Si3TwiCTEEnK0yWBZc3nH6SS4wjWMOCQMK CPBUcLsW4Q7Fzt4KScz/vPp51KUEMJfsLAs= X-Zoho-Virus-Status: 1 X-ZohoMail-DKIM: pass (identity @groups.io) --_000_FAD0D7E0AE0FA54D987F6E72435CAFD50AF62DAASHSMSX101ccrcor_ Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1850 This script is used to Detect unreferenced PCD and GUID/Protocols/PPIs. The input parameters are Dec file and package directory. This script can be run in both Py2 and Py3. Cc: Bob Feng Cc: Liming Gao Signed-off-by: Zhiju.Fan --- BaseTools/Scripts/DetectNotUsedItem.py | 185 +++++++++++++++++++++++++++++= ++++ 1 file changed, 185 insertions(+) create mode 100644 BaseTools/Scripts/DetectNotUsedItem.py diff --git a/BaseTools/Scripts/DetectNotUsedItem.py b/BaseTools/Scripts/Det= ectNotUsedItem.py new file mode 100644 index 0000000000..655fb65a96 --- /dev/null +++ b/BaseTools/Scripts/DetectNotUsedItem.py @@ -0,0 +1,185 @@ +## @file +# Detect unreferenced PCD and GUID/Protocols/PPIs. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' +DetectNotUsedItem +''' +import re +import os +import sys +import argparse + +# +# Globals for help information +# +__prog__ =3D 'DetectNotUsedItem' +__version__ =3D '%s Version %s' % (__prog__, '0.1') +__copyright__ =3D 'Copyright (c) 2019, Intel Corporation. All rights res= erved.' +__description__ =3D "Detect unreferenced PCD and GUID/Protocols/PPIs.\n" + +SectionList =3D ["LibraryClasses", "Guids", "Ppis", "Protocols", "Pcd"] + +class PROCESS(object): + + def __init__(self, DecPath, InfDirs): + self.Dec =3D DecPath + self.InfPath =3D InfDirs + self.Log =3D [] + + def ParserDscFdfInfFile(self): + AllContentList =3D [] + for File in (self.SearchbyExt(".dsc") + self.SearchbyExt(".fdf") + sel= f.SearchbyExt(".inf")): + AllContentList +=3D self.ParseDscFdfInfContent(File) + return AllContentList + + #Search File by extension name + def SearchbyExt(self, Ext): + FileList =3D [] + for path in self.InfPath: + for root, _, files in os.walk(path, topdown=3DTrue, followlinks=3DFa= lse): + for filename in files: + if filename.endswith(Ext): + FileList.append(os.path.join(root, filename)) + return FileList + + # Parse DEC file to get Line number and Name + # return section name, the Item Name and comments line number + def ParseDecContent(self): + SectionRE =3D re.compile(r'\[(.*)\]') + Flag =3D False + Comments =3D{} + Comment_Line =3D [] + ItemName =3D {} + with open(self.Dec, 'r') as F: + for Index, content in enumerate(F): + NotComment =3D not content.strip().startswith("#") + Section =3D SectionRE.findall(content) + if Section and NotComment: + Flag =3D self.IsNeedParseSection(Section[0]) + if Flag: + Comment_Line.append(Index) + if NotComment: + if content !=3D "\n" and content !=3D "\r\n": + ItemName[Index] =3D content.split('=3D')[0].split('|')[0].sp= lit('#')[0].strip() + Comments[Index] =3D Comment_Line + Comment_Line =3D [] + return ItemName, Comments + + def IsNeedParseSection(self, SectionName): + for item in SectionList: + if item in SectionName: + return True + return False + + #Parse DSC, FDF, INF File, remove comments, return Lines list + def ParseDscFdfInfContent(self, File): + with open(File,'r') as F: + lines =3D F.readlines() + for Index in range(len(lines)-1, -1, -1): + if lines[Index].strip().startswith("#") or lines[Index] =3D=3D "\n" = or lines[Index] =3D=3D "\r\n": + lines.remove(lines[Index]) + elif "#" in lines[Index]: + lines[Index] =3D lines[Index].split("#")[0].strip() + else: + lines[Index] =3D lines[Index].strip() + return lines + + def DetectNotUsedItem(self): + NotUsedItem =3D {} + DecItem, DecComments =3D self.ParseDecContent() + InfDscFdfContent =3D self.ParserDscFdfInfFile() + for LineNum in list(DecItem.keys()): + DecItemName =3D DecItem[LineNum] + Match_reg =3D re.compile("(?