Add bazel to the PATH in setup.py (#9590)

Co-authored-by: Mehrdad <noreply@github.com>
This commit is contained in:
mehrdadn 2020-07-21 13:35:29 -07:00 committed by GitHub
parent 4a36f72ce1
commit c5cde65bc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 7 deletions

View file

@ -6,7 +6,6 @@ ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
arg1="${1-}" arg1="${1-}"
version="3.2.0"
achitecture="${HOSTTYPE}" achitecture="${HOSTTYPE}"
platform="unknown" platform="unknown"
case "${OSTYPE}" in case "${OSTYPE}" in
@ -30,7 +29,8 @@ esac
# Sanity check: Verify we have symlinks where we expect them, or Bazel can produce weird "missing input file" errors. # Sanity check: Verify we have symlinks where we expect them, or Bazel can produce weird "missing input file" errors.
# This is most likely to occur on Windows, where symlinks are sometimes disabled by default. # This is most likely to occur on Windows, where symlinks are sometimes disabled by default.
{ git ls-files -s || true; } | { { git ls-files -s 2>/dev/null || true; } | (
set +x
missing_symlinks=() missing_symlinks=()
while read -r mode digest sn path; do while read -r mode digest sn path; do
if [ "${mode}" = 120000 ]; then if [ "${mode}" = 120000 ]; then
@ -42,8 +42,10 @@ esac
echo "For a correct build, please run 'git config --local core.symlinks true' and re-run git checkout." 1>&2 echo "For a correct build, please run 'git config --local core.symlinks true' and re-run git checkout." 1>&2
false false
fi fi
} )
python="$(command -v python3 || command -v python || echo python)"
version="$("${python}" -s -c "import runpy, sys; runpy.run_path(sys.argv.pop(), run_name='__api__')" bazel_version "${ROOT_DIR}/../../python/setup.py")"
if [ "${OSTYPE}" = "msys" ]; then if [ "${OSTYPE}" = "msys" ]; then
target="${MINGW_DIR-/usr}/bin/bazel.exe" target="${MINGW_DIR-/usr}/bin/bazel.exe"
mkdir -p "${target%/*}" mkdir -p "${target%/*}"

View file

@ -80,6 +80,7 @@ Ray can be built from the repository as follows.
git clone https://github.com/ray-project/ray.git git clone https://github.com/ray-project/ray.git
# Install Bazel. # Install Bazel.
# (Windows users: please manually place Bazel in your PATH, and point BAZEL_SH to MSYS2's Bash.)
ray/ci/travis/install-bazel.sh ray/ci/travis/install-bazel.sh
# Optionally build the dashboard # Optionally build the dashboard

View file

@ -1,6 +1,7 @@
import argparse import argparse
import glob import glob
import io import io
import logging
import os import os
import re import re
import shutil import shutil
@ -16,6 +17,8 @@ import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
logger = logging.getLogger(__name__)
# Ideally, we could include these files by putting them in a # Ideally, we could include these files by putting them in a
# MANIFEST.in or using the package_data argument to setup, but the # MANIFEST.in or using the package_data argument to setup, but the
# MANIFEST.in gets applied at the very beginning when setup.py runs # MANIFEST.in gets applied at the very beginning when setup.py runs
@ -23,6 +26,7 @@ import urllib.request
# manually. # manually.
SUPPORTED_PYTHONS = [(3, 5), (3, 6), (3, 7), (3, 8)] SUPPORTED_PYTHONS = [(3, 5), (3, 6), (3, 7), (3, 8)]
SUPPORTED_BAZEL = (3, 2, 0)
ROOT_DIR = os.path.dirname(__file__) ROOT_DIR = os.path.dirname(__file__)
BUILD_JAVA = os.getenv("RAY_INSTALL_JAVA") == "1" BUILD_JAVA = os.getenv("RAY_INSTALL_JAVA") == "1"
@ -129,6 +133,28 @@ def is_invalid_windows_platform():
return platform == "msys" or (platform == "win32" and ver and "GCC" in ver) return platform == "msys" or (platform == "win32" and ver and "GCC" in ver)
# Calls Bazel in PATH, falling back to the standard user installatation path
# (~/.bazel/bin/bazel) if it isn't found.
def bazel_invoke(invoker, cmdline, *args, **kwargs):
home = os.path.expanduser("~")
candidates = ["bazel"]
if sys.platform == "win32":
mingw_dir = os.getenv("MINGW_DIR")
if mingw_dir:
candidates.append(mingw_dir + "/bin/bazel.exe")
else:
candidates.append(os.path.join(home, ".bazel", "bin", "bazel"))
result = None
for i, cmd in enumerate(candidates):
try:
result = invoker([cmd] + cmdline, *args, **kwargs)
break
except IOError:
if i >= len(candidates) - 1:
raise
return result
def download(url): def download(url):
try: try:
result = urllib.request.urlopen(url).read() result = urllib.request.urlopen(url).read()
@ -221,12 +247,19 @@ def build(build_python, build_java):
] + pip_packages, ] + pip_packages,
env=dict(os.environ, CC="gcc")) env=dict(os.environ, CC="gcc"))
bazel = os.getenv("BAZEL_EXECUTABLE", "bazel") version_info = bazel_invoke(subprocess.check_output, ["--version"])
bazel_version_str = version_info.rstrip().decode("utf-8").split(" ", 1)[1]
bazel_version = tuple(map(int, bazel_version_str.split(".")))
if bazel_version <= SUPPORTED_BAZEL:
logger.warning("Expected Bazel version {} but found {}",
bazel_version, SUPPORTED_BAZEL)
bazel_targets = [] bazel_targets = []
bazel_targets += ["//:ray_pkg"] if build_python else [] bazel_targets += ["//:ray_pkg"] if build_python else []
bazel_targets += ["//java:ray_java_pkg"] if build_java else [] bazel_targets += ["//java:ray_java_pkg"] if build_java else []
return subprocess.check_call( return bazel_invoke(
[bazel, "build", "--verbose_failures", "--"] + bazel_targets, subprocess.check_call,
["build", "--verbose_failures", "--"] + bazel_targets,
env=bazel_env) env=bazel_env)
@ -318,7 +351,8 @@ def pip_run(build_ext):
def api_main(program, *args): def api_main(program, *args):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("command", type=str, choices=["build", "help"]) choices = ["build", "bazel_version", "help"]
parser.add_argument("command", type=str, choices=choices)
parser.add_argument( parser.add_argument(
"-l", "-l",
"--language", "--language",
@ -341,6 +375,8 @@ def api_main(program, *args):
else: else:
raise ValueError("invalid language: {!r}".format(lang)) raise ValueError("invalid language: {!r}".format(lang))
result = build(**kwargs) result = build(**kwargs)
elif parsed_args.command == "bazel_version":
print(".".join(map(str, SUPPORTED_BAZEL)))
elif parsed_args.command == "help": elif parsed_args.command == "help":
parser.print_help() parser.print_help()
else: else: