From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web08.95.1637709954594589307 for ; Tue, 23 Nov 2021 15:25:54 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=AxZlbv2V; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from [10.0.0.19] (c-73-27-179-174.hsd1.fl.comcast.net [73.27.179.174]) by linux.microsoft.com (Postfix) with ESMTPSA id 581C520D4D3F; Tue, 23 Nov 2021 15:25:53 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 581C520D4D3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1637709953; bh=H7McgqJhD+A8KwoJ9HGIK7VSh2f70CyRqZf03ef/9HY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AxZlbv2V6ByR7mx7Snk62ejQtMnvZvq0LaQ+gNDmW0rFwYVJQcAH01VSmnabhYfHg CmlmcL0HYy6jYNwvYMw0fw7/ShXy/iUXmczREEAOQT0Oa+tQSTqK+rdDMhsQZgnjpu 04s3/aU2c18iR/RILakah0fc/2lcjB/5rlMuHAY8= Message-ID: <8c0245e6-8f0f-6832-673e-978410b4ca19@linux.microsoft.com> Date: Tue, 23 Nov 2021 18:25:52 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 Subject: Re: [edk2-devel] [Patch V2 1/1] .pytools/Plugin/LicenseCheck: Use temp directory for git diff output To: devel@edk2.groups.io, michael.d.kinney@intel.com Cc: Sean Brogan , Bret Barkelew , Liming Gao , Michael Kubacki References: <20211123173131.1245-1-michael.d.kinney@intel.com> From: "Michael Kubacki" In-Reply-To: <20211123173131.1245-1-michael.d.kinney@intel.com> Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Acked-by: Michael Kubacki On 11/23/2021 12:31 PM, Michael D Kinney wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3746 > > Use --output option in git diff command to remove code diffs > from build log on stdout when LicenseCheck plugin is run. > Instead, create a temp directory for the diff output file and > remove the temp directory after the diff output is processed. > > Cc: Sean Brogan > Cc: Bret Barkelew > Cc: Liming Gao > Cc: Michael Kubacki > Signed-off-by: Michael D Kinney > --- > .pytool/Plugin/LicenseCheck/LicenseCheck.py | 20 ++++++++++++++------ > 1 file changed, 14 insertions(+), 6 deletions(-) > > diff --git a/.pytool/Plugin/LicenseCheck/LicenseCheck.py b/.pytool/Plugin/LicenseCheck/LicenseCheck.py > index 5733f7bf4ec0..7b998daf6f6b 100644 > --- a/.pytool/Plugin/LicenseCheck/LicenseCheck.py > +++ b/.pytool/Plugin/LicenseCheck/LicenseCheck.py > @@ -5,6 +5,7 @@ > ## > > import os > +import shutil > import logging > import re > from io import StringIO > @@ -61,12 +62,19 @@ class LicenseCheck(ICiBuildPlugin): > # - Junit Logger > # - output_stream the StringIO output stream from this plugin via logging > def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None): > - return_buffer = StringIO() > - params = "diff --unified=0 origin/master HEAD" > - RunCmd("git", params, outstream=return_buffer) > - p = return_buffer.getvalue().strip() > - patch = p.split("\n") > - return_buffer.close() > + # Create temp directory > + temp_path = os.path.join(Edk2pathObj.WorkspacePath, 'Build', '.pytool', 'Plugin', 'LicenseCheck') > + if not os.path.exists(temp_path): > + os.makedirs(temp_path) > + # Output file to use for git diff operations > + temp_diff_output = os.path.join (temp_path, 'diff.txt') > + params = "diff --output={} --unified=0 origin/master HEAD".format(temp_diff_output) > + RunCmd("git", params) > + with open(temp_diff_output) as file: > + patch = file.read().strip().split("\n") > + # Delete temp directory > + if os.path.exists(temp_path): > + shutil.rmtree(temp_path) > > ignore_files = [] > if "IgnoreFiles" in pkgconfig: >