|
| 1 | + |
| 2 | + #! /bin/bash |
| 3 | + |
| 4 | +# ============================================================================== |
| 5 | +# Copyright 2018 Intel Corporation |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# ============================================================================== |
| 19 | + |
| 20 | +# This script is designed to be called from within a docker container. |
| 21 | +# It is installed into a docker image. It will not run outside the container. |
| 22 | + |
| 23 | +set -e # Make sure we exit on any command that returns non-zero |
| 24 | +set -u # No unset variables |
| 25 | +set -o pipefail # Make sure cmds in pipe that are non-zero also fail immediately |
| 26 | + |
| 27 | +# Set up some important known directories |
| 28 | +bridge_dir='/home/dockuser/ngraph-tf' |
| 29 | +bbuild_dir="${bridge_dir}/build" |
| 30 | +tf_dir="${bbuild_dir}/tensorflow" |
| 31 | +ci_dir="${bridge_dir}/test/ci/docker" |
| 32 | +venv_dir="/tmp/venv_code_check" |
| 33 | +ngraph_wheel_dir="${bbuild_dir}" |
| 34 | + |
| 35 | +# HOME is expected to be /home/dockuser. See script run-as-user.sh, which |
| 36 | +# sets this up. |
| 37 | + |
| 38 | +echo "In $(basename ${0}):" |
| 39 | +echo '' |
| 40 | +echo " bridge_dir=${bridge_dir}" |
| 41 | +echo " bbuild_dir=${bbuild_dir}" |
| 42 | +echo " tf_dir=${tf_dir}" |
| 43 | +echo " ci_dir=${ci_dir}" |
| 44 | +echo " venv_dir=${venv_dir}" |
| 45 | +echo " ngraph_wheel_dir=${ngraph_wheel_dir}" |
| 46 | +echo '' |
| 47 | +echo " HOME=${HOME}" |
| 48 | + |
| 49 | +# Do some up-front checks, to make sure necessary directories are in-place and |
| 50 | +# build directories are not-in-place |
| 51 | + |
| 52 | +if [ -d "${bbuild_dir}" ] ; then |
| 53 | + ( >&2 echo '***** Error: *****' ) |
| 54 | + ( >&2 echo "Bridge build directory already exists -- please remove it before calling this script: ${bbuild_dir}" ) |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +if [ -d "${venv_dir}" ] ; then |
| 59 | + ( >&2 echo '***** Error: *****' ) |
| 60 | + ( >&2 echo "Virtual-env build directory already exists -- please remove it before calling this script: ${venv_dir}" ) |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +# Make sure the Bazel cache is in /tmp, as docker images have too little space |
| 65 | +# in the root filesystem, where /home (and $HOME/.cache) is. Even though we |
| 66 | +# may not be using the Bazel cache in the builds (in docker), we do this anyway |
| 67 | +# in case we decide to turn the Bazel cache back on. |
| 68 | +echo "Adjusting bazel cache to be located in /tmp/bazel-cache" |
| 69 | +rm -fr "$HOME/.cache" |
| 70 | +mkdir /tmp/bazel-cache |
| 71 | +ln -s /tmp/bazel-cache "$HOME/.cache" |
| 72 | + |
| 73 | +xtime="$(date)" |
| 74 | +echo ' ' |
| 75 | +echo "===== Checking gcc, python and OS version at ${xtime} =====" |
| 76 | +echo ' ' |
| 77 | + |
| 78 | +echo 'gcc is being run from:' |
| 79 | +which gcc |
| 80 | + |
| 81 | +echo ' ' |
| 82 | +echo 'gcc verison is:' |
| 83 | +gcc --version |
| 84 | + |
| 85 | +echo 'g++ is being run from:' |
| 86 | +which g++ |
| 87 | + |
| 88 | +echo ' ' |
| 89 | +echo 'g++ version is:' |
| 90 | +g++ --version |
| 91 | + |
| 92 | +echo ' ' |
| 93 | +echo 'python version is:' |
| 94 | +python --version |
| 95 | + |
| 96 | +echo ' ' |
| 97 | +echo 'python2 version is:' |
| 98 | +python2 --version |
| 99 | + |
| 100 | +echo ' ' |
| 101 | +echo 'python3 version is:' |
| 102 | +python3 --version |
| 103 | + |
| 104 | +echo ' ' |
| 105 | +echo 'virtualenv version is:' |
| 106 | +virtualenv --version |
| 107 | + |
| 108 | +echo ' ' |
| 109 | +echo 'pip version is:' |
| 110 | +pip --version |
| 111 | + |
| 112 | +echo ' ' |
| 113 | +echo 'Ubuntu version is:' |
| 114 | +cat /etc/os-release |
| 115 | + |
| 116 | +xtime="$(date)" |
| 117 | +echo ' ' |
| 118 | +echo "===== Setting Up Virtual Environment for Code-Format Check at ${xtime} =====" |
| 119 | +echo ' ' |
| 120 | + |
| 121 | +# Make sure the bash shell prompt variables are set, as virtualenv crashes |
| 122 | +# if PS2 is not set. |
| 123 | +PS1='prompt> ' |
| 124 | +PS2='prompt-more> ' |
| 125 | +virtualenv --system-site-packages -p /usr/bin/python2 "${venv_dir}" |
| 126 | +source "${venv_dir}/bin/activate" |
| 127 | + |
| 128 | +# yapf and futures are needed for code-format checks (ngraph-tf PR#211) |
| 129 | +pip install yapf==0.24.0 |
| 130 | +pip install futures |
| 131 | + |
| 132 | +xtime="$(date)" |
| 133 | +echo ' ' |
| 134 | +echo "===== Starting nGraph TensorFlow Bridge Source Code Format Check at ${xtime} =====" |
| 135 | +echo ' ' |
| 136 | + |
| 137 | +cd "${bridge_dir}" |
| 138 | +maint/check-code-format.sh |
| 139 | + |
| 140 | +xtime="$(date)" |
| 141 | +echo ' ' |
| 142 | +echo "===== Deactivating Virtual Environment at ${xtime} =====" |
| 143 | +echo ' ' |
| 144 | + |
| 145 | +deactivate |
| 146 | + |
| 147 | +xtime="$(date)" |
| 148 | +echo ' ' |
| 149 | +echo "===== Completed Code Format Check at ${xtime} =====" |
| 150 | +echo ' ' |
0 commit comments