Replace distutils.spawn.find_executable

It's not always available on Windows apparently.
This commit is contained in:
mpeterv 2016-03-20 20:30:17 +03:00
parent f4139453df
commit 721b2c467b

View File

@ -5,7 +5,6 @@
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import distutils
import os import os
import re import re
import shutil import shutil
@ -28,9 +27,33 @@ __all__ = ["main"]
opts = None opts = None
temp_dir = None temp_dir = None
def is_executable(path):
return (os.path.exists(path) and
os.access(path, os.F_OK | os.X_OK) and
not os.path.isdir(path))
def program_exists(prog):
path = os.environ.get("PATH", os.defpath)
if not path:
return False
if os.name == "nt":
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
candidates = [prog + ext for ext in pathext]
else:
candidates = [prog]
for directory in path.split(os.pathsep):
for candidate in candidates:
if is_executable(os.path.join(directory, candidate)):
return True
return False
platform_to_lua_target = { platform_to_lua_target = {
"linux": "linux", "linux": "linux",
"win": "cl" if os.name == "nt" and distutils.spawn.find_executable("cl") else "mingw", "win": "cl" if os.name == "nt" and program_exists("cl") else "mingw",
"darwin": "macosx", "darwin": "macosx",
"freebsd": "freebsd" "freebsd": "freebsd"
} }
@ -50,7 +73,6 @@ def get_default_cache():
else: else:
return os.path.join(os.getenv("HOME"), ".cache", "hererocks") return os.path.join(os.getenv("HOME"), ".cache", "hererocks")
def quote(command_arg): def quote(command_arg):
return "'" + command_arg.replace("'", "'\"'\"'") + "'" return "'" + command_arg.replace("'", "'\"'\"'") + "'"
@ -691,7 +713,7 @@ class LuaJIT(Lua):
else: else:
make = "mingw32-make" if ( make = "mingw32-make" if (
opts.target == "mingw" and opts.target == "mingw" and
distutils.spawn.find_executable("mingw32-make")) else "make" program_exists("mingw32-make")) else "make"
run_command(make if opts.cflags is None else make + " XCFLAGS=" + quote(opts.cflags)) run_command(make if opts.cflags is None else make + " XCFLAGS=" + quote(opts.cflags))
def make_install(self): def make_install(self):