]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Fix the issue caused by tostring() removal on Py39
authorBob Feng <bob.c.feng@intel.com>
Tue, 29 Dec 2020 09:03:53 +0000 (17:03 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 6 Jan 2021 01:24:43 +0000 (01:24 +0000)
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 <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Mingyue Liang <mingyuex.liang@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py

index dc1727c4666db66e9621f311f96dab4c7b1a8e19..3019ec63c3bb8f757e284c58c121079d1542428f 100644 (file)
@@ -27,10 +27,11 @@ from Common.TargetTxtClassObject import TargetTxtDict
 from Common.ToolDefClassObject import ToolDefDict\r
 from AutoGen.BuildEngine import ToolBuildRule\r
 import Common.DataType as DataType\r
-from Common.Misc import PathClass\r
+from Common.Misc import PathClass,CreateDirectory\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 import Common.GlobalData as GlobalData\r
+from Common.BuildToolError import *\r
 \r
 ## Global variables\r
 #\r
@@ -463,12 +464,28 @@ class GenFdsGlobalVariable:
                     GenFdsGlobalVariable.SecCmdList.append(' '.join(Cmd).strip())\r
             else:\r
                 SectionData = array('B', [0, 0, 0, 0])\r
-                SectionData.fromstring(Ui.encode("utf_16_le"))\r
+                SectionData.fromlist(array('B',Ui.encode('utf-16-le')).tolist())\r
                 SectionData.append(0)\r
                 SectionData.append(0)\r
                 Len = len(SectionData)\r
                 GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)\r
-                SaveFileOnChange(Output, SectionData.tostring())\r
+\r
+\r
+                DirName = os.path.dirname(Output)\r
+                if not CreateDirectory(DirName):\r
+                    EdkLogger.error(None, FILE_CREATE_FAILURE, "Could not create directory %s" % DirName)\r
+                else:\r
+                    if DirName == '':\r
+                        DirName = os.getcwd()\r
+                    if not os.access(DirName, os.W_OK):\r
+                        EdkLogger.error(None, PERMISSION_FAILURE, "Do not have write permission on directory %s" % DirName)\r
+\r
+                try:\r
+                    with open(Output, "wb") as Fd:\r
+                        SectionData.tofile(Fd)\r
+                        Fd.flush()\r
+                except IOError as X:\r
+                    EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X)\r
 \r
         elif Ver:\r
             Cmd += ("-n", Ver)\r