# This is for creating a local developer environment to run non-rust commands. # # # Prerequisites # This assumes you have the following installed: # - python2.7 # - virtuanenv (with any python version) # # Python recommended command: `sudo pip install virtualenv` # # # Usage # To use simply execute the following. All your paths will be setup for you: # ``` # source env # ``` export RUSTFMT_VERSION="0.2.5" export RUSTCLIPPY_VERSION="0.0.155" export RUST_VERSION="nightly-2017-08-31" export PKG_CONFIG_ALLOW_CROSS=1 export NPM_PACKAGES="\ elm@0.18.0 \ elm-test@0.17.3 elm-format@0.6.1-alpha \ webpack@3.5.5 \ phantomjs@2.1.7 \ " export PYTHON_CHECK="\ web-ui/sel_tests \ web-ui/py_helpers \ scripts/interact.py \ " export NODE_VERSION="v8.4.0" if [ -z $TRAVIS_BUILD_DIR ]; then # if non-travis, create in target directory and override PATH export ENV_DIR=$PWD/target/env export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin" else # if on travis, create in ~/build_environment and leave PATH alone export ENV_DIR=$HOME/build_environment fi if [[ `uname` == "Darwin" ]]; then NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-darwin-x64.tar.gz" else NODE_URL="https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64.tar.xz" fi errcho() { >&2 echo "\e[1m\e[32m${1}\e[0m" } if [ ! -d ".git" ] || [ ! -d "web-ui" ]; then errcho "Must be run in repository root." return 1 fi pathinsert() { export PATH="$1:$PATH" } mkdir -p $ENV_DIR ################################################################################ # setup rust errcho "-- setting up rust --" RUST_DIR=$ENV_DIR/rust export CARGO_HOME=$RUST_DIR/cargo export RUSTUP_HOME=$RUST_DIR/multirust export RUST_BIN=$CARGO_HOME/bin mkdir -p $CARGO_HOME if [ ! -d $RUSTUP_HOME ]; then errcho "- installing rustup" curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUST_VERSION || return $? fi pathinsert $RUST_BIN # always make sure the default is up-to-date rustup default $RUST_VERSION || return $? if [ "$CI_BUILD" = "fast" ]; then echo "CI_BUILD=fast, only rust is installed in env." return 0 fi ################################################################################ # setup python virtualenv and packages errcho "-- setting up python --" PY_DIR=$ENV_DIR/art PY_ACTIVATE=$PY_DIR/bin/activate export PYTHONPATH="web-ui" if [ ! -d $PY_DIR ]; then virtualenv $PY_DIR -p python2.7 || return $? source $PY_ACTIVATE || return $? else source $PY_ACTIVATE || return $? fi ################################################################################ # set up node path and packages errcho "-- setting up node.js and elm --" export NODE_DIR=$ENV_DIR/node NODE_BIN=$NODE_DIR/bin if [ -x $NODE_BIN/node ]; then current_node_version=$($NODE_BIN/node --version) || return $? fi if [ ! -x $NODE_BIN/node ] || [ "$current_node_version" != "$NODE_VERSION" ]; then errcho "- installing node.js + npm" rm -rf $NODE_DIR && mkdir $NODE_DIR || return $? curl -LSfs $NODE_URL | \ tar xJ --directory $NODE_DIR --strip-components=1 -- fi pathinsert $NODE_DIR/node_modules/.bin pathinsert $NODE_BIN ################################################################################ # Do final updates mkdir -p $RUST_BIN errcho "-- do final update of dependencies --" if [ ! -e $RUST_BIN/just ]; then errcho "- installing build tools" # install required packages. They can be updated with `just update` cargo install cargo-update || return $? cargo install just || return $? fi pathinsert $NODE_DIR/node_modules/.bin if [ "$CI_BUILD" = "full" ]; then just update || return $? echo "CI_BUILD=full, finished setting up env" return 0 fi if [ ! -e $RUST_BIN/art ]; then errcho "- building release+debug artifact as art+artd" # build artifact in release mode and debug mode and link both cargo build --release || return $? cargo build || return $? ln -s $PWD/target/release/art $RUST_BIN/art || return $? ln -s $PWD/target/debug/art $RUST_BIN/artd || return $? fi errcho "-- artifact environment has been set up successfully --"