From nobody Sat Apr 20 07:14:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+83953+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83953+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1637685076; cv=none; d=zohomail.com; s=zohoarc; b=blz4xAEJElQM7URIoqjC/FtPPD77oWuolQITmaeowKzirnefPZnXbRy2FI912x5CIiYnVXfYn8Wyteo1JFqhyZ4r8fnhdKhE+6ZDHthktp5OqMcb4qX5ckGf9LwG23/wbhpcRtIrP0c6n9jgxyg87eXgTvP5jlDPgcYtTtwiSh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637685076; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=rZa19UUlKp5oiceVv9wo/OnoX68hdanR4QKk2663U+I=; b=P1d3M7711yJqZupEhWbY1wcgrbc1b/3BUjv1kuN8lMD9N4v7EDq0yknOxpfl0h4xmmLBui3vW+i5mAsA8Wnw31XeBPUJygpbpDlJr0cM0dHZdRmrtydwU60u98dwtykEhF1dwdnjB2cpNMjE4tuda+JIZWjQYGwH9/a1jMCsWqo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83953+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1637685076355824.1949432344621; Tue, 23 Nov 2021 08:31:16 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id VokLYY1788612xqpkRjxCNaX; Tue, 23 Nov 2021 08:31:16 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.13776.1637685074761235619 for ; Tue, 23 Nov 2021 08:31:15 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="298466165" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="298466165" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="571112437" X-Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.59.198]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:13 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Liming Gao , Michael Kubacki Subject: [edk2-devel] [Patch V2 1/3] .pytool/Plugin/EccCheck: Remove RevertCode() Date: Tue, 23 Nov 2021 08:30:59 -0800 Message-Id: <20211123163101.786-2-michael.d.kinney@intel.com> In-Reply-To: <20211123163101.786-1-michael.d.kinney@intel.com> References: <20211123163101.786-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,michael.d.kinney@intel.com X-Gm-Message-State: NFp5fWKHWMYZ8YPzq1mBLFVIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637685076; bh=TCSLtk7WPJFTDvvL+JpbuK9NFtU8kN6EfJCHjSwlVbA=; h=Cc:Date:From:Reply-To:Subject:To; b=KDO83TysaJhKQLnNKu6T1yqFo7DXHn4eJoa4yEYZuwGN9vN/nP52MpadjsN86ohpNyh nqHF/OONqnMx7QouJsaVySSvKSDwNP2PCA7S4vqifrRI3tKdB+lni9TuzyxdTvITdlxF4 +wCmfRwY0tM37sizUGPvbM4ipRRKcbIHj2c= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637685077166100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2986 The RevertCode() method uses git reset which can remove local changes. Instead of modifying the local files, a copy of the package passed into the EccCheck tool is copied to a temp directory in Build/ecctemp. This same temp directory is also used for exception.xml. The working directory used by ECC is also set to this same temp directory. The combination of these changes eliminates operations that that modified the git state. Cc: Sean Brogan Cc: Bret Barkelew Cc: Liming Gao Cc: Michael Kubacki Signed-off-by: Michael D Kinney Acked-by: Sean Brogan Reviewed-by: Liming Gao --- .pytool/Plugin/EccCheck/EccCheck.py | 93 ++++++++++++++++------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/= EccCheck.py index 2d0612269b2e..c4c2af1bf6e4 100644 --- a/.pytool/Plugin/EccCheck/EccCheck.py +++ b/.pytool/Plugin/EccCheck/EccCheck.py @@ -69,32 +69,50 @@ class EccCheck(ICiBuildPlugin): env.set_shell_var('WORKSPACE', workspace_path) env.set_shell_var('PACKAGES_PATH', os.pathsep.join(Edk2pathObj.Pac= kagePathList)) self.ECC_PASS =3D True - self.ApplyConfig(pkgconfig, workspace_path, basetools_path, packag= ename) + + # Create temp directory + temp_path =3D os.path.join(workspace_path, 'Build', '.pytool', 'Pl= ugin', 'EccCheck') + # Delete temp directory + if os.path.exists(temp_path): + shutil.rmtree(temp_path) + # Copy package being scanned to temp_path + shutil.copytree ( + os.path.join(workspace_path, packagename), + os.path.join(temp_path, packagename), + symlinks=3DTrue + ) + # Copy exception.xml to temp_path + shutil.copyfile ( + os.path.join(basetools_path, "Source", "Python", "Ecc", "excepti= on.xml"), + os.path.join(temp_path, "exception.xml") + ) + + self.ApplyConfig(pkgconfig, temp_path, packagename) modify_dir_list =3D self.GetModifyDir(packagename) patch =3D self.GetDiff(packagename) - ecc_diff_range =3D self.GetDiffRange(patch, packagename, workspace= _path) - self.GenerateEccReport(modify_dir_list, ecc_diff_range, workspace_= path, basetools_path) - ecc_log =3D os.path.join(workspace_path, "Ecc.log") - self.RevertCode() + ecc_diff_range =3D self.GetDiffRange(patch, packagename, temp_path) + # + # Use temp_path as working directory when running ECC tool + # + self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path,= basetools_path) + ecc_log =3D os.path.join(temp_path, "Ecc.log") if self.ECC_PASS: + # Delete temp directory + if os.path.exists(temp_path): + shutil.rmtree(temp_path) tc.SetSuccess() - self.RemoveFile(ecc_log) return 0 else: with open(ecc_log, encoding=3D'utf8') as output: ecc_output =3D output.readlines() for line in ecc_output: logging.error(line.strip()) - self.RemoveFile(ecc_log) - tc.SetFailed("EccCheck failed for {0}".format(packagename), "E= cc detected issues") + # Delete temp directory + if os.path.exists(temp_path): + shutil.rmtree(temp_path) + tc.SetFailed("EccCheck failed for {0}".format(packagename), "C= HECK FAILED") return 1 =20 - def RevertCode(self) -> None: - submoudle_params =3D "submodule update --init" - RunCmd("git", submoudle_params) - reset_params =3D "reset HEAD --hard" - RunCmd("git", reset_params) - def GetDiff(self, pkg: str) -> List[str]: return_buffer =3D StringIO() params =3D "diff --unified=3D0 origin/master HEAD" @@ -105,11 +123,6 @@ class EccCheck(ICiBuildPlugin): =20 return patch =20 - def RemoveFile(self, file: str) -> None: - if os.path.exists(file): - os.remove(file) - return - def GetModifyDir(self, pkg: str) -> List[str]: return_buffer =3D StringIO() params =3D "diff --name-status" + ' HEAD' + ' origin/master' @@ -132,14 +145,14 @@ class EccCheck(ICiBuildPlugin): modify_dir_list =3D list(set(modify_dir_list)) return modify_dir_list =20 - def GetDiffRange(self, patch_diff: List[str], pkg: str, workingdir: st= r) -> Dict[str, List[Tuple[int, int]]]: + def GetDiffRange(self, patch_diff: List[str], pkg: str, temp_path: str= ) -> Dict[str, List[Tuple[int, int]]]: IsDelete =3D True StartCheck =3D False range_directory: Dict[str, List[Tuple[int, int]]] =3D {} for line in patch_diff: modify_file =3D self.FindModifyFile.findall(line) if modify_file and pkg in modify_file[0] and not StartCheck an= d os.path.isfile(modify_file[0]): - modify_file_comment_dic =3D self.GetCommentRange(modify_fi= le[0], workingdir) + modify_file_comment_dic =3D self.GetCommentRange(modify_fi= le[0], temp_path) IsDelete =3D False StartCheck =3D True modify_file_dic =3D modify_file[0] @@ -158,11 +171,13 @@ class EccCheck(ICiBuildPlugin): range_directory[modify_file_dic].append(i) return range_directory =20 - def GetCommentRange(self, modify_file: str, workingdir: str) -> List[T= uple[int, int]]: - modify_file_path =3D os.path.join(workingdir, modify_file) + def GetCommentRange(self, modify_file: str, temp_path: str) -> List[Tu= ple[int, int]]: + comment_range: List[Tuple[int, int]] =3D [] + modify_file_path =3D os.path.join(temp_path, modify_file) + if not os.path.exists (modify_file_path): + return comment_range with open(modify_file_path) as f: line_no =3D 1 - comment_range: List[Tuple[int, int]] =3D [] Start =3D False for line in f: if line.startswith('/**'): @@ -179,35 +194,33 @@ class EccCheck(ICiBuildPlugin): return comment_range =20 def GenerateEccReport(self, modify_dir_list: List[str], ecc_diff_range= : Dict[str, List[Tuple[int, int]]], - workspace_path: str, basetools_path: str) -> No= ne: + temp_path: str, basetools_path: str) -> None: ecc_need =3D False ecc_run =3D True - config =3D os.path.join(basetools_path, "Source", "Python", "Ecc",= "config.ini") - exception =3D os.path.join(basetools_path, "Source", "Python", "Ec= c", "exception.xml") - report =3D os.path.join(workspace_path, "Ecc.csv") + config =3D os.path.normpath(os.path.join(basetools_path, "Sourc= e", "Python", "Ecc", "config.ini")) + exception =3D os.path.normpath(os.path.join(temp_path, "exception.= xml")) + report =3D os.path.normpath(os.path.join(temp_path, "Ecc.csv")) for modify_dir in modify_dir_list: - target =3D os.path.join(workspace_path, modify_dir) + target =3D os.path.normpath(os.path.join(temp_path, modify_dir= )) logging.info('Run ECC tool for the commit in %s' % modify_dir) ecc_need =3D True ecc_params =3D "-c {0} -e {1} -t {2} -r {3}".format(config, ex= ception, target, report) - return_code =3D RunCmd("Ecc", ecc_params, workingdir=3Dworkspa= ce_path) + return_code =3D RunCmd("Ecc", ecc_params, workingdir=3Dtemp_pa= th) if return_code !=3D 0: ecc_run =3D False break if not ecc_run: logging.error('Fail to run ECC tool') - self.ParseEccReport(ecc_diff_range, workspace_path) + self.ParseEccReport(ecc_diff_range, temp_path) =20 if not ecc_need: logging.info("Doesn't need run ECC check") =20 - revert_params =3D "checkout -- {}".format(exception) - RunCmd("git", revert_params) return =20 - def ParseEccReport(self, ecc_diff_range: Dict[str, List[Tuple[int, int= ]]], workspace_path: str) -> None: - ecc_log =3D os.path.join(workspace_path, "Ecc.log") - ecc_csv =3D os.path.join(workspace_path, "Ecc.csv") + def ParseEccReport(self, ecc_diff_range: Dict[str, List[Tuple[int, int= ]]], temp_path: str) -> None: + ecc_log =3D os.path.join(temp_path, "Ecc.log") + ecc_csv =3D os.path.join(temp_path, "Ecc.csv") row_lines =3D [] ignore_error_code =3D self.GetIgnoreErrorCode() if os.path.exists(ecc_csv): @@ -236,16 +249,16 @@ class EccCheck(ICiBuildPlugin): log.writelines(all_line) return =20 - def ApplyConfig(self, pkgconfig: Dict[str, List[str]], workspace_path:= str, basetools_path: str, pkg: str) -> None: + def ApplyConfig(self, pkgconfig: Dict[str, List[str]], temp_path: str,= pkg: str) -> None: if "IgnoreFiles" in pkgconfig: for a in pkgconfig["IgnoreFiles"]: - a =3D os.path.join(workspace_path, pkg, a) + a =3D os.path.join(temp_path, pkg, a) a =3D a.replace(os.sep, "/") =20 logging.info("Ignoring Files {0}".format(a)) if os.path.exists(a): if os.path.isfile(a): - self.RemoveFile(a) + os.remove(a) elif os.path.isdir(a): shutil.rmtree(a) else: @@ -253,7 +266,7 @@ class EccCheck(ICiBuildPlugin): =20 if "ExceptionList" in pkgconfig: exception_list =3D pkgconfig["ExceptionList"] - exception_xml =3D os.path.join(basetools_path, "Source", "Pyth= on", "Ecc", "exception.xml") + exception_xml =3D os.path.join(temp_path, "exception.xml") try: logging.info("Appending exceptions") self.AppendException(exception_list, exception_xml) --=20 2.32.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#83953): https://edk2.groups.io/g/devel/message/83953 Mute This Topic: https://groups.io/mt/87262299/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 07:14:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+83955+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83955+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1637685082; cv=none; d=zohomail.com; s=zohoarc; b=k/+DJX3zDohadgmSrVaWiiOQaZzmXfy9sTqFYJuakxGXAEXlOnB5v4+e3P3iPUdk5aimK0S8bWxjZqswQfVCm18EDwWWcPz6JadhLxW41/jVPPoOAfNttq9ghq7hnbgMeiIDmveg6l7eaYRLKTSn71LwNYHzeEBzDfW3+GUV2aY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637685082; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=szeMzu/XspkJZMYJQtKxxPkXG9sxM7onZGtFi2gBjhA=; b=DXjNNahootbNQ6awAW7wjNemzZXRLM1i65BbvR6C6J1Vh33SMuJqmPmFqMQeEXYj+wHXnY5fqQtGNLmMEsOtE3QJR7/ZVZxiSbfOaEpeDZ5LHpru5F3oVufAGkgQU3J8KcfBf7Y0cEu/5q/v2hcvUnqHVEttwPjnH7Qoev1ARhE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83955+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1637685082530785.4679821705894; Tue, 23 Nov 2021 08:31:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id OuQMYY1788612xAIKcB2rRut; Tue, 23 Nov 2021 08:31:20 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web10.13721.1637685075541196235 for ; Tue, 23 Nov 2021 08:31:15 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="298466167" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="298466167" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="571112443" X-Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.59.198]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Liming Gao , Michael Kubacki Subject: [edk2-devel] [Patch V2 2/3] .pytool/Plugin/EccCheck: Remove temp directory on exception Date: Tue, 23 Nov 2021 08:31:00 -0800 Message-Id: <20211123163101.786-3-michael.d.kinney@intel.com> In-Reply-To: <20211123163101.786-1-michael.d.kinney@intel.com> References: <20211123163101.786-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,michael.d.kinney@intel.com X-Gm-Message-State: yLkWPXt5GgUotctY8KUBNMzDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637685080; bh=gwNTpt3ZM5dqeItFT/BmymbP1O9r267OAWe7JMFfF1I=; h=Cc:Date:From:Reply-To:Subject:To; b=DX/cXjyUMoa6A0PXBHV6dg8M8CCblj0b75+6MSJa60SIENlzFzDHgCyx+/cISdsNrUW SCK6hAODwXwnmpEQ78JQSErQP9e+Y3K4VD25HS/sh1BIhT4AHb1jfw6KRHbWoba1zbNdL tj+Zh/QSTaWp6ucjNjk3nW8U91VfiLiwGvo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637685084724100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2986 Add try/except to RunBuildPlugin() to remove temporary directory if a KeyboardInterrupt exception or an unexpected exception is detected. Cc: Sean Brogan Cc: Bret Barkelew Cc: Liming Gao Cc: Michael Kubacki Signed-off-by: Michael D Kinney Acked-by: Sean Brogan Reviewed-by: Liming Gao --- .pytool/Plugin/EccCheck/EccCheck.py | 78 +++++++++++++++++------------ 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/= EccCheck.py index c4c2af1bf6e4..de766d984f7c 100644 --- a/.pytool/Plugin/EccCheck/EccCheck.py +++ b/.pytool/Plugin/EccCheck/EccCheck.py @@ -72,45 +72,61 @@ class EccCheck(ICiBuildPlugin): =20 # Create temp directory temp_path =3D os.path.join(workspace_path, 'Build', '.pytool', 'Pl= ugin', 'EccCheck') - # Delete temp directory - if os.path.exists(temp_path): - shutil.rmtree(temp_path) - # Copy package being scanned to temp_path - shutil.copytree ( - os.path.join(workspace_path, packagename), - os.path.join(temp_path, packagename), - symlinks=3DTrue - ) - # Copy exception.xml to temp_path - shutil.copyfile ( - os.path.join(basetools_path, "Source", "Python", "Ecc", "excepti= on.xml"), - os.path.join(temp_path, "exception.xml") - ) + try: + # Delete temp directory + if os.path.exists(temp_path): + shutil.rmtree(temp_path) + # Copy package being scanned to temp_path + shutil.copytree ( + os.path.join(workspace_path, packagename), + os.path.join(temp_path, packagename), + symlinks=3DTrue + ) + # Copy exception.xml to temp_path + shutil.copyfile ( + os.path.join(basetools_path, "Source", "Python", "Ecc", "exc= eption.xml"), + os.path.join(temp_path, "exception.xml") + ) =20 - self.ApplyConfig(pkgconfig, temp_path, packagename) - modify_dir_list =3D self.GetModifyDir(packagename) - patch =3D self.GetDiff(packagename) - ecc_diff_range =3D self.GetDiffRange(patch, packagename, temp_path) - # - # Use temp_path as working directory when running ECC tool - # - self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path,= basetools_path) - ecc_log =3D os.path.join(temp_path, "Ecc.log") - if self.ECC_PASS: + self.ApplyConfig(pkgconfig, temp_path, packagename) + modify_dir_list =3D self.GetModifyDir(packagename) + patch =3D self.GetDiff(packagename) + ecc_diff_range =3D self.GetDiffRange(patch, packagename, temp_= path) + # + # Use temp_path as working directory when running ECC tool + # + self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_p= ath, basetools_path) + ecc_log =3D os.path.join(temp_path, "Ecc.log") + if self.ECC_PASS: + # Delete temp directory + if os.path.exists(temp_path): + shutil.rmtree(temp_path) + tc.SetSuccess() + return 0 + else: + with open(ecc_log, encoding=3D'utf8') as output: + ecc_output =3D output.readlines() + for line in ecc_output: + logging.error(line.strip()) + # Delete temp directory + if os.path.exists(temp_path): + shutil.rmtree(temp_path) + tc.SetFailed("EccCheck failed for {0}".format(packagename)= , "CHECK FAILED") + return 1 + except KeyboardInterrupt: + # If EccCheck is interrupted by keybard interrupt, then return= failure # Delete temp directory if os.path.exists(temp_path): shutil.rmtree(temp_path) - tc.SetSuccess() - return 0 + tc.SetFailed("EccCheck interrupted for {0}".format(packagename= ), "CHECK FAILED") + return 1 else: - with open(ecc_log, encoding=3D'utf8') as output: - ecc_output =3D output.readlines() - for line in ecc_output: - logging.error(line.strip()) + # If EccCheck fails for any other exception type, raise the ex= ception # Delete temp directory if os.path.exists(temp_path): shutil.rmtree(temp_path) - tc.SetFailed("EccCheck failed for {0}".format(packagename), "C= HECK FAILED") + tc.SetFailed("EccCheck exception for {0}".format(packagename),= "CHECK FAILED") + raise return 1 =20 def GetDiff(self, pkg: str) -> List[str]: --=20 2.32.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#83955): https://edk2.groups.io/g/devel/message/83955 Mute This Topic: https://groups.io/mt/87262302/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat Apr 20 07:14:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+83954+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83954+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1637685083; cv=none; d=zohomail.com; s=zohoarc; b=WTlpq+hIierkJpIxedk7eETpZwZwiZMaGdCYt/atClMC52etxgdKxYNcvH3puiqkxh6Ck6AV+xoJKNBRUrVboK6sdYg1rV2yFKjooIemNmKOEqALYjsdQrHJiBNXRyLCozVwduLdTILQQCt0rVtWd81cDVVedXds9Jqbj1sb7zI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637685083; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=vUMOCoQ5q0TQU+Br6UrsXrfNnIt7Qz1S9sE22ytHFho=; b=BqzRXzBTD9G+GFF3+GikzgiaLxONb7s2IyLl7q/ur5ZzKZsMnHTjyNmEC1kWLaVEufXsIKKSknORcSQwgdUHkPBB93CQS2PFNQP+f3qzCSDD8Es5A4rl3KxgsgdtfIbJMFfv7jwYaLd78JtEj2AkQkRd3yinkI1FnSZPEB2hRHc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83954+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163768508354038.43055454393209; Tue, 23 Nov 2021 08:31:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kqSXYY1788612xKD5vSpui5l; Tue, 23 Nov 2021 08:31:23 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.13776.1637685074761235619 for ; Tue, 23 Nov 2021 08:31:15 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="298466170" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="298466170" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="571112444" X-Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.59.198]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Liming Gao , Michael Kubacki Subject: [edk2-devel] [Patch V2 3/3] .pytool/Plugin/EccCheck: Add performance optimizations Date: Tue, 23 Nov 2021 08:31:01 -0800 Message-Id: <20211123163101.786-4-michael.d.kinney@intel.com> In-Reply-To: <20211123163101.786-1-michael.d.kinney@intel.com> References: <20211123163101.786-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,michael.d.kinney@intel.com X-Gm-Message-State: 4EhJdzwQvQiGK9utHnmsRJsHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637685083; bh=1loRVaYGEPeot1jTLNWZKOm37SD28N2Egd50ZzaMvMM=; h=Cc:Date:From:Reply-To:Subject:To; b=JPAUeaakGNe85D9+SOHwOH6+BcSnMmuEeG2ibhxVpvaKco2BD9A6bJcTX0S65J5e1Ev 4KSLQrOvtrBogq/EKDdLPhpt23/dusE9sV3Z92Ddx+dWp0cyOTKm/+wSerpRhRIsPsDB5 eN4PUP+ZTMqBVBrbC9/Jst3LAwOfRhsYt9c= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637685085239100005 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2986 Improve the performance of EccCheck by using a temp file instead of stdout to capture the results of the git diff commands. If a large patch set is passed into EccCheck, using stdout could be slow and also added the large diff content to the build log that is redundant information. A second performance improvement is to filter the modified directories to remove duplicate directories. Complex libraries and modules that have subdirectories with sources would be scanned twice if there were source changes in both the main directory and subdirectories. Filter out the subdirectories from the modified directory list when this case is detected. Cc: Sean Brogan Cc: Bret Barkelew Cc: Liming Gao Cc: Michael Kubacki Signed-off-by: Michael D Kinney Acked-by: Sean Brogan Reviewed-by: Liming Gao --- .pytool/Plugin/EccCheck/EccCheck.py | 121 +++++++++++++++++++++------- 1 file changed, 94 insertions(+), 27 deletions(-) diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/= EccCheck.py index de766d984f7c..4fbc67765fdf 100644 --- a/.pytool/Plugin/EccCheck/EccCheck.py +++ b/.pytool/Plugin/EccCheck/EccCheck.py @@ -30,7 +30,6 @@ class EccCheck(ICiBuildPlugin): }, """ =20 - ReModifyFile =3D re.compile(r'[B-Q,S-Z]+[\d]*\t(.*)') FindModifyFile =3D re.compile(r'\+\+\+ b\/(.*)') LineScopePattern =3D (r'@@ -\d*\,*\d* \+\d*\,*\d* @@.*') LineNumRange =3D re.compile(r'@@ -\d*\,*\d* \+(\d*)\,*(\d*) @@.*') @@ -87,10 +86,12 @@ class EccCheck(ICiBuildPlugin): os.path.join(basetools_path, "Source", "Python", "Ecc", "exc= eption.xml"), os.path.join(temp_path, "exception.xml") ) + # Output file to use for git diff operations + temp_diff_output =3D os.path.join (temp_path, 'diff.txt') =20 self.ApplyConfig(pkgconfig, temp_path, packagename) - modify_dir_list =3D self.GetModifyDir(packagename) - patch =3D self.GetDiff(packagename) + modify_dir_list =3D self.GetModifyDir(packagename, temp_diff_o= utput) + patch =3D self.GetDiff(packagename, temp_diff_output) ecc_diff_range =3D self.GetDiffRange(patch, packagename, temp_= path) # # Use temp_path as working directory when running ECC tool @@ -129,37 +130,103 @@ class EccCheck(ICiBuildPlugin): raise return 1 =20 - def GetDiff(self, pkg: str) -> List[str]: - return_buffer =3D StringIO() - params =3D "diff --unified=3D0 origin/master HEAD" - RunCmd("git", params, outstream=3Dreturn_buffer) - p =3D return_buffer.getvalue().strip() - patch =3D p.split("\n") - return_buffer.close() - + def GetDiff(self, pkg: str, temp_diff_output: str) -> List[str]: + patch =3D [] + # + # Generate unified diff between origin/master and HEAD. + # + params =3D "diff --output=3D{} --unified=3D0 origin/master HEAD".f= ormat(temp_diff_output) + RunCmd("git", params) + with open(temp_diff_output) as file: + patch =3D file.read().strip().split('\n') return patch =20 - def GetModifyDir(self, pkg: str) -> List[str]: - return_buffer =3D StringIO() - params =3D "diff --name-status" + ' HEAD' + ' origin/master' - RunCmd("git", params, outstream=3Dreturn_buffer) - p1 =3D return_buffer.getvalue().strip() - dir_list =3D p1.split("\n") - return_buffer.close() + def GetModifyDir(self, pkg: str, temp_diff_output: str) -> List[str]: + # + # Generate diff between origin/master and HEAD using --diff-filter= to + # exclude deleted and renamed files that do not need to be scanned= by + # ECC. Also use --name-status to only generate the names of the f= iles + # with differences. The output format of this git diff command is= a + # list of files with the change status and the filename. The file= name + # is always at the end of the line. Examples: + # + # M MdeModulePkg/Application/CapsuleApp/CapsuleApp.h + # M MdeModulePkg/Application/UiApp/FrontPage.h + # + params =3D "diff --output=3D{} --diff-filter=3Ddr --name-status or= igin/master HEAD".format(temp_diff_output) + RunCmd("git", params) + dir_list =3D [] + with open(temp_diff_output) as file: + dir_list =3D file.read().strip().split('\n') + modify_dir_list =3D [] for modify_dir in dir_list: - file_path =3D self.ReModifyFile.findall(modify_dir) - if file_path: - file_dir =3D os.path.dirname(file_path[0]) - else: + # + # Parse file name from the end of the line + # + file_path =3D modify_dir.strip().split() + # + # Skip lines that do not have at least 2 elements (status and = file name) + # + if len(file_path) < 2: continue - if pkg in file_dir and file_dir !=3D pkg: - modify_dir_list.append('%s' % file_dir) - else: + # + # Parse the directory name from the file name + # + file_dir =3D os.path.dirname(file_path[-1]) + # + # Skip directory names that do not start with the package bein= g scanned. + # + if file_dir.split('/')[0] !=3D pkg: continue + # + # Skip directory names that are identical to the package being= scanned. + # The assumption here is that there are no source files at the= package + # root. Instead, the only expected files in the package root = are + # EDK II meta data files (DEC, DSC, FDF). + # + if file_dir =3D=3D pkg: + continue + # + # Skip directory names that are already in the modified dir li= st + # + if file_dir in modify_dir_list: + continue + # + # Add the candidate directory to scan to the modified dir list + # + modify_dir_list.append(file_dir) =20 - modify_dir_list =3D list(set(modify_dir_list)) - return modify_dir_list + # + # Remove duplicates from modify_dir_list + # Given a folder path, ECC performs a recursive scan of that folde= r. + # If a parent and child folder are both present in modify_dir_list, + # then ECC will perform redudanct scans of source files. In order + # to prevent redundant scans, if a parent and child folder are both + # present, then remove all the child folders. + # + # For example, if modified_dir_list contains the following element= s: + # MdeModulePkg/Core/Dxe + # MdeModulePkg/Core/Dxe/Hand + # MdeModulePkg/Core/Dxe/Mem + # + # Then MdeModulePkg/Core/Dxe/Hand and MdeModulePkg/Core/Dxe/Mem sh= ould + # be removed because the files in those folders are covered by a s= can + # of MdeModulePkg/Core/Dxe. + # + filtered_list =3D [] + for dir1 in modify_dir_list: + Append =3D True + for dir2 in modify_dir_list: + if dir1 =3D=3D dir2: + continue + common =3D os.path.commonpath([dir1, dir2]) + if os.path.normpath(common) =3D=3D os.path.normpath(dir2): + Append =3D False + break + if Append and dir1 not in filtered_list: + filtered_list.append(dir1) + return filtered_list =20 def GetDiffRange(self, patch_diff: List[str], pkg: str, temp_path: str= ) -> Dict[str, List[Tuple[int, int]]]: IsDelete =3D True --=20 2.32.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#83954): https://edk2.groups.io/g/devel/message/83954 Mute This Topic: https://groups.io/mt/87262301/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-