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.web10.10861.1609244103357949286 for ; Tue, 29 Dec 2020 04:15:03 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: bob.c.feng@intel.com) IronPort-SDR: W6AzrRJ+ZtQX9nF0HPdtX7RfiQsZqfeplW4AX47dBv703PihFWHB/MOtLVmrptyDmUQFctGOKH NRurwDADLx1w== X-IronPort-AV: E=McAfee;i="6000,8403,9848"; a="172976841" X-IronPort-AV: E=Sophos;i="5.78,457,1599548400"; d="scan'208";a="172976841" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Dec 2020 04:15:02 -0800 IronPort-SDR: rEpusL3y0rirh9SCpHnlGR10l+0r03iRm4pY28yPLmJkAI3IFj5/aGfKhL7iF1a08pSXU2drOB LfEkoSgrkulw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,457,1599548400"; d="scan'208";a="460138387" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.32]) by fmsmga001.fm.intel.com with ESMTP; 29 Dec 2020 04:15:01 -0800 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Yuwei Chen , Mingyue Liang Subject: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 Date: Tue, 29 Dec 2020 20:14:57 +0800 Message-Id: <20201229121457.1066-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.29.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3136 Python 3.9 remove the array.array.tostring and array.array.fromstring() function. This patch is to use other method to replace tostring() and fromstring() Signed-off-by: Bob Feng Cc: Liming Gao Cc: Yuwei Chen Cc: Mingyue Liang --- .../Python/GenFds/GenFdsGlobalVariable.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index dc1727c4666d..3019ec63c3bb 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -25,14 +25,15 @@ from Common.Misc import SaveFileOnChange from Common.TargetTxtClassObject import TargetTxtDict from Common.ToolDefClassObject import ToolDefDict from AutoGen.BuildEngine import ToolBuildRule import Common.DataType as DataType -from Common.Misc import PathClass +from Common.Misc import PathClass,CreateDirectory from Common.LongFilePathSupport import OpenLongFilePath as open from Common.MultipleWorkspace import MultipleWorkspace as mws import Common.GlobalData as GlobalData +from Common.BuildToolError import * ## Global variables # # class GenFdsGlobalVariable: @@ -461,16 +462,32 @@ class GenFdsGlobalVariable: Cmd += ("-o", Output) if ' '.join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList: GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip()) else: SectionData = array('B', [0, 0, 0, 0]) - SectionData.fromstring(Ui.encode("utf_16_le")) + SectionData.fromlist(array('B',Ui.encode('utf-16-le')).tolist()) SectionData.append(0) SectionData.append(0) Len = len(SectionData) GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15) - SaveFileOnChange(Output, SectionData.tostring()) + + + DirName = os.path.dirname(Output) + if not CreateDirectory(DirName): + EdkLogger.error(None, FILE_CREATE_FAILURE, "Could not create directory %s" % DirName) + else: + if DirName == '': + DirName = os.getcwd() + if not os.access(DirName, os.W_OK): + EdkLogger.error(None, PERMISSION_FAILURE, "Do not have write permission on directory %s" % DirName) + + try: + with open(Output, "wb") as Fd: + SectionData.tofile(Fd) + Fd.flush() + except IOError as X: + EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X) elif Ver: Cmd += ("-n", Ver) if BuildNumber: Cmd += ("-j", BuildNumber) -- 2.29.1.windows.1