User:Aligorith/Scripts/brepo init sh

Shell script for checking out and setting up new checkouts of the Blender sources, ready to use for development.

This was created during Code Quest '18, as I was constantly setting up new repos after having to set up my machine twice in as many days. It automates the process of running all the necessary git commands to check out the source tree, addons + other submodules, switch to a target branch, checkout/install libs, and set up symlinks so that you won't need to wait for scripts to get copied on each rebuild.

Usage
Save the following script as " ", and put in " " to make it available everywhere.

Script

 * 1) !/usr/bin/env bash
 * 2) Script to download an initialise a new Blender repository
 * 3) Author: Joshua Leung (aligorith@gmail.com)
 * 4) Date: April 2018
 * 1) Date: April 2018


 * 1) Configuration Parameters
 * 2) NOTE: Customise these before running the script

ROOT_DIR=$PWD REPO_DIR=$1 # first parameter is the name of the repo to use

BUILD_DIR="build_linux" # XXX: figure out how to make cmake write to just "build"

AS_DEV=false OPTIMISE_REBUILDS=true

if [ $# = 2 ]; then # optional second parameter is either "--install_deps" or " " if [ $2 = "--install_deps" ]; then echo " -- Install Deps" INSTALL_DEPS=true BRANCH="master" else echo " -- Checkout Branch '$2'" INSTALL_DEPS=false BRANCH=$2 fi else # no (extra) arguments provided - do nothing INSTALL_DEPS=false BRANCH="master" fi


 * 1) Printing Helpers (from blender's install_deps.sh) --

BLACK=$(tput setaf 0) RED=$(tput setaf 1) GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) LIME_YELLOW=$(tput setaf 190) POWDER_BLUE=$(tput setaf 153) BLUE=$(tput setaf 4) MAGENTA=$(tput setaf 5) CYAN=$(tput setaf 6) WHITE=$(tput setaf 7) BRIGHT=$(tput bold) NORMAL=$(tput sgr0) BLINK=$(tput blink) REVERSE=$(tput smso) UNDERLINE=$(tput smul)

_echo { if [ "X$1" = "X-n" ]; then shift; printf "%s" "$@" else printf "%s\n" "$@" fi }

ERROR { _echo "${BRIGHT}${RED}ERROR! ${NORMAL}${RED}$@${NORMAL}" }

WARNING { _echo "${BRIGHT}${YELLOW}WARNING! ${NORMAL}${YELLOW}$@${NORMAL}" }

USAGE { _echo "${BRIGHT}${YELLOW}USAGE! ${BRIGHT}${YELLOW}$@${NORMAL}" }

INFO { _echo "${BRIGHT}${GREEN}$@${NORMAL}" }

PRINT { _echo "$@" }


 * 1) Help/Usage Info -

if [ $# = 0 ]; then USAGE "$ . brepo_init.sh  --install_deps | ]" echo "($# args found)" #return fi


 * 1) Let the magic begin --

if [ $# = 0 ]; then REPO_DIR="master" fi REPO_ROOT_DIR="$ROOT_DIR/$REPO_DIR"
 * 1) TODO: Check if root directory exists

INFO "Creating repo - '$REPO_ROOT_DIR'" mkdir $REPO_ROOT_DIR cd $REPO_ROOT_DIR

INFO "Checking out Blender Sources..." if [ $AS_DEV = true ]; then git clone git@git.blender.org:blender.git else git clone git://git.blender.org/blender.git fi

cd blender

INFO "Checking out Blender Submodules..." git submodule update --init --recursive git submodule foreach git checkout master git submodule foreach git pull --rebase origin master

if [ "$BRANCH" != "master" ]; then INFO "Checking out '${BRANCH}' branch..." git checkout -b $BRANCH origin/$BRANCH fi


 * 1) Install dependencies -

if [ $INSTALL_DEPS = true ]; then INFO "Installing dependencies..." build_files/build_environment/install_deps.sh fi


 * 1) Make Symlinks --

INFO "Making links..." mkdir ../build_linux  # XXX: this is the name used by the default makefile mkdir ../build_linux/bin

ln -s "$REPO_ROOT_DIR/build_linux/bin/" "$REPO_ROOT_DIR/install"

if [ $OPTIMISE_REBUILDS = true ]; then INFO " Optimise rebuilds..." ln -s "$REPO_ROOT_DIR/blender/release" "$REPO_ROOT_DIR/build_linux/bin" fi
 * 1) Optimise rebuilds

INFO "Done! Change current directory to '$REPO_ROOT_DIR/blender' to compile"
 * 1) Done ---
 * 2) XXX: Ideally we would be able to help the user change current directories in the parent shell too...
 * 3) For now, just copy the text to the clipboard