* Add python 3 only support for bazel build
When building tensorflow in a python3 system (i.e.,
only `/usr/bin/python3`, no `/usr/bin/python`), even
though `/usr/bin/python3` is specified during the configure
the following failure still occur:
```
SUBCOMMAND: # //tensorflow/core:version_info_gen [action 'Executing genrule //tensorflow/core:version_info_gen [for host]']
(cd /home/ubuntu/.cache/bazel/_bazel_ubuntu/
ad1e09741bb4109fbc70ef8216b59ee2/execroot/org_tensorflow && \
exec env - \
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; tensorflow/tools/git/gen_git_source.py --generate external/local_config_git/gen/spec.json external/local_config_git/gen/head external/local_config_git/gen/branch_ref "bazel-out/host/genfiles/tensorflow/core/util/version_info.cc" --git_tag_override=${GIT_TAG_OVERRIDE:-}')
ERROR: /home/ubuntu/tensorflow/tensorflow/core/BUILD:2015:1: Executing genrule //tensorflow/core:version_info_gen failed (Exit 127)
/usr/bin/env: 'python': No such file or directory
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/ubuntu/tensorflow/tensorflow/tools/api/generator/BUILD:27:1 Executing genrule //tensorflow/core:version_info_gen failed (Exit 127)
INFO: Elapsed time: 391.217s, Critical Path: 46.74s
INFO: 656 processes, local.
FAILED: Build did NOT complete successfully
```
This fix adds the necessary `${PYTHON_BIN_PATH}` (configured already in `./configure`)
into related commands so that bazel build works even in python 3 only environment.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Fix build failure for api generator in python 3 only environment
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Add `${PYTHON_BIN_PATH}` to cython build
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Optionally add PYTHON_BIN_PATH for non-windows only
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
name = filename + "_cython_translation",
srcs = [filename],
outs = [filename.split(".")[0] + ".cpp"],
- cmd = "PYTHONHASHSEED=0 $(location @cython//:cython_binary) --cplus $(SRCS) --output-file $(OUTS)",
+ # Optionally use PYTHON_BIN_PATH on Linux platforms so that python 3
+ # works. Windows has issues with cython_binary so skip PYTHON_BIN_PATH.
+ cmd = "PYTHONHASHSEED=0 " + select({
+ "@bazel_tools//src/conditions:windows": "",
+ "//conditions:default": "$${PYTHON_BIN_PATH} ",
+ }) + "$(location @cython//:cython_binary) --cplus $(SRCS) --output-file $(OUTS)",
tools = ["@cython//:cython_binary"] + pxd_srcs,
)
],
outs=["util/version_info.cc"],
cmd=
- "$(location //tensorflow/tools/git:gen_git_source.py) --generate $(SRCS) \"$@\" --git_tag_override=$${GIT_TAG_OVERRIDE:-}",
+ "$${PYTHON_BIN_PATH} $(location //tensorflow/tools/git:gen_git_source.py) --generate $(SRCS) \"$@\" --git_tag_override=$${GIT_TAG_OVERRIDE:-}",
local=1,
tools=[clean_dep("//tensorflow/tools/git:gen_git_source.py")],)
name="py_build_info_gen",
outs=["platform/build_info.py"],
cmd=
- "$(location //tensorflow/tools/build_info:gen_build_info.py) --raw_generate \"$@\" --build_config " + if_cuda("cuda", "cpu"),
+ "$${PYTHON_BIN_PATH} $(location //tensorflow/tools/build_info:gen_build_info.py) --raw_generate \"$@\" --build_config " + if_cuda("cuda", "cpu"),
local=1,
tools=[clean_dep("//tensorflow/tools/build_info:gen_build_info.py")],)
"api/user_ops/__init__.py",
# END GENERATED FILES
],
- cmd = "$(location create_python_api) $(OUTS)",
+ # Optionally use PYTHON_BIN_PATH on Linux platforms so that python 3
+ # works. Windows has issues with the command so skip PYTHON_BIN_PATH
+ # for now.
+ cmd = select({
+ "@bazel_tools//src/conditions:windows": "",
+ "//conditions:default": "$${PYTHON_BIN_PATH} ",
+ }) + "$(location create_python_api) $(OUTS)",
tools = ["create_python_api"],
)