Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ci/travis/install-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)

arg1="${1-}"

version="3.2.0"
achitecture="${HOSTTYPE}"
platform="unknown"
case "${OSTYPE}" in
Expand All @@ -30,7 +29,8 @@ esac

# 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.
{ git ls-files -s || true; } | {
{ git ls-files -s 2>/dev/null || true; } | (
set +x
missing_symlinks=()
while read -r mode digest sn path; do
if [ "${mode}" = 120000 ]; then
Expand All @@ -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
false
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
target="${MINGW_DIR-/usr}/bin/bazel.exe"
mkdir -p "${target%/*}"
Expand Down
1 change: 1 addition & 0 deletions doc/source/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Ray can be built from the repository as follows.
git clone https://github.com/ray-project/ray.git

# 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

# Optionally build the dashboard
Expand Down
44 changes: 40 additions & 4 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import glob
import io
import logging
import os
import re
import shutil
Expand All @@ -16,13 +17,16 @@
import urllib.parse
import urllib.request

logger = logging.getLogger(__name__)

# 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 gets applied at the very beginning when setup.py runs
# before these files have been created, so we have to move the files
# manually.

SUPPORTED_PYTHONS = [(3, 5), (3, 6), (3, 7), (3, 8)]
SUPPORTED_BAZEL = (3, 2, 0)

ROOT_DIR = os.path.dirname(__file__)
BUILD_JAVA = os.getenv("RAY_INSTALL_JAVA") == "1"
Expand Down Expand Up @@ -129,6 +133,28 @@ def is_invalid_windows_platform():
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):
try:
result = urllib.request.urlopen(url).read()
Expand Down Expand Up @@ -221,12 +247,19 @@ def build(build_python, build_java):
] + pip_packages,
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 += ["//:ray_pkg"] if build_python else []
bazel_targets += ["//java:ray_java_pkg"] if build_java else []
return subprocess.check_call(
[bazel, "build", "--verbose_failures", "--"] + bazel_targets,
return bazel_invoke(
subprocess.check_call,
["build", "--verbose_failures", "--"] + bazel_targets,
env=bazel_env)


Expand Down Expand Up @@ -318,7 +351,8 @@ def pip_run(build_ext):

def api_main(program, *args):
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(
"-l",
"--language",
Expand All @@ -341,6 +375,8 @@ def api_main(program, *args):
else:
raise ValueError("invalid language: {!r}".format(lang))
result = build(**kwargs)
elif parsed_args.command == "bazel_version":
print(".".join(map(str, SUPPORTED_BAZEL)))
elif parsed_args.command == "help":
parser.print_help()
else:
Expand Down