From 79789dd5abe59ec525bc3bdffec82b6af8dbd0d8 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 27 Apr 2017 04:47:01 -0800 Subject: Removing python_config.sh, moved functionality asking users for input to root configure moved lib checks to python_configure.bzl Change: 154412830 --- configure | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 27 deletions(-) (limited to 'configure') diff --git a/configure b/configure index fad3fdbebd..75d3e160f5 100755 --- a/configure +++ b/configure @@ -51,6 +51,121 @@ function write_action_env_to_bazelrc() { write_to_bazelrc "build --action_env $1=\"$2\"" } +function python_path { + "$PYTHON_BIN_PATH" - <&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 -- cgit v1.2.3