Skip to content
Permalink
Browse files

Update to bazel-0.18.0 and use try-import

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: #22762
Fixes: #22906
Signed-off-by: Jason Zaman <jason@perfinion.com>
  • Loading branch information...
perfinion committed Oct 14, 2018
1 parent 43a1df9 commit b41761c499a5081870b9da4a8ae73adc45df269a
@@ -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
@@ -1,7 +1,7 @@
.DS_Store
.ipynb_checkpoints
node_modules
/.bazelrc
/.bazelrc.user
/.tf_configure.bazelrc
/bazel-*
/bazel_pip
@@ -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")

@@ -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.
@@ -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


@@ -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)
@@ -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}')
@@ -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}')
@@ -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 && \
@@ -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 && \
@@ -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 && \
@@ -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 && \

0 comments on commit b41761c

Please sign in to comment.
You can’t perform that action at this time.