diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2017-04-27 04:47:01 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-04-27 06:13:19 -0700 |
commit | 79789dd5abe59ec525bc3bdffec82b6af8dbd0d8 (patch) | |
tree | 61d1a77f9dc8417d178e65b6c8039c273302d91a /third_party | |
parent | 95ca363c6caf5d152eef594c7fc3703a5d490070 (diff) |
Removing python_config.sh, moved functionality asking users for input to root configure moved lib checks to python_configure.bzl
Change: 154412830
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/py/python_configure.bzl | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl index d49d4c1781..460a9b5d05 100644 --- a/third_party/py/python_configure.bzl +++ b/third_party/py/python_configure.bzl @@ -6,11 +6,13 @@ * `NUMPY_INCLUDE_PATH`: Location of Numpy libraries. * `PYTHON_BIN_PATH`: location of python binary. * `PYTHON_INCLUDE_PATH`: Location of python binaries. + * `PYTHON_LIB_PATH`: Location of python libraries. """ _NUMPY_INCLUDE_PATH = "NUMPY_INCLUDE_PATH" _PYTHON_BIN_PATH = "PYTHON_BIN_PATH" _PYTHON_INCLUDE_PATH = "PYTHON_INCLUDE_PATH" +_PYTHON_LIB_PATH = "PYTHON_LIB_PATH" def _tpl(repository_ctx, tpl, substitutions={}, out=None): @@ -114,6 +116,14 @@ def _genrule(src_dir, genrule_name, command, outs): ) +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]) + if result.return_code == 1: + _python_configure_fail("Invalid python library path: %s" % python_lib) + + def _check_python_bin(repository_ctx, python_bin): """Checks the python bin path.""" cmd = '[[ -x "%s" ]] && [[ ! -d "%s" ]]' % (python_bin, python_bin) @@ -151,28 +161,51 @@ def _create_python_repository(repository_ctx): """Creates the repository containing files set up to build with Python.""" python_include = None numpy_include = None + empty_config = False # If local checks were requested, the python and numpy include will be auto # detected on the host config (using _PYTHON_BIN_PATH). if repository_ctx.attr.local_checks: python_bin = _get_env_var(repository_ctx, _PYTHON_BIN_PATH) _check_python_bin(repository_ctx, python_bin) - python_include = _get_python_include(repository_ctx, python_bin) - numpy_include = _get_numpy_include(repository_ctx, python_bin) + '/numpy' + python_lib = _get_env_var(repository_ctx, _PYTHON_LIB_PATH, '') + if python_lib == '': + # If we could not find the python lib we will create an empty config that + # will allow non-compilation targets to build correctly (e.g., smoke + # tests). + empty_config = True + _python_configure_warning('PYTHON_LIB_PATH was not set;' + + ' python setup cannot complete successfully.' + + ' Please run ./configure.') + else: + _check_python_lib(repository_ctx, python_lib) + python_include = _get_python_include(repository_ctx, python_bin) + numpy_include = _get_numpy_include(repository_ctx, python_bin) + '/numpy' else: # Otherwise, we assume user provides all paths (via ENV or attrs) python_include = _get_env_var(repository_ctx, _PYTHON_INCLUDE_PATH, repository_ctx.attr.python_include) numpy_include = _get_env_var(repository_ctx, _NUMPY_INCLUDE_PATH, repository_ctx.attr.numpy_include) + '/numpy' - - python_include_rule = _symlink_genrule_for_dir( - repository_ctx, python_include, 'python_include', 'python_include') - numpy_include_rule = _symlink_genrule_for_dir( - repository_ctx, numpy_include, 'numpy_include/numpy', 'numpy_include') - _tpl(repository_ctx, "BUILD", { - "%{PYTHON_INCLUDE_GENRULE}": python_include_rule, - "%{NUMPY_INCLUDE_GENRULE}": numpy_include_rule, - }) + if empty_config: + _tpl(repository_ctx, "BUILD", { + "%{PYTHON_INCLUDE_GENRULE}": ('filegroup(\n' + + ' name = "python_include",\n' + + ' srcs = [],\n' + + ')\n'), + "%{NUMPY_INCLUDE_GENRULE}": ('filegroup(\n' + + ' name = "numpy_include",\n' + + ' srcs = [],\n' + + ')\n'), + }) + else: + python_include_rule = _symlink_genrule_for_dir( + repository_ctx, python_include, 'python_include', 'python_include') + numpy_include_rule = _symlink_genrule_for_dir( + repository_ctx, numpy_include, 'numpy_include/numpy', 'numpy_include') + _tpl(repository_ctx, "BUILD", { + "%{PYTHON_INCLUDE_GENRULE}": python_include_rule, + "%{NUMPY_INCLUDE_GENRULE}": numpy_include_rule, + }) def _python_autoconf_impl(repository_ctx): @@ -190,6 +223,7 @@ python_configure = repository_rule( environ = [ _PYTHON_BIN_PATH, _PYTHON_INCLUDE_PATH, + _PYTHON_LIB_PATH, _NUMPY_INCLUDE_PATH, ], ) |