From 875b202cbbc2ecf1aa86243be7541fbb43d647c8 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 31 Dec 2019 18:50:40 +0200 Subject: [PATCH] Windows: Fix ImportError: No module named win32file (see https://crbug.com/1033106) --- patch/patch.cfg | 5 ++ patch/patches/win_tool_wrapper_1033106.patch | 67 ++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 patch/patches/win_tool_wrapper_1033106.patch diff --git a/patch/patch.cfg b/patch/patch.cfg index c12b263cb..c21133754 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -468,4 +468,9 @@ patches = [ # https://bitbucket.org/chromiumembedded/cef/issues/2745 'name': 'osr_fling_2745', }, + { + # Windows: Fix ImportError: No module named win32file + # https://bugs.chromium.org/p/chromium/issues/detail?id=1033106#c7 + 'name': 'win_tool_wrapper_1033106', + } ] diff --git a/patch/patches/win_tool_wrapper_1033106.patch b/patch/patches/win_tool_wrapper_1033106.patch new file mode 100644 index 000000000..54a9cab17 --- /dev/null +++ b/patch/patches/win_tool_wrapper_1033106.patch @@ -0,0 +1,67 @@ +diff --git build/toolchain/win/tool_wrapper.py build/toolchain/win/tool_wrapper.py +index e5cc81b1fde7..d32cd8779948 100644 +--- build/toolchain/win/tool_wrapper.py ++++ build/toolchain/win/tool_wrapper.py +@@ -17,50 +17,6 @@ import subprocess + import stat + import sys + +-# Embedded vpython spec to provide `win32file` when this is invoked with +-# vpython on windows. +-# +-# [VPYTHON:BEGIN] +-# wheel: < +-# name: "infra/python/wheels/pypiwin32/${vpython_platform}" +-# version: "version:219" +-# match_tag: < platform: "win32" > +-# match_tag: < platform: "win_amd64" > +-# > +-# [VPYTHON:END] +- +-if sys.platform == "win32": +- try: +- # First, try the normal way. This will work for python installations which +- # have win32file already, or for vpython invocations of this script. +- import win32file +- except ImportError: +- # Otherwise, do a hack to locate the depot_tools specific version of +- # win32file. +- # +- # tool_wrapper.py doesn't get invoked through python.bat so the Python bin +- # directory doesn't get added to the path. The Python module search logic +- # handles this fine and finds win32file.pyd. However the Windows module +- # search logic then looks for pywintypes27.dll and other DLLs in the path +- # and if it finds versions with a different bitness first then win32file.pyd +- # will fail to load with a cryptic error: +- # ImportError: DLL load failed: %1 is not a valid Win32 application. +- if sys.platform == 'win32': +- os.environ['PATH'] = os.path.dirname(sys.executable) + \ +- os.pathsep + os.environ['PATH'] +- import win32file # pylint: disable=import-error +- +- def superflush(pe_name): +- # Flush the file buffers to try to work around a Windows 10 kernel bug, +- # https://crbug.com/644525 +- output_handle = win32file.CreateFile(pe_name, win32file.GENERIC_WRITE, +- 0, None, win32file.OPEN_EXISTING, 0, 0) +- win32file.FlushFileBuffers(output_handle) +- output_handle.Close() +-else: +- def superflush(pe_name): +- return None +- + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + + # A regex matching an argument corresponding to the output filename passed to +@@ -188,10 +144,7 @@ class WinTool(object): + not line.startswith('Generating code') and + not line.startswith('Finished generating code')): + print(line) +- result = link.wait() +- if result == 0 and sys.platform == 'win32': +- superflush(pe_name) +- return result ++ return link.wait() + + def ExecAsmWrapper(self, arch, *args): + """Filter logo banner from invocations of asm.exe."""