diff options
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 143 |
1 files changed, 116 insertions, 27 deletions
@@ -51,6 +51,121 @@ function write_action_env_to_bazelrc() { write_to_bazelrc "build --action_env $1=\"$2\"" } +function python_path { + "$PYTHON_BIN_PATH" - <<END +from __future__ import print_function +import site +import os + +try: + input = raw_input +except NameError: + pass + +python_paths = [] +if os.getenv('PYTHONPATH') is not None: + python_paths = os.getenv('PYTHONPATH').split(':') +try: + library_paths = site.getsitepackages() +except AttributeError: + from distutils.sysconfig import get_python_lib + library_paths = [get_python_lib()] +all_paths = set(python_paths + library_paths) + +paths = [] +for path in all_paths: + if os.path.isdir(path): + paths.append(path) + +print(",".join(paths)) +END +} + +function setup_python { + ## Set up python-related environment settings: + while true; do + fromuser="" + if [ -z "$PYTHON_BIN_PATH" ]; then + default_python_bin_path=$(which python || which python3 || true) + read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH + fromuser="1" + if [ -z "$PYTHON_BIN_PATH" ]; then + PYTHON_BIN_PATH=$default_python_bin_path + fi + fi + if [ -e "$PYTHON_BIN_PATH" ]; then + break + fi + echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2 + if [ -z "$fromuser" ]; then + exit 1 + fi + PYTHON_BIN_PATH="" + # Retry + done + + if [ -z "$PYTHON_LIB_PATH" ]; then + # Split python_path into an array of paths, this allows path containing spaces + IFS=',' + python_lib_path=($(python_path)) + unset IFS + + if [ 1 = "$USE_DEFAULT_PYTHON_LIB_PATH" ]; then + PYTHON_LIB_PATH=${python_lib_path[0]} + echo "Using python library path: $PYTHON_LIB_PATH" + + else + echo "Found possible Python library paths:" + for x in "${python_lib_path[@]}"; do + echo " $x" + done + set -- "${python_lib_path[@]}" + echo "Please input the desired Python library path to use. Default is ["$1"]" + read b || true + if [ "$b" == "" ]; then + PYTHON_LIB_PATH=${python_lib_path[0]} + echo "Using python library path: $PYTHON_LIB_PATH" + else + PYTHON_LIB_PATH="$b" + fi + fi + fi + + if [ ! -x "$PYTHON_BIN_PATH" ] || [ -d "$PYTHON_BIN_PATH" ]; then + echo "PYTHON_BIN_PATH is not executable. Is it the python binary?" + exit 1 + fi + + local python_major_version=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import sys; print(sys.version_info[0]);') + if [ "$python_major_version" == "" ]; then + echo -e "\n\nERROR: Problem getting python version. Is $PYTHON_BIN_PATH the correct python binary?" + exit 1 + fi + + # Convert python path to Windows style before writing into bazel.rc + if is_windows; then + PYTHON_BIN_PATH="$(cygpath -m "$PYTHON_BIN_PATH")" + fi + + # Set-up env variables used by python_configure.bzl + write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH" + write_action_env_to_bazelrc "PYTHON_LIB_PATH" "$PYTHON_LIB_PATH" + write_to_bazelrc "build --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH" + write_to_bazelrc "build --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH" + write_to_bazelrc "build --force_python=py$python_major_version" + write_to_bazelrc "build --host_force_python=py$python_major_version" + write_to_bazelrc "build --python${python_major_version}_path=$PYTHON_BIN_PATH" + write_to_bazelrc "test --force_python=py$python_major_version" + write_to_bazelrc "test --host_force_python=py$python_major_version" + write_to_bazelrc "test --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH" + write_to_bazelrc "test --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH" + write_to_bazelrc "run --define PYTHON_BIN_PATH=$PYTHON_BIN_PATH" + write_to_bazelrc "run --define PYTHON_LIB_PATH=$PYTHON_LIB_PATH" + + # Write tools/python_bin_path.sh + echo "export PYTHON_BIN_PATH=\"$PYTHON_BIN_PATH\"" > tools/python_bin_path.sh +} + # This file contains customized config settings. rm -f .tf_configure.bazelrc touch .tf_configure.bazelrc @@ -65,30 +180,7 @@ if [ -d "${MAKEFILE_DOWNLOAD_DIR}" ]; then find ${MAKEFILE_DOWNLOAD_DIR} -type f -name '*BUILD' -delete fi -## Set up python-related environment settings -while true; do - fromuser="" - if [ -z "$PYTHON_BIN_PATH" ]; then - default_python_bin_path=$(which python || which python3 || true) - read -p "Please specify the location of python. [Default is $default_python_bin_path]: " PYTHON_BIN_PATH - fromuser="1" - if [ -z "$PYTHON_BIN_PATH" ]; then - PYTHON_BIN_PATH=$default_python_bin_path - fi - fi - if [ -e "$PYTHON_BIN_PATH" ]; then - break - fi - echo "Invalid python path. ${PYTHON_BIN_PATH} cannot be found" 1>&2 - if [ -z "$fromuser" ]; then - exit 1 - fi - PYTHON_BIN_PATH="" - # Retry -done -export PYTHON_BIN_PATH -write_action_env_to_bazelrc "PYTHON_BIN_PATH" "$PYTHON_BIN_PATH" -# TODO(ngiraldo): allow the user to optionally set PYTHON_INCLUDE_PATH and NUMPY_INCLUDE_PATH +setup_python ## Set up MKL related environment settings if false; then # Disable building with MKL for now @@ -263,9 +355,6 @@ if [[ "$TF_NEED_VERBS" == "1" ]]; then write_to_bazelrc 'build --define with_verbs_support=true' fi -# Invoke python_config and set up symlinks to python includes -./util/python/python_config.sh "$PYTHON_BIN_PATH" - # Append CC optimization flags to bazel.rc echo >> tools/bazel.rc for opt in $CC_OPT_FLAGS; do |