Skip to content

Commit

Permalink
Update to bazel-0.18.0 and use try-import
Browse files Browse the repository at this point in the history
Bazel-0.18.0 adds a try-import option that will non-fatally try and
import a file. Use this for the configure options so that .bazelrc does
not need to change. ./configure rewriting .bazelrc makes using the git
repo annoying because the file is changed.

The allowed bazel range is now 0.18.0-0.20.0 inclusive. The env var
TF_IGNORE_MAX_BAZEL_VERSION can be set to skip the max bazel version
check.

Also optionally import a /.bazelrc.user file that is gitignored so
user-specific options can go in there.

Fixes: tensorflow#22762
Fixes: tensorflow#22906
Signed-off-by: Jason Zaman <[email protected]>
  • Loading branch information
perfinion committed Dec 5, 2018
1 parent 43a1df9 commit b41761c
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 26 deletions.
8 changes: 8 additions & 0 deletions tools/bazel.rc → .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ build:dynamic_kernels --copt=-DAUTOLOAD_DYNAMIC_KERNELS
build --define=PREFIX=/usr
build --define=LIBDIR=$(PREFIX)/lib
build --define=INCLUDEDIR=$(PREFIX)/include

# Default options should come above this line

# Options from ./configure
try-import %workspace%/.tf_configure.bazelrc

# Put user-specific options in .bazelrc.user
try-import %workspace%/.bazelrc.user
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
.ipynb_checkpoints
node_modules
/.bazelrc
/.bazelrc.user
/.tf_configure.bazelrc
/bazel-*
/bazel_pip
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ remote_config_workspace()
# files, in case the parsing of those build files depends on the bazel
# version we require here.
load("//tensorflow:version_check.bzl", "check_bazel_version_at_least")
check_bazel_version_at_least("0.15.0")
check_bazel_version_at_least("0.18.0")

load("//tensorflow:workspace.bzl", "tf_workspace")

Expand Down
22 changes: 4 additions & 18 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,6 @@ def setup_python(environ_cp):
def reset_tf_configure_bazelrc():
"""Reset file that contains customized config settings."""
open(_TF_BAZELRC, 'w').close()
bazelrc_path = os.path.join(_TF_WORKSPACE_ROOT, '.bazelrc')

data = []
if os.path.exists(bazelrc_path):
with open(bazelrc_path, 'r') as f:
data = f.read().splitlines()
with open(bazelrc_path, 'w') as f:
for l in data:
if _TF_BAZELRC_FILENAME in l:
continue
f.write('%s\n' % l)
f.write('import %%workspace%%/%s\n' % _TF_BAZELRC_FILENAME)

def cleanup_makefile():
"""Delete any leftover BUILD files from the Makefile build.
Expand Down Expand Up @@ -488,11 +476,11 @@ def check_bazel_version(min_version, max_version):
if curr_version_int < min_version_int:
print('Please upgrade your bazel installation to version %s or higher to '
'build TensorFlow!' % min_version)
sys.exit(0)
if curr_version_int > max_version_int:
sys.exit(1)
if curr_version_int > max_version_int and not 'TF_IGNORE_MAX_BAZEL_VERSION' in os.environ:
print('Please downgrade your bazel installation to version %s or lower to '
'build TensorFlow!' % max_version)
sys.exit(0)
sys.exit(1)
return curr_version


Expand Down Expand Up @@ -1565,11 +1553,9 @@ def main():
# environment variables.
environ_cp = dict(os.environ)

check_bazel_version('0.15.0', '0.20.0')
check_bazel_version('0.18.0', '0.20.0')

reset_tf_configure_bazelrc()
# Explicitly import tools/bazel.rc, this is needed for Bazel 0.19.0 or later
write_to_bazelrc('import %workspace%/tools/bazel.rc')

cleanup_makefile()
setup_python(environ_cp)
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/tools/ci_build/install/install_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# ==============================================================================

# Select bazel version.
BAZEL_VERSION="0.15.0"
BAZEL_VERSION="0.18.0"

set +e
local_bazel_ver=$(bazel version 2>&1 | grep -i label | awk '{print $3}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# It will compile bazel from source and install it in /usr/local/bin

# Select bazel version.
BAZEL_VERSION="0.15.0"
BAZEL_VERSION="0.18.0"

set +e
local_bazel_ver=$(bazel version 2>&1 | grep -i label | awk '{print $3}')
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/tools/docker/Dockerfile.devel
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ RUN echo "startup --batch" >>/etc/bazel.bazelrc
RUN echo "build --spawn_strategy=standalone --genrule_strategy=standalone" \
>>/etc/bazel.bazelrc
# Install the most recent bazel release.
ENV BAZEL_VERSION 0.15.0
ENV BAZEL_VERSION 0.18.0
WORKDIR /
RUN mkdir /bazel && \
cd /bazel && \
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/tools/docker/Dockerfile.devel-gpu
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ RUN echo "startup --batch" >>/etc/bazel.bazelrc
RUN echo "build --spawn_strategy=standalone --genrule_strategy=standalone" \
>>/etc/bazel.bazelrc
# Install the most recent bazel release.
ENV BAZEL_VERSION 0.15.0
ENV BAZEL_VERSION 0.18.0
WORKDIR /
RUN mkdir /bazel && \
cd /bazel && \
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/tools/docker/Dockerfile.devel-mkl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ RUN echo "startup --batch" >>/etc/bazel.bazelrc
RUN echo "build --spawn_strategy=standalone --genrule_strategy=standalone" \
>>/etc/bazel.bazelrc
# Install the most recent bazel release.
ENV BAZEL_VERSION 0.15.0
ENV BAZEL_VERSION 0.18.0
WORKDIR /
RUN mkdir /bazel && \
cd /bazel && \
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/tools/docker/Dockerfile.devel-mkl-horovod
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ RUN echo "startup --batch" >>/etc/bazel.bazelrc
RUN echo "build --spawn_strategy=standalone --genrule_strategy=standalone" \
>>/etc/bazel.bazelrc
# Install the most recent bazel release.
ENV BAZEL_VERSION 0.15.0
ENV BAZEL_VERSION 0.18.0
WORKDIR /
RUN mkdir /bazel && \
cd /bazel && \
Expand Down

0 comments on commit b41761c

Please sign in to comment.