From 6a64efa8e3b2a20fa11fe508fa37041eb27f436e Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Thu, 9 Jan 2025 17:45:01 +0900 Subject: [PATCH] Gracefully handle empty output from `vswhere.exe` (#1159) This is a follow up commit to my previous commit [1], which started using 'vswhere.exe' to locate 'vcvarsall.bat' as discussed in #1057. One thing I overlooked is that 'vswhere.exe' could return an empty result even when the exitcode is ERROR_SUCCESS. With this commit such a case will be gracefully handled. This is also a preparation to support ARM64 build on Windows (#1130). [1]: ace314567109cbc30dc336fb27844dacff782dd9 PiperOrigin-RevId: 713563231 --- src/build_tools/vs_util.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/build_tools/vs_util.py b/src/build_tools/vs_util.py index 0a3e49a81..44b2b06ae 100755 --- a/src/build_tools/vs_util.py +++ b/src/build_tools/vs_util.py @@ -112,22 +112,24 @@ def get_vcvarsall( msgs += ['-----stderr-----', stderr] raise ChildProcessError('\n'.join(msgs)) - vcvarsall = pathlib.Path(stdout.splitlines()[0]) - if not vcvarsall.exists(): - msg = 'Could not find vcvarsall.bat.' - if arch.endswith('arm64'): - msg += ( - ' Make sure Microsoft.VisualStudio.Component.VC.Tools.ARM64 is' - ' installed.' - ) - else: - msg += ( - ' Consider using --vcvarsall_path option e.g.\n' - r' --vcvarsall_path=C:\VS\VC\Auxiliary\Build\vcvarsall.bat' - ) - raise FileNotFoundError(msg) - - return vcvarsall + lines = stdout.splitlines() + if len(lines) > 0: + vcvarsall = pathlib.Path(lines[0]) + if vcvarsall.exists(): + return vcvarsall + + msg = 'Could not find vcvarsall.bat.' + if arch.endswith('arm64'): + msg += ( + ' Make sure Microsoft.VisualStudio.Component.VC.Tools.ARM64 is' + ' installed.' + ) + else: + msg += ( + ' Consider using --vcvarsall_path option e.g.\n' + r' --vcvarsall_path=C:\VS\VC\Auxiliary\Build\vcvarsall.bat' + ) + raise FileNotFoundError(msg) def get_vs_env_vars(