* [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 @ 2020-12-29 12:14 Bob Feng 2021-01-04 0:50 ` 回复: " gaoliming 0 siblings, 1 reply; 7+ messages in thread From: Bob Feng @ 2020-12-29 12:14 UTC (permalink / raw) To: devel; +Cc: Liming Gao, Yuwei Chen, Mingyue Liang 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> --- .../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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 2020-12-29 12:14 [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 Bob Feng @ 2021-01-04 0:50 ` gaoliming 2021-01-04 2:27 ` [edk2-devel] " Bob Feng 0 siblings, 1 reply; 7+ messages in thread From: gaoliming @ 2021-01-04 0:50 UTC (permalink / raw) To: 'Bob Feng', devel; +Cc: 'Yuwei Chen', 'Mingyue Liang' Bob: > -----邮件原件----- > 发件人: Bob Feng <bob.c.feng@intel.com> > 发送时间: 2020年12月29日 20:15 > 收件人: devel@edk2.groups.io > 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen > <yuwei.chen@intel.com>; Mingyue Liang <mingyuex.liang@intel.com> > 主题: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on > Py39 > > 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> > --- > .../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) Does this change always update the file time stamp even if the file content is not changed? Thanks Liming > > elif Ver: > Cmd += ("-n", Ver) > if BuildNumber: > Cmd += ("-j", BuildNumber) > -- > 2.29.1.windows.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 2021-01-04 0:50 ` 回复: " gaoliming @ 2021-01-04 2:27 ` Bob Feng 2021-01-04 8:31 ` 回复: " gaoliming 0 siblings, 1 reply; 7+ messages in thread From: Bob Feng @ 2021-01-04 2:27 UTC (permalink / raw) To: devel@edk2.groups.io, gaoliming@byosoft.com.cn Cc: Chen, Christine, Liang, MingyueX Yes. it will always update .ui file. Thanks, Bob -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming Sent: Monday, January 4, 2021 8:51 AM To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX <mingyuex.liang@intel.com> Subject: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 Bob: > -----邮件原件----- > 发件人: Bob Feng <bob.c.feng@intel.com> > 发送时间: 2020年12月29日 20:15 > 收件人: devel@edk2.groups.io > 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen > <yuwei.chen@intel.com>; Mingyue Liang <mingyuex.liang@intel.com> > 主题: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal > on > Py39 > > 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> > --- > .../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) Does this change always update the file time stamp even if the file content is not changed? Thanks Liming > > elif Ver: > Cmd += ("-n", Ver) > if BuildNumber: > Cmd += ("-j", BuildNumber) > -- > 2.29.1.windows.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* 回复: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 2021-01-04 2:27 ` [edk2-devel] " Bob Feng @ 2021-01-04 8:31 ` gaoliming 2021-01-05 9:09 ` Bob Feng 0 siblings, 1 reply; 7+ messages in thread From: gaoliming @ 2021-01-04 8:31 UTC (permalink / raw) To: 'Feng, Bob C', devel Cc: 'Chen, Christine', 'Liang, MingyueX' Original SaveFileOnChange() saves the file only when the file is updated. Can this patch keep the same behavior? Thanks Liming > -----邮件原件----- > 发件人: Feng, Bob C <bob.c.feng@intel.com> > 发送时间: 2021年1月4日 10:27 > 收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn > 抄送: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > 主题: RE: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by > tostring() removal on Py39 > > Yes. it will always update .ui file. > > Thanks, > Bob > > -----Original Message----- > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming > Sent: Monday, January 4, 2021 8:51 AM > To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io > Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > Subject: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by > tostring() removal on Py39 > > Bob: > > > -----邮件原件----- > > 发件人: Bob Feng <bob.c.feng@intel.com> > > 发送时间: 2020年12月29日 20:15 > > 收件人: devel@edk2.groups.io > > 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen > > <yuwei.chen@intel.com>; Mingyue Liang <mingyuex.liang@intel.com> > > 主题: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal > > on > > Py39 > > > > 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> > > --- > > .../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) > > Does this change always update the file time stamp even if the file content is > not changed? > > Thanks > Liming > > > > elif Ver: > > Cmd += ("-n", Ver) > > if BuildNumber: > > Cmd += ("-j", BuildNumber) > > -- > > 2.29.1.windows.1 > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 2021-01-04 8:31 ` 回复: " gaoliming @ 2021-01-05 9:09 ` Bob Feng 2021-01-05 13:27 ` 回复: " gaoliming 0 siblings, 1 reply; 7+ messages in thread From: Bob Feng @ 2021-01-05 9:09 UTC (permalink / raw) To: gaoliming, devel@edk2.groups.io; +Cc: Chen, Christine, Liang, MingyueX Hi Liming, The method in this patch is just to avoid converting the SectionData to a bytes string because there is no compatible way to generate a bytes string from a array.array. So I can't do the bytes strings comparison between the new content and the content in the existing file. Since the this block of code will only run in GenFds phase, the effect of the incremental save is small, I think it can be fine to save the new content anyway. Thanks, Bob -----Original Message----- From: gaoliming <gaoliming@byosoft.com.cn> Sent: Monday, January 4, 2021 4:32 PM To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX <mingyuex.liang@intel.com> Subject: 回复: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 Original SaveFileOnChange() saves the file only when the file is updated. Can this patch keep the same behavior? Thanks Liming > -----邮件原件----- > 发件人: Feng, Bob C <bob.c.feng@intel.com> > 发送时间: 2021年1月4日 10:27 > 收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn > 抄送: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > 主题: RE: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused > by > tostring() removal on Py39 > > Yes. it will always update .ui file. > > Thanks, > Bob > > -----Original Message----- > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > gaoliming > Sent: Monday, January 4, 2021 8:51 AM > To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io > Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > Subject: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused > by > tostring() removal on Py39 > > Bob: > > > -----邮件原件----- > > 发件人: Bob Feng <bob.c.feng@intel.com> > > 发送时间: 2020年12月29日 20:15 > > 收件人: devel@edk2.groups.io > > 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen > > <yuwei.chen@intel.com>; Mingyue Liang <mingyuex.liang@intel.com> > > 主题: [Patch 1/1] BaseTools: Fix the issue caused by tostring() > > removal on > > Py39 > > > > 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> > > --- > > .../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) > > Does this change always update the file time stamp even if the file > content is not changed? > > Thanks > Liming > > > > elif Ver: > > Cmd += ("-n", Ver) > > if BuildNumber: > > Cmd += ("-j", BuildNumber) > > -- > > 2.29.1.windows.1 > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* 回复: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 2021-01-05 9:09 ` Bob Feng @ 2021-01-05 13:27 ` gaoliming 2021-01-06 0:58 ` Bob Feng 0 siblings, 1 reply; 7+ messages in thread From: gaoliming @ 2021-01-05 13:27 UTC (permalink / raw) To: 'Feng, Bob C', devel Cc: 'Chen, Christine', 'Liang, MingyueX' Bob: I agree its impact is not big. If no better solution, I am OK for this fix. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Thanks Liming > -----邮件原件----- > 发件人: Feng, Bob C <bob.c.feng@intel.com> > 发送时间: 2021年1月5日 17:10 > 收件人: gaoliming <gaoliming@byosoft.com.cn>; devel@edk2.groups.io > 抄送: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > 主题: RE: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by > tostring() removal on Py39 > > Hi Liming, > > The method in this patch is just to avoid converting the SectionData to a bytes > string because there is no compatible way to generate a bytes string from a > array.array. > So I can't do the bytes strings comparison between the new content and the > content in the existing file. > > Since the this block of code will only run in GenFds phase, the effect of the > incremental save is small, I think it can be fine to save the new content > anyway. > > Thanks, > Bob > > -----Original Message----- > From: gaoliming <gaoliming@byosoft.com.cn> > Sent: Monday, January 4, 2021 4:32 PM > To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io > Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > Subject: 回复: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue > caused by tostring() removal on Py39 > > Original SaveFileOnChange() saves the file only when the file is updated. Can > this patch keep the same behavior? > > Thanks > Liming > > -----邮件原件----- > > 发件人: Feng, Bob C <bob.c.feng@intel.com> > > 发送时间: 2021年1月4日 10:27 > > 收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn > > 抄送: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > > <mingyuex.liang@intel.com> > > 主题: RE: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused > > by > > tostring() removal on Py39 > > > > Yes. it will always update .ui file. > > > > Thanks, > > Bob > > > > -----Original Message----- > > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > > gaoliming > > Sent: Monday, January 4, 2021 8:51 AM > > To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io > > Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > > <mingyuex.liang@intel.com> > > Subject: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused > > by > > tostring() removal on Py39 > > > > Bob: > > > > > -----邮件原件----- > > > 发件人: Bob Feng <bob.c.feng@intel.com> > > > 发送时间: 2020年12月29日 20:15 > > > 收件人: devel@edk2.groups.io > > > 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen > > > <yuwei.chen@intel.com>; Mingyue Liang <mingyuex.liang@intel.com> > > > 主题: [Patch 1/1] BaseTools: Fix the issue caused by tostring() > > > removal on > > > Py39 > > > > > > 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> > > > --- > > > .../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) > > > > Does this change always update the file time stamp even if the file > > content is not changed? > > > > Thanks > > Liming > > > > > > elif Ver: > > > Cmd += ("-n", Ver) > > > if BuildNumber: > > > Cmd += ("-j", BuildNumber) > > > -- > > > 2.29.1.windows.1 > > > > > > > > > > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 2021-01-05 13:27 ` 回复: " gaoliming @ 2021-01-06 0:58 ` Bob Feng 0 siblings, 0 replies; 7+ messages in thread From: Bob Feng @ 2021-01-06 0:58 UTC (permalink / raw) To: devel@edk2.groups.io, gaoliming@byosoft.com.cn Cc: Chen, Christine, Liang, MingyueX Thanks. I created a PR https://github.com/tianocore/edk2/pull/1296 Thanks, Bob -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming Sent: Tuesday, January 5, 2021 9:28 PM To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX <mingyuex.liang@intel.com> Subject: 回复: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 Bob: I agree its impact is not big. If no better solution, I am OK for this fix. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Thanks Liming > -----邮件原件----- > 发件人: Feng, Bob C <bob.c.feng@intel.com> > 发送时间: 2021年1月5日 17:10 > 收件人: gaoliming <gaoliming@byosoft.com.cn>; devel@edk2.groups.io > 抄送: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > 主题: RE: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused > by > tostring() removal on Py39 > > Hi Liming, > > The method in this patch is just to avoid converting the SectionData > to a bytes string because there is no compatible way to generate a > bytes string from a array.array. > So I can't do the bytes strings comparison between the new content and > the content in the existing file. > > Since the this block of code will only run in GenFds phase, the effect > of the incremental save is small, I think it can be fine to save the > new content anyway. > > Thanks, > Bob > > -----Original Message----- > From: gaoliming <gaoliming@byosoft.com.cn> > Sent: Monday, January 4, 2021 4:32 PM > To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io > Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > <mingyuex.liang@intel.com> > Subject: 回复: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue > caused by tostring() removal on Py39 > > Original SaveFileOnChange() saves the file only when the file is > updated. Can this patch keep the same behavior? > > Thanks > Liming > > -----邮件原件----- > > 发件人: Feng, Bob C <bob.c.feng@intel.com> > > 发送时间: 2021年1月4日 10:27 > > 收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn > > 抄送: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > > <mingyuex.liang@intel.com> > > 主题: RE: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue caused > > by > > tostring() removal on Py39 > > > > Yes. it will always update .ui file. > > > > Thanks, > > Bob > > > > -----Original Message----- > > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > > gaoliming > > Sent: Monday, January 4, 2021 8:51 AM > > To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io > > Cc: Chen, Christine <yuwei.chen@intel.com>; Liang, MingyueX > > <mingyuex.liang@intel.com> > > Subject: [edk2-devel] 回复: [Patch 1/1] BaseTools: Fix the issue > > caused by > > tostring() removal on Py39 > > > > Bob: > > > > > -----邮件原件----- > > > 发件人: Bob Feng <bob.c.feng@intel.com> > > > 发送时间: 2020年12月29日 20:15 > > > 收件人: devel@edk2.groups.io > > > 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen > > > <yuwei.chen@intel.com>; Mingyue Liang <mingyuex.liang@intel.com> > > > 主题: [Patch 1/1] BaseTools: Fix the issue caused by tostring() > > > removal on > > > Py39 > > > > > > 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> > > > --- > > > .../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) > > > > Does this change always update the file time stamp even if the file > > content is not changed? > > > > Thanks > > Liming > > > > > > elif Ver: > > > Cmd += ("-n", Ver) > > > if BuildNumber: > > > Cmd += ("-j", BuildNumber) > > > -- > > > 2.29.1.windows.1 > > > > > > > > > > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-01-06 0:58 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-12-29 12:14 [Patch 1/1] BaseTools: Fix the issue caused by tostring() removal on Py39 Bob Feng 2021-01-04 0:50 ` 回复: " gaoliming 2021-01-04 2:27 ` [edk2-devel] " Bob Feng 2021-01-04 8:31 ` 回复: " gaoliming 2021-01-05 9:09 ` Bob Feng 2021-01-05 13:27 ` 回复: " gaoliming 2021-01-06 0:58 ` Bob Feng
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox