Skip to content

Commit

Permalink
Gracefully handle empty output from vswhere.exe (#1159)
Browse files Browse the repository at this point in the history
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]: ace3145

PiperOrigin-RevId: 713563231
  • Loading branch information
yukawa authored Jan 9, 2025
1 parent c4cbd4c commit 6a64efa
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/build_tools/vs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6a64efa

Please sign in to comment.