From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web12.14753.1637689298530860117 for ; Tue, 23 Nov 2021 09:41:39 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: michael.d.kinney@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="232568365" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="232568365" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 09:31:41 -0800 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="497356369" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.59.198]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 09:31:40 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Liming Gao , Michael Kubacki Subject: [Patch V2 1/1] .pytools/Plugin/LicenseCheck: Use temp directory for git diff output Date: Tue, 23 Nov 2021 09:31:31 -0800 Message-Id: <20211123173131.1245-1-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.32.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: -- 2.32.0.windows.1