Skip to content

Commit 23ae983

Browse files
committed
scripts: Use ninja.exe on Windows if present in PATH
Visual Studio 2019 ships with ninja.exe.
1 parent 2c3cff4 commit 23ae983

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

scripts/internal/windows_build_common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from subprocess import check_call
44
import os
5+
import shutil
56

67
DEFAULT_PY_ENVS = ["35-x64", "36-x64", "37-x64", "38-x64"]
78

@@ -32,6 +33,8 @@ def venv_paths(python_version):
3233
pip = os.path.join(venv_dir, "Scripts", "pip.exe")
3334

3435
ninja_executable = os.path.join(venv_dir, "Scripts", "ninja.exe")
36+
if not os.path.exists(ninja_executable):
37+
ninja_executable = shutil.which("ninja.exe")
3538
print("NINJA_EXECUTABLE:%s" % ninja_executable)
3639

3740
# Update PATH

scripts/windows_build_wheels.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ def build_wheels(py_envs=DEFAULT_PY_ENVS, single_wheel=False,
251251

252252
cmake_executable = "cmake.exe"
253253
tools_venv = os.path.join(ROOT_DIR, "venv-" + py_envs[0])
254-
pip_install(tools_venv, "ninja")
255-
ninja_executable = os.path.join(tools_venv, "Scripts", "ninja.exe")
254+
ninja_executable = shutil.which('ninja.exe')
255+
if ninja_executable is None:
256+
pip_install(tools_venv, "ninja")
257+
ninja_executable = os.path.join(tools_venv, "Scripts", "ninja.exe")
256258

257259
# Build standalone project and populate archive cache
258260
check_call([
@@ -268,7 +270,9 @@ def build_wheels(py_envs=DEFAULT_PY_ENVS, single_wheel=False,
268270
# Compile wheels re-using standalone project and archive cache
269271
for py_env in py_envs:
270272
tools_venv = os.path.join(ROOT_DIR, "venv-" + py_env)
271-
pip_install(tools_venv, "ninja")
273+
ninja_executable = shutil.which('ninja.exe')
274+
if ninja_executable is None:
275+
pip_install(tools_venv, "ninja")
272276
build_wheel(py_env, single_wheel=single_wheel,
273277
cleanup=cleanup, wheel_names=wheel_names,
274278
cmake_options=cmake_options)

0 commit comments

Comments
 (0)