aboutsummaryrefslogtreecommitdiffhomepage
path: root/util
diff options
context:
space:
mode:
authorGravatar Shanqing Cai <cais@google.com>2017-04-20 10:42:44 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-04-20 12:05:32 -0700
commit3a39b41b975ce4c508b566d316514b2181e2e166 (patch)
tree7ace7a0655806ad373d3bae37b988f204c6160e2 /util
parent92bf4b39274d6da59ddf710f5ef5be2e9039a99e (diff)
Automated rollback of change 153709951
Change: 153736477
Diffstat (limited to 'util')
-rw-r--r--util/python/BUILD28
-rwxr-xr-xutil/python/python_config.sh76
2 files changed, 97 insertions, 7 deletions
diff --git a/util/python/BUILD b/util/python/BUILD
index 96daf9947a..29688b875d 100644
--- a/util/python/BUILD
+++ b/util/python/BUILD
@@ -2,7 +2,31 @@ licenses(["restricted"])
package(default_visibility = ["//visibility:public"])
-alias(
+cc_library(
name = "python_headers",
- actual = "@local_config_python//:python_headers",
+ hdrs = glob([
+ "python_include/**/*.h",
+ ]),
+ data = [":python_checked"],
+ includes = ["python_include"],
+)
+
+genrule(
+ name = "python_check",
+ srcs = [
+ "python_config.sh",
+ "configure_files",
+ ],
+ outs = [
+ "python_checked",
+ ],
+ cmd = "OUTPUTDIR=\"$(@D)/\"; $(location :python_config.sh) --check && touch $$OUTPUTDIR/python_checked",
+ local = 1,
+)
+
+filegroup(
+ name = "configure_files",
+ data = glob([
+ "*",
+ ]),
)
diff --git a/util/python/python_config.sh b/util/python/python_config.sh
index d5762ad456..4b18bf3578 100755
--- a/util/python/python_config.sh
+++ b/util/python/python_config.sh
@@ -26,9 +26,23 @@ else
script_path=${script_path:-.}
fi
+EXPECTED_PATHS="$script_path/util/python/python_include"\
+" $script_path/util/python/python_lib"\
+" $script_path/third_party/py/numpy/numpy_include"
+
function main {
- setup_python "$1"
- exit 0
+ argument="$1"
+ shift
+ case $argument in
+ --check)
+ check_python
+ exit 0
+ ;;
+ --setup)
+ setup_python "$1"
+ exit 0
+ ;;
+ esac
}
function python_path {
@@ -79,7 +93,6 @@ END
function setup_python {
PYTHON_BIN_PATH="$1";
- # TODO(ngiraldo): move most of these checks to root configure
if [ -z "$PYTHON_BIN_PATH" ]; then
echo "PYTHON_BIN_PATH was not provided. Did you run configure?"
exit 1
@@ -95,7 +108,12 @@ function setup_python {
exit 1
fi
- # TODO(ngiraldo): confirm if these checks are really necessary, remove if not
+ local python_include="$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_inc());')"
+ if [ "$python_include" == "" ]; then
+ echo -e "\n\nERROR: Problem getting python include path. Is distutils installed?"
+ exit 1
+ fi
+
if [ -z "$PYTHON_LIB_PATH" ]; then
local python_lib_path
# Split python_path into an array of paths, this allows path containing spaces
@@ -131,12 +149,35 @@ function setup_python {
exit 1
fi
+ local numpy_include=$("${PYTHON_BIN_PATH}" -c 'from __future__ import print_function; import numpy; print(numpy.get_include());')
+ if [ "$numpy_include" == "" ]; then
+ echo -e "\n\nERROR: Problem getting numpy include path. Is numpy installed?"
+ exit 1
+ fi
+
+ for x in $EXPECTED_PATHS; do
+ if [ -e "$x" ]; then
+ rm -rf "$x"
+ fi
+ done
+
+# ln -sf is actually implemented as copying in msys since creating symbolic
+# links is privileged on Windows. But copying is too slow, so invoke mklink
+# to create junctions on Windows.
+ if is_windows; then
+ cmd /c "mklink /J util\\python\\python_include \"${python_include}\""
+ cmd /c "mklink /J util\\python\\python_lib \"${python_lib}\""
+ cmd /c "mklink /J third_party\\py\\numpy\\numpy_include \"${numpy_include}\""
+ else
+ ln -sf "${python_include}" util/python/python_include
+ ln -sf "${python_lib}" util/python/python_lib
+ ln -sf "${numpy_include}" third_party/py/numpy/numpy_include
+ 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
- # TODO(ngiraldo): move all below to root configure
# Write tools/bazel.rc
echo "# Autogenerated by configure: DO NOT EDIT" > tools/bazel.rc
sed -e "s/\$PYTHON_MAJOR_VERSION/$python_major_version/g" \
@@ -156,4 +197,29 @@ function is_windows() {
fi
}
+function check_python {
+ for x in $EXPECTED_PATHS; do
+ if [ ! -e "$x" ]; then
+ echo -e "\n\nERROR: Cannot find '${x}'. Did you run configure?\n\n" 1>&2
+ exit 1
+ fi
+ # Don't check symbolic link on Windows
+ if ! is_windows && [ ! -L "${x}" ]; then
+ echo -e "\n\nERROR: '${x}' is not a symbolic link. Internal error.\n\n" 1>&2
+ exit 1
+ fi
+ if is_windows; then
+ # In msys, readlink <path> doesn't work, because no symbolic link on
+ # Windows. readlink -f <path> returns the real path of a junction.
+ true_path=$(readlink -f "${x}")
+ else
+ true_path=$(readlink "${x}")
+ fi
+ if [ ! -d "${true_path}" ]; then
+ echo -e "\n\nERROR: '${x}' does not refer to an existing directory: ${true_path}. Do you need to rerun configure?\n\n" 1>&2
+ exit 1
+ fi
+ done
+}
+
main "$@"