aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/py
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2018-05-29 05:05:08 +0200
committerGravatar Gunhan Gulsoy <gunan@google.com>2018-05-28 20:05:08 -0700
commit694892d4c0fba6bd4322e943f8b1483b36f1ae99 (patch)
tree9cee4d0a3d509dace6446e31009b84bfeca5e89b /third_party/py
parenteadfa07685bfcc0c79d6ae8bf7bccae33eedff0d (diff)
python_configure.bzl: Find bash binary path through BAZEL_SH env var. (#19598)
* python_configure.bzl: Find bash binary path through BAZEL_SH env var. This helps avoid invoking the wrong bash binary when "Bash on Ubuntu on Windows" is installed. Fixed https://github.com/tensorflow/tensorflow/issues/11735 * Readability modifications.
Diffstat (limited to 'third_party/py')
-rw-r--r--third_party/py/python_configure.bzl23
1 files changed, 20 insertions, 3 deletions
diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl
index 954f21f5f8..0c98d5d134 100644
--- a/third_party/py/python_configure.bzl
+++ b/third_party/py/python_configure.bzl
@@ -6,6 +6,7 @@
* `PYTHON_LIB_PATH`: Location of python libraries.
"""
+_BAZEL_SH = "BAZEL_SH"
_PYTHON_BIN_PATH = "PYTHON_BIN_PATH"
_PYTHON_LIB_PATH = "PYTHON_LIB_PATH"
_TF_PYTHON_CONFIG_REPO = "TF_PYTHON_CONFIG_REPO"
@@ -152,6 +153,22 @@ def _get_python_bin(repository_ctx):
_PYTHON_BIN_PATH, repository_ctx.os.environ.get("PATH", "")))
+def _get_bash_bin(repository_ctx):
+ """Gets the bash bin path."""
+ bash_bin = repository_ctx.os.environ.get(_BAZEL_SH)
+ if bash_bin != None:
+ return bash_bin
+ else:
+ bash_bin_path = repository_ctx.which("bash")
+ if bash_bin_path != None:
+ return str(bash_bin_path)
+ else:
+ _fail("Cannot find bash in PATH, please make sure " +
+ "bash is installed and add its directory in PATH, or --define " +
+ "%s='/path/to/bash'.\nPATH=%s" % (
+ _BAZEL_SH, repository_ctx.os.environ.get("PATH", "")))
+
+
def _get_python_lib(repository_ctx, python_bin):
"""Gets the python lib path."""
python_lib = repository_ctx.os.environ.get(_PYTHON_LIB_PATH)
@@ -184,14 +201,14 @@ def _get_python_lib(repository_ctx, python_bin):
" print(paths[0])\n" +
"END")
cmd = '%s - %s' % (python_bin, print_lib)
- result = repository_ctx.execute(["bash", "-c", cmd])
+ result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd])
return result.stdout.strip('\n')
def _check_python_lib(repository_ctx, python_lib):
"""Checks the python lib path."""
cmd = 'test -d "%s" -a -x "%s"' % (python_lib, python_lib)
- result = repository_ctx.execute(["bash", "-c", cmd])
+ result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd])
if result.return_code == 1:
_fail("Invalid python library path: %s" % python_lib)
@@ -199,7 +216,7 @@ def _check_python_lib(repository_ctx, python_lib):
def _check_python_bin(repository_ctx, python_bin):
"""Checks the python bin path."""
cmd = '[[ -x "%s" ]] && [[ ! -d "%s" ]]' % (python_bin, python_bin)
- result = repository_ctx.execute(["bash", "-c", cmd])
+ result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd])
if result.return_code == 1:
_fail("--define %s='%s' is not executable. Is it the python binary?" % (
_PYTHON_BIN_PATH, python_bin))