From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0128E21138AB5 for ; Sun, 16 Sep 2018 23:43:09 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Sep 2018 23:43:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,384,1531810800"; d="scan'208";a="257844555" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by orsmga005.jf.intel.com with ESMTP; 16 Sep 2018 23:43:07 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Liming Gao Date: Mon, 17 Sep 2018 14:43:06 +0800 Message-Id: <1537166586-32980-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: remove PyUtility and open the file with unbuffered X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Sep 2018 06:43:10 -0000 the PyUtility is not used, so we remove it. And update the open file with unbuffered to avoid the case that the file is not wrote but directly used in later when the host's multiple thread is very strong. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu --- BaseTools/Source/C/PyUtility/Makefile | 25 ------- BaseTools/Source/C/PyUtility/PyUtility.c | 106 --------------------------- BaseTools/Source/C/PyUtility/setup.py | 42 ----------- BaseTools/Source/Python/Common/Misc.py | 16 +--- BaseTools/Source/Python/Common/PyUtility.pyd | Bin 6144 -> 0 bytes 5 files changed, 3 insertions(+), 186 deletions(-) delete mode 100644 BaseTools/Source/C/PyUtility/Makefile delete mode 100644 BaseTools/Source/C/PyUtility/PyUtility.c delete mode 100644 BaseTools/Source/C/PyUtility/setup.py delete mode 100644 BaseTools/Source/Python/Common/PyUtility.pyd diff --git a/BaseTools/Source/C/PyUtility/Makefile b/BaseTools/Source/C/PyUtility/Makefile deleted file mode 100644 index 5829070..0000000 --- a/BaseTools/Source/C/PyUtility/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -## @file -# Makefile -# -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -!INCLUDE ..\Makefiles\ms.common - -APPNAME = GenSec - -LIBS = $(LIB_PATH)\Common.lib - -OBJECTS = PyUtility.obj - -#CFLAGS = $(CFLAGS) /nodefaultlib:libc.lib - -!INCLUDE ..\Makefiles\ms.app - diff --git a/BaseTools/Source/C/PyUtility/PyUtility.c b/BaseTools/Source/C/PyUtility/PyUtility.c deleted file mode 100644 index d14b872..0000000 --- a/BaseTools/Source/C/PyUtility/PyUtility.c +++ /dev/null @@ -1,106 +0,0 @@ -/** @file -Python Utility - -Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
-This program and the accompanying materials are licensed and made available -under the terms and conditions of the BSD License which accompanies this -distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include -#include -#include - -/* - SaveFileToDisk(FilePath, Content) -*/ -STATIC -PyObject* -SaveFileToDisk ( - PyObject *Self, - PyObject *Args - ) -{ - CHAR8 *File; - UINT8 *Data; - UINTN DataLength; - UINTN WriteBytes; - UINTN Status; - HANDLE FileHandle; - PyObject *ReturnValue = Py_False; - - Status = PyArg_ParseTuple( - Args, - "ss#", - &File, - &Data, - &DataLength - ); - if (Status == 0) { - return NULL; - } - - FileHandle = CreateFile( - File, - GENERIC_WRITE, - FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_SHARE_DELETE, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL - ); - if (FileHandle == INVALID_HANDLE_VALUE) { - PyErr_SetString(PyExc_Exception, "File creation failure"); - return NULL; - } - - while (WriteFile(FileHandle, Data, DataLength, &WriteBytes, NULL)) { - if (DataLength <= WriteBytes) { - DataLength = 0; - break; - } - - Data += WriteBytes; - DataLength -= WriteBytes; - } - - if (DataLength != 0) { - // file saved unsuccessfully - PyErr_SetString(PyExc_Exception, "File write failure"); - goto Done; - } - - // - // Flush buffer may slow down the whole build performance (average 10s slower) - // - //if (!FlushFileBuffers(FileHandle)) { - // PyErr_SetString(PyExc_Exception, "File flush failure"); - // goto Done; - //} - - // success! - ReturnValue = Py_True; - -Done: - CloseHandle(FileHandle); - return ReturnValue; -} - -STATIC INT8 SaveFileToDiskDocs[] = "SaveFileToDisk(): Make sure the file is saved to disk\n"; - -STATIC PyMethodDef PyUtility_Funcs[] = { - {"SaveFileToDisk", (PyCFunction)SaveFileToDisk, METH_VARARGS, SaveFileToDiskDocs}, - {NULL, NULL, 0, NULL} -}; - -PyMODINIT_FUNC -initPyUtility(VOID) { - Py_InitModule3("PyUtility", PyUtility_Funcs, "Utilties Module Implemented C Language"); -} - - diff --git a/BaseTools/Source/C/PyUtility/setup.py b/BaseTools/Source/C/PyUtility/setup.py deleted file mode 100644 index e4d407d..0000000 --- a/BaseTools/Source/C/PyUtility/setup.py +++ /dev/null @@ -1,42 +0,0 @@ -## @file -# package and install PyEfiCompressor extension -# -# Copyright (c) 2008, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# - -## -# Import Modules -# -from distutils.core import setup, Extension -import os - -if 'BASE_TOOLS_PATH' not in os.environ: - raise "Please define BASE_TOOLS_PATH to the root of base tools tree" - -BaseToolsDir = os.environ['BASE_TOOLS_PATH'] -setup( - name="PyUtility", - version="0.01", - ext_modules=[ - Extension( - 'PyUtility', - sources=[ - 'PyUtility.c' - ], - include_dirs=[ - os.path.join(BaseToolsDir, 'Source', 'C', 'Include'), - os.path.join(BaseToolsDir, 'Source', 'C', 'Include', 'Ia32'), - os.path.join(BaseToolsDir, 'Source', 'C', 'Common') - ], - ) - ], - ) - diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 430bf6b..3a8e7ca 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -470,23 +470,13 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True): 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: - if GlobalData.gIsWindows: - try: - from .PyUtility import SaveFileToDisk - if not SaveFileToDisk(File, Content): - EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData=File) - except: - Fd = open(File, "wb") - Fd.write(Content) - Fd.close() - else: - Fd = open(File, "wb") - Fd.write(Content) - Fd.close() + Fd = open(File, "wb", 0) + Fd.write(Content) + Fd.close() except IOError as X: EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X) return True diff --git a/BaseTools/Source/Python/Common/PyUtility.pyd b/BaseTools/Source/Python/Common/PyUtility.pyd deleted file mode 100644 index 856b508e4ea39a806fbe52264ac5e4db0956a2de..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6144 zcmeHLe{hrK9e*LWve_ASI=x2o0fm+ayhs`sRIE ztFXg`&gEXKZh9Oy-AS*z!|n7=Jsll53AD4Ib%zWqo1NFW>VoaG3PRm#-+i7pDYS^* z?XPWjKDqDnyPsC2^UQ_s)&|ek&^PzraJecO|R>n<%20xWK?Sacd zNTo_cPUOE^HH{l4>VkQyY(nNzM^f0=^DycGMrEy6=4wJRmF3luxPYKRLjxHNo9MnP zV`}+aAt4)peX@WkTPVkMTNxo+RM(}g6dmayyk_22kf|%x1JQLK4e)E);1XVMHWY(X8jnrM;v&iLBweWenv{@( ziV$r*lSs*^HffZql!0qy^>s`gh4j!1x6Z&oPC(o)peVSiN4#2uH%xJ$t23^ zdt@j!D!*+-7O4s)|Xl4xKok%^ZfZAFh;h=os6h zQ%N~KswUfAQyb68gYevrvv9&E<>b>~wQD3>5g6hQo$KfVkVo^G#Q9S=gQfk#&Hf~O zkqx(lAxLW7@*slt_tC6=hmIc7u6*zZ)%A#ec5qSBiHl%#rT=9x`(H%YpGoPIF?l;k zb#>s&g75%P{^uyyGw70YDJ^cJyo_AO?$L=_Xfl{VV^i7Hh~SG_ z*+9{<;_>+#AQTbE?a*T4>r#Ac)5N$*lJYO*Tkh97HA!t%oQh4Tg&eqaA60q&C7@*+ z&5mRfV3s^shj4Wya`!!`P-x2JL1{vA=s?iN_h@4uYfAU%_^Q}yB3zISZPb@6;k;ZT z55^r6DMUO=-aL^KD-X&xDumJoCFew}Pscj-VkYa*3NOZ;`nXdUcW9-F(L=JRlMTBe zt}Z1+DHo-1m_#=XA?uhFwXSshP(z;jdrqCuk)YmhFF*|6K|ZC=rB9{pS`g!o5$06f z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