2012-02-25 11:30:03 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-06-07 22:55:06 +04:00
|
|
|
# Copyright 2012, Google Inc. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can
|
|
|
|
# be found in the LICENSE file.
|
2012-02-25 11:30:03 +04:00
|
|
|
|
2015-03-12 19:06:23 +03:00
|
|
|
SKIP_ROOT_INSTALLS=False
|
2015-03-13 22:09:08 +03:00
|
|
|
if [ "$1" = "--skip_root_installs" ]; then
|
2015-03-12 19:06:23 +03:00
|
|
|
SKIP_ROOT_INSTALLS=True
|
|
|
|
fi
|
|
|
|
|
2016-01-26 03:01:09 +03:00
|
|
|
# Run parallel make, based on number of cores available.
|
|
|
|
NB_CORES=$(grep -c '^processor' /proc/cpuinfo)
|
|
|
|
if [ -n "$NB_CORES" ]; then
|
|
|
|
export MAKEFLAGS="-j$((NB_CORES+1)) -l${NB_CORES}"
|
|
|
|
fi
|
|
|
|
|
2015-11-05 07:49:58 +03:00
|
|
|
function fail() {
|
|
|
|
echo "ERROR: $1"
|
|
|
|
exit 1
|
2015-11-05 06:04:49 +03:00
|
|
|
}
|
|
|
|
|
2016-01-12 01:29:40 +03:00
|
|
|
function zk_patch_mac() {
|
|
|
|
if [ `uname -s` == "Darwin" ]; then
|
|
|
|
cd zookeeper-$zk_ver && \
|
|
|
|
wget https://issues.apache.org/jira/secure/attachment/12673210/ZOOKEEPER-2049.noprefix.branch-3.4.patch && \
|
|
|
|
patch -p0 < ZOOKEEPER-2049.noprefix.branch-3.4.patch && \
|
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-11-05 07:49:58 +03:00
|
|
|
[ -f bootstrap.sh ] || fail "bootstrap.sh must be run from its current directory"
|
2012-02-25 11:30:03 +04:00
|
|
|
|
2015-11-05 07:49:58 +03:00
|
|
|
[ "$USER" != "root" ] || fail "Vitess cannot run as root. Please bootstrap with a non-root user."
|
2015-01-08 00:23:03 +03:00
|
|
|
|
2015-11-05 07:49:58 +03:00
|
|
|
go version 2>&1 >/dev/null || fail "Go is not installed or is not on \$PATH"
|
2015-01-28 11:04:36 +03:00
|
|
|
|
2016-03-02 09:02:26 +03:00
|
|
|
# Set up the proper GOPATH for go get below.
|
|
|
|
source ./dev.env
|
2012-02-25 11:30:03 +04:00
|
|
|
|
2012-09-13 22:12:27 +04:00
|
|
|
mkdir -p $VTROOT/dist
|
|
|
|
mkdir -p $VTROOT/bin
|
|
|
|
mkdir -p $VTROOT/lib
|
2012-10-27 00:11:44 +04:00
|
|
|
mkdir -p $VTROOT/vthook
|
2012-06-04 09:24:54 +04:00
|
|
|
|
2016-04-15 01:32:59 +03:00
|
|
|
echo "Updating git submodules..."
|
|
|
|
git submodule update --init
|
|
|
|
|
2013-07-18 01:07:28 +04:00
|
|
|
# install zookeeper
|
2015-11-03 06:33:25 +03:00
|
|
|
zk_ver=3.4.6
|
|
|
|
zk_dist=$VTROOT/dist/vt-zookeeper-$zk_ver
|
2015-03-12 09:01:59 +03:00
|
|
|
if [ -f $zk_dist/.build_finished ]; then
|
|
|
|
echo "skipping zookeeper build. remove $zk_dist to force rebuild."
|
2013-07-18 01:07:28 +04:00
|
|
|
else
|
2015-03-12 09:01:59 +03:00
|
|
|
rm -rf $zk_dist
|
2015-11-03 06:33:25 +03:00
|
|
|
(cd $VTROOT/dist && \
|
2015-12-06 03:40:43 +03:00
|
|
|
wget http://archive.apache.org/dist/zookeeper/zookeeper-$zk_ver/zookeeper-$zk_ver.tar.gz && \
|
2015-11-03 06:33:25 +03:00
|
|
|
tar -xzf zookeeper-$zk_ver.tar.gz && \
|
2016-01-12 01:29:40 +03:00
|
|
|
zk_patch_mac && \
|
2013-07-18 01:07:28 +04:00
|
|
|
mkdir -p $zk_dist/lib && \
|
2015-11-03 06:33:25 +03:00
|
|
|
cp zookeeper-$zk_ver/contrib/fatjar/zookeeper-$zk_ver-fatjar.jar $zk_dist/lib && \
|
|
|
|
(cd zookeeper-$zk_ver/src/c && \
|
2013-07-18 01:07:28 +04:00
|
|
|
./configure --prefix=$zk_dist && \
|
2015-11-03 06:33:25 +03:00
|
|
|
make install) && rm -rf zookeeper-$zk_ver zookeeper-$zk_ver.tar.gz)
|
2015-11-05 08:15:57 +03:00
|
|
|
[ $? -eq 0 ] || fail "zookeeper build failed"
|
2015-03-12 09:01:59 +03:00
|
|
|
touch $zk_dist/.build_finished
|
2013-07-18 01:07:28 +04:00
|
|
|
fi
|
|
|
|
|
2016-01-22 21:21:08 +03:00
|
|
|
# install gRPC C++ base, so we can install the python adapters.
|
|
|
|
# this also installs protobufs
|
2015-03-02 19:48:22 +03:00
|
|
|
grpc_dist=$VTROOT/dist/grpc
|
2016-02-27 03:51:56 +03:00
|
|
|
grpc_ver=release-0_13_0
|
2015-03-12 19:06:23 +03:00
|
|
|
if [ $SKIP_ROOT_INSTALLS == "True" ]; then
|
2015-03-27 00:14:25 +03:00
|
|
|
echo "skipping grpc build, as root version was already installed."
|
2016-01-22 23:57:23 +03:00
|
|
|
elif [[ -f $grpc_dist/.build_finished && "$(cat $grpc_dist/.build_finished)" == "$grpc_ver" ]]; then
|
2015-03-12 09:01:59 +03:00
|
|
|
echo "skipping gRPC build. remove $grpc_dist to force rebuild."
|
2015-03-02 19:48:22 +03:00
|
|
|
else
|
2016-02-01 00:44:27 +03:00
|
|
|
# unlink homebrew's protobuf, to be able to compile the downloaded protobuf package
|
|
|
|
if [[ `uname -s` == "Darwin" && "$(brew list -1 | grep google-protobuf)" ]]; then
|
|
|
|
brew unlink grpc/grpc/google-protobuf
|
|
|
|
fi
|
2016-03-02 09:02:26 +03:00
|
|
|
|
|
|
|
# protobuf used to be a separate package, now we use the gRPC one.
|
2016-01-22 23:57:23 +03:00
|
|
|
rm -rf $VTROOT/dist/protobuf
|
2016-03-02 09:02:26 +03:00
|
|
|
|
|
|
|
# Cleanup any existing data and re-create the directory.
|
2015-03-12 09:01:59 +03:00
|
|
|
rm -rf $grpc_dist
|
2016-03-02 09:02:26 +03:00
|
|
|
mkdir -p $grpc_dist
|
2016-01-31 21:45:54 +03:00
|
|
|
|
2015-11-05 07:49:58 +03:00
|
|
|
./travis/install_grpc.sh $grpc_dist || fail "gRPC build failed"
|
2016-01-22 23:57:23 +03:00
|
|
|
echo "$grpc_ver" > $grpc_dist/.build_finished
|
2016-02-01 00:44:27 +03:00
|
|
|
|
|
|
|
# link homebrew's protobuf back
|
|
|
|
if [[ `uname -s` == "Darwin" && "$(brew list -1 | grep google-protobuf)" ]]; then
|
|
|
|
brew link grpc/grpc/google-protobuf
|
|
|
|
fi
|
2016-03-02 09:02:26 +03:00
|
|
|
|
|
|
|
# Add newly installed Python code to PYTHONPATH such that other Python module
|
|
|
|
# installations can reuse it. (Once bootstrap.sh has finished, run
|
|
|
|
# source dev.env instead to set the correct PYTHONPATH.)
|
|
|
|
export PYTHONPATH=$(prepend_path $PYTHONPATH $grpc_dist/usr/local/lib/python2.7/dist-packages)
|
2015-03-02 19:48:22 +03:00
|
|
|
fi
|
|
|
|
|
2016-04-15 04:42:48 +03:00
|
|
|
# Install third-party Go tools used as part of the development workflow.
|
|
|
|
#
|
|
|
|
# DO NOT ADD LIBRARY DEPENDENCIES HERE. Instead use govendor as described below.
|
|
|
|
#
|
|
|
|
gotools=" \
|
2015-07-23 09:46:05 +03:00
|
|
|
github.com/golang/lint/golint \
|
2016-03-10 01:44:40 +03:00
|
|
|
github.com/golang/mock/mockgen \
|
2016-04-15 03:37:43 +03:00
|
|
|
github.com/kardianos/govendor \
|
2015-07-23 09:46:05 +03:00
|
|
|
golang.org/x/tools/cmd/goimports \
|
|
|
|
"
|
2013-07-18 01:07:28 +04:00
|
|
|
|
2016-04-15 04:42:48 +03:00
|
|
|
# Tools for uploading code coverage to coveralls.io (used by Travis CI).
|
|
|
|
gotools+=" github.com/modocache/gover github.com/mattn/goveralls"
|
2015-01-28 10:46:06 +03:00
|
|
|
# The cover tool needs to be installed into the Go toolchain, so it will fail
|
2015-07-23 09:46:05 +03:00
|
|
|
# if Go is installed somewhere that requires root access.
|
2015-08-07 00:51:46 +03:00
|
|
|
source tools/shell_functions.inc
|
|
|
|
if goversion_min 1.4; then
|
2016-04-15 04:42:48 +03:00
|
|
|
gotools+=" golang.org/x/tools/cmd/cover"
|
2015-08-07 00:51:46 +03:00
|
|
|
else
|
2016-04-15 04:42:48 +03:00
|
|
|
gotools+=" code.google.com/p/go.tools/cmd/cover"
|
2015-08-07 00:51:46 +03:00
|
|
|
fi
|
2015-07-23 09:46:05 +03:00
|
|
|
|
2016-04-15 04:42:48 +03:00
|
|
|
echo "Installing dev tools with 'go get'..."
|
|
|
|
go get -u $gotools || fail "Failed to download some Go tools with 'go get'. Please re-run bootstrap.sh in case of transient errors."
|
2014-10-01 05:59:51 +04:00
|
|
|
|
2016-04-15 03:37:43 +03:00
|
|
|
# Download dependencies that are version-pinned via govendor.
|
2016-04-15 04:42:48 +03:00
|
|
|
#
|
|
|
|
# To add a new dependency, run:
|
|
|
|
# govendor fetch <package_path>
|
|
|
|
#
|
2016-04-20 22:26:25 +03:00
|
|
|
# Existing dependencies can be updated to the latest version with 'fetch' as well.
|
|
|
|
#
|
2016-04-15 04:42:48 +03:00
|
|
|
# Then:
|
|
|
|
# git add vendor/vendor.json
|
|
|
|
# git commit
|
|
|
|
#
|
|
|
|
# See https://github.com/kardianos/govendor for more options.
|
|
|
|
echo "Updating govendor dependencies..."
|
2016-04-15 03:37:43 +03:00
|
|
|
govendor sync || fail "Failed to download/update dependencies with govendor. Please re-run bootstrap.sh in case of transient errors."
|
|
|
|
|
2013-03-09 00:01:49 +04:00
|
|
|
ln -snf $VTTOP/config $VTROOT/config
|
|
|
|
ln -snf $VTTOP/data $VTROOT/data
|
|
|
|
ln -snf $VTTOP/py $VTROOT/py-vtdb
|
|
|
|
ln -snf $VTTOP/go/zk/zkctl/zksrv.sh $VTROOT/bin/zksrv.sh
|
2014-04-04 22:33:57 +04:00
|
|
|
ln -snf $VTTOP/test/vthook-test.sh $VTROOT/vthook/test.sh
|
2013-03-09 00:01:49 +04:00
|
|
|
|
2016-03-05 02:48:34 +03:00
|
|
|
# find mysql and prepare to use libmysqlclient
|
2015-02-23 18:42:32 +03:00
|
|
|
if [ -z "$MYSQL_FLAVOR" ]; then
|
2016-03-05 02:48:34 +03:00
|
|
|
export MYSQL_FLAVOR=MySQL56
|
|
|
|
echo "MYSQL_FLAVOR environment variable not set. Using default: $MYSQL_FLAVOR"
|
2015-02-23 18:42:32 +03:00
|
|
|
fi
|
2014-08-29 00:14:26 +04:00
|
|
|
case "$MYSQL_FLAVOR" in
|
2015-04-22 23:02:10 +03:00
|
|
|
"MySQL56")
|
2016-05-19 22:48:56 +03:00
|
|
|
myversion=`$VT_MYSQL_ROOT/bin/mysql --version`
|
|
|
|
[[ "$myversion" =~ Distrib\ 5\.[67] ]] || fail "Couldn't find MySQL 5.6+ in $VT_MYSQL_ROOT. Set VT_MYSQL_ROOT to override search location."
|
|
|
|
echo "Found MySQL 5.6+ installation in $VT_MYSQL_ROOT."
|
2015-02-20 00:03:12 +03:00
|
|
|
;;
|
|
|
|
|
2015-02-23 18:42:32 +03:00
|
|
|
"MariaDB")
|
2016-05-19 22:48:56 +03:00
|
|
|
myversion=`$VT_MYSQL_ROOT/bin/mysql --version`
|
|
|
|
[[ "$myversion" =~ MariaDB ]] || fail "Couldn't find MariaDB in $VT_MYSQL_ROOT. Set VT_MYSQL_ROOT to override search location."
|
2014-08-29 00:14:26 +04:00
|
|
|
echo "Found MariaDB installation in $VT_MYSQL_ROOT."
|
|
|
|
;;
|
|
|
|
|
2015-02-23 18:42:32 +03:00
|
|
|
*)
|
2015-11-05 07:49:58 +03:00
|
|
|
fail "Unsupported MYSQL_FLAVOR $MYSQL_FLAVOR"
|
2015-02-23 18:42:32 +03:00
|
|
|
;;
|
|
|
|
|
2014-08-29 00:14:26 +04:00
|
|
|
esac
|
2013-07-19 04:24:47 +04:00
|
|
|
|
2014-08-23 00:53:54 +04:00
|
|
|
# save the flavor that was used in bootstrap, so it can be restored
|
|
|
|
# every time dev.env is sourced.
|
2014-08-29 00:14:26 +04:00
|
|
|
echo "$MYSQL_FLAVOR" > $VTROOT/dist/MYSQL_FLAVOR
|
2014-08-23 00:53:54 +04:00
|
|
|
|
2012-09-13 22:12:27 +04:00
|
|
|
# generate pkg-config, so go can use mysql C client
|
2015-11-05 07:49:58 +03:00
|
|
|
[ -x $VT_MYSQL_ROOT/bin/mysql_config ] || fail "Cannot execute $VT_MYSQL_ROOT/bin/mysql_config. Did you install a client dev package?"
|
2013-07-18 01:07:28 +04:00
|
|
|
|
2012-09-13 22:12:27 +04:00
|
|
|
cp $VTTOP/config/gomysql.pc.tmpl $VTROOT/lib/gomysql.pc
|
2016-05-19 22:48:56 +03:00
|
|
|
myversion=`$VT_MYSQL_ROOT/bin/mysql_config --version`
|
|
|
|
echo "Version:" "$myversion" >> $VTROOT/lib/gomysql.pc
|
2012-09-13 22:12:27 +04:00
|
|
|
echo "Cflags:" "$($VT_MYSQL_ROOT/bin/mysql_config --cflags) -ggdb -fPIC" >> $VTROOT/lib/gomysql.pc
|
2016-05-19 22:48:56 +03:00
|
|
|
if [[ "$MYSQL_FLAVOR" == "MariaDB" || "$myversion" =~ ^5\.7\. ]]; then
|
2014-08-20 03:07:43 +04:00
|
|
|
# Use static linking because the shared library doesn't export
|
|
|
|
# some internal functions we use, like cli_safe_read.
|
2016-01-14 08:24:17 +03:00
|
|
|
echo "Libs:" "$($VT_MYSQL_ROOT/bin/mysql_config --libs_r | sed -r 's,-lmysqlclient(_r)?,-l:libmysqlclient.a -lstdc++,')" >> $VTROOT/lib/gomysql.pc
|
2014-08-20 03:07:43 +04:00
|
|
|
else
|
|
|
|
echo "Libs:" "$($VT_MYSQL_ROOT/bin/mysql_config --libs_r)" >> $VTROOT/lib/gomysql.pc
|
|
|
|
fi
|
2012-09-05 01:20:28 +04:00
|
|
|
|
2015-06-26 08:51:53 +03:00
|
|
|
# install mock
|
|
|
|
mock_dist=$VTROOT/dist/py-mock-1.0.1
|
|
|
|
if [ -f $mock_dist/.build_finished ]; then
|
|
|
|
echo "skipping mock python build"
|
|
|
|
else
|
2015-07-23 10:25:51 +03:00
|
|
|
# Cleanup any existing data
|
|
|
|
# (e.g. necessary for Travis CI caching which creates .build_finished as directory and prevents this script from creating it as file).
|
|
|
|
rm -rf $mock_dist
|
2015-06-26 08:51:53 +03:00
|
|
|
# For some reason, it seems like setuptools won't create directories even with the --prefix argument
|
|
|
|
mkdir -p $mock_dist/lib/python2.7/site-packages
|
2015-06-27 09:58:22 +03:00
|
|
|
export PYTHONPATH=$(prepend_path $PYTHONPATH $mock_dist/lib/python2.7/site-packages)
|
2015-06-26 08:51:53 +03:00
|
|
|
cd $VTTOP/third_party/py && \
|
|
|
|
tar -xzf mock-1.0.1.tar.gz && \
|
|
|
|
cd mock-1.0.1 && \
|
|
|
|
python ./setup.py install --prefix=$mock_dist && \
|
|
|
|
touch $mock_dist/.build_finished && \
|
|
|
|
cd .. && \
|
|
|
|
rm -r mock-1.0.1
|
|
|
|
fi
|
|
|
|
|
2013-07-20 03:23:02 +04:00
|
|
|
# create pre-commit hooks
|
|
|
|
echo "creating git pre-commit hooks"
|
2016-01-22 23:57:23 +03:00
|
|
|
mkdir -p $VTTOP/.git/hooks
|
2013-07-20 03:23:02 +04:00
|
|
|
ln -sf $VTTOP/misc/git/pre-commit $VTTOP/.git/hooks/pre-commit
|
2015-01-08 00:23:03 +03:00
|
|
|
|
2016-06-18 01:38:53 +03:00
|
|
|
# Download chromedriver
|
2016-06-23 01:26:14 +03:00
|
|
|
echo "Installing selenium and chromedriver"
|
|
|
|
selenium_dist=$VTROOT/dist/selenium
|
|
|
|
mkdir -p $selenium_dist
|
|
|
|
virtualenv $selenium_dist
|
|
|
|
$selenium_dist/bin/pip install selenium
|
2016-06-18 01:38:53 +03:00
|
|
|
mkdir -p $VTROOT/dist/chromedriver
|
2016-06-24 21:49:36 +03:00
|
|
|
curl http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip > chromedriver_linux64.zip -s
|
2016-06-23 01:26:14 +03:00
|
|
|
unzip -o -q chromedriver_linux64.zip -d $VTROOT/dist/chromedriver
|
|
|
|
rm chromedriver_linux64.zip
|
2016-06-18 01:38:53 +03:00
|
|
|
|
2015-01-08 00:23:03 +03:00
|
|
|
echo
|
2015-01-28 10:48:29 +03:00
|
|
|
echo "bootstrap finished - run 'source dev.env' in your shell before building."
|