利用者:Gdh/Workflow

提供: wiki
< 利用者:Gdh
2013年7月2日 (火) 09:02時点におけるwiki>Gdhによる版 (Recopied blender_release again. I really need to wait until I finish changing it before I put it up here.)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Workflow

My workflow mainly consists of Bash scripts and aliases.

Bash Scripts

Yes/No Script (yesno.sh)

I found this script on the Internet. It asks the user a yes/no question. If you give it a default, the user can accept the default by just pressing enter. If you give it a timeout, it will assume the default answer after that amount of time. I include this script because a lot of my other scripts use it.

#!/bin/bash

# Original script by Mitch Frazier. Copied from
# http://www.linuxjournal.com/content/asking-yesno-question-bash-script
# I made one change and turned the yesno function into the actual script.


#####################################################################
# Print warning message.

function warning()
{
    echo "$*" >&2
}

#####################################################################
# Print error message and exit.

function error()
{
    echo "$*" >&2
    exit 1
}


#####################################################################
# Ask yesno question.
#
# Usage: yesno OPTIONS QUESTION
#
#   Options:
#     --timeout N    Timeout if no input seen in N seconds.
#     --default ANS  Use ANS as the default answer on timeout or
#                    if an empty answer is provided.
#
# Exit status is the answer.

ans=''
ok=0
timeout=0
default=''
t=0

while [[ "$1" ]]
do
    case "$1" in
    --default)
        shift
        default=$1
        if [[ ! "$default" ]]; then error "Missing default value"; fi
        t=$(tr '[:upper:]' '[:lower:]' <<<$default)
        if [[ "$t" != 'y'  &&  "$t" != 'yes'  &&  "$t" != 'n'  &&  "$t" != 'no' ]]; then
            error "Illegal default answer: $default"
        fi
        default=$t
        shift
        ;;

    --timeout)
        shift
        timeout=$1
        if [[ ! "$timeout" ]]; then error "Missing timeout value"; fi
        if [[ ! "$timeout" =~ ^[0-9][0-9]*$ ]]; then error "Illegal timeout value: $timeout"; fi
        shift
        ;;

    -*)
        error "Unrecognized option: $1"
        ;;

    *)
        break
        ;;
    esac
done

if [[ $timeout -ne 0  &&  ! "$default" ]]; then
    error "Non-zero timeout requires a default answer"
fi

if [[ ! "$*" ]]; then error "Missing question"; fi

while [[ $ok -eq 0 ]]
do
    if [[ $timeout -ne 0 ]]; then
        if ! read -t $timeout -p "$*" ans; then
        	echo -e
            ans=$default
        else
            # Turn off timeout if answer entered.
            timeout=0
            if [[ ! "$ans" ]]; then ans=$default; fi
        fi
    else
        read -p "$*" ans
        if [[ ! "$ans" ]]; then
            ans=$default
        else
            ans=$(tr '[:upper:]' '[:lower:]' <<<$ans)
        fi 
    fi

    if [[ "$ans" == 'y'  ||  "$ans" == 'yes'  ||  "$ans" == 'n'  ||  "$ans" == 'no' ]]; then
        ok=1
    fi

    if [[ $ok -eq 0 ]]; then warning "Valid answers are: yes y no n"; fi
done
[[ "$ans" = "y" || "$ans" == "yes" ]]

Blender Builder (blender_builder.sh)

This script compiles Blender. It will also run it. It will accept two different arguments: '--norun', which will cause it to exit without running Blender, and '--yesrun', which will cause it to run Blender without asking. If the user doesn't use those arguments, it will ask the user (using the yesno.sh script above) if they want to run Blender.

This script will compile Blender with a custom splash. If you don't want a custom splash comment out the code that would generate it. The code in question is marked.

#!/bin/bash

# Set variables.

# Don't change this one. It is the URL for the trunk.
trunk='https://svn.blender.org/svnroot/bf-blender/trunk/blender'

# Change this one to the directory ABOVE your blender source tree.
# I have this directory to hold my build tree, my GSoC files, etc.
# This assumes that the user does out-of-source builds (which are
# highly recommended).
ROOT='/home/gavin/Code/blender-svn'

# Change this one to the directory containing the source tree.
SRC="$ROOT/blender"

# This is the directory where the build tree is stored. Notice
# that it is contained in the same directory as the source tree.
# Change this if needed.
BUILD="$ROOT/build"

# This is the absolute path to Blender's splash image. This is in
# the source tree. (On my computer, the source tree is in the folder
# $SRC/blender. Change this one if needed.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
SPLASH="$SRC/release/datafiles/splash.png"

# This is the path to my custom splash image. This is in the directory
# above the source tree. Change if needed.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
MY_SPLASH="$ROOT/splash.png"

# This is the path to the file where we store a temporary copy of
# the official splash. Change this if needed.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
TEMP_SPLASH="$ROOT/current.png"

# This is how many threads the user wants to use for building.
# Change this if needed.
THREADS=8

# This sound plays when the merge is finished.
# Change to your preferred sound file.
sound='/usr/share/sounds/ubuntu/stereo/dialog-question.ogg'

# This is the location of the yesno script. I use this script to
# ask the user a yes/no question. Change this if needed.
yesno='/home/gavin/Scripts/yesno.sh'

# We can pass in an argument to not run blender.
NORUN=0
YESRUN=0
if [ $# -eq 1 ];
then
	if [ $1 == "--norun" ];
	then
		NORUN=1
	elif [ $1 == "--yesrun" ];
	then
		YESRUN=1
	else
		echo -e "Unrecognized argument $1."
	fi
fi

# Get into the blender root directory.
cd $SRC

# Replace the real splash with our splash.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
mv -f $SPLASH $TEMP_SPLASH
cp $MY_SPLASH $SPLASH

# Compile blender.
cd $BUILD
cmake $SRC
make install -j$THREADS

# Put the real splash back.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
cd $SRC
rm $SPLASH
mv -f $TEMP_SPLASH $SPLASH
svn revert $SPLASH

# Play an alert sound to let me know it's done building.
paplay $sound

# Run blender.
if [[ $NORUN -ne 1 ]];
then
	if [[ $YESRUN -ne 1 ]];
	then
		if $yesno --timeout 30 --default no "Run Blender [y/n]: ";
		then
			cd $BUILD
			bin/blender
		fi
	else
		cd $BUILD
		bin/blender
	fi
fi

Blender Updater (blender_updater.sh)

This script updates trunk to the latest revision.

#!/bin/bash

# Define variables.

# Don't change this one. It is the URL for the trunk.
trunk='https://svn.blender.org/svnroot/bf-blender/trunk/blender'

# Change this one to the directory ABOVE your blender source tree.
# I have this directory to hold my build tree, my GSoC files, etc.
# This assumes that the user does out-of-source builds (which are
# highly recommended).
ROOT='/home/gavin/Code/blender-svn'

# Change this one to the directory containing the source tree.
SRC="$ROOT/blender"

# This is the file where the svn log is written to.
# Change this if needed.
log="$ROOT/log"

# This is the file that the current revision number is
# written to. Change this if needed.
revision="$ROOT/.rev"

# This is the location of the blender_builder script.
# Change this to the location of your builder script.
build='/home/gavin/Scripts/blender/blender_builder.sh'

# This is where the actual script begins.

# Update the source.
cd $SRC
svn switch $trunk
svn up

# This will remove the log file if necessary.
if [ -e "$log" ]
then
   rm $log
fi

# Get the last revision.
read lastRev < $revision

# Get the current revision.
thisRev=$(svn info | grep "Revision" | awk {'print $2'})

# If the revisions are not the same, add one to the lastRev.
# This is so I don't have to see svn log twice for that revision.
if [ $lastRev -lt $thisRev ]
then
	lastRev=$( expr $lastRev + 1 )
fi

# Generate the log from the revisions.
echo -e "svn log $lastRev:$thisRev\n" > $log
svn log --diff -r $lastRev:$thisRev >> $log
nano -v $log

# Put the new revision into the file.
echo $thisRev > $revision

# Compile blender.
$build

Blender Merge (blender_merge.sh)

This script merges the latest trunk into my branch. It will also allow me to add to the commit message if I want to.

#!/bin/bash

# Set variables.

# Don't change this one. It is the URL for the trunk.
trunk='https://svn.blender.org/svnroot/bf-blender/trunk/blender'

# Change this one to the URL of the branch you are working on.
branch='https://svn.blender.org/svnroot/bf-blender/branches/soc-2013-cycles_mblur'

# Change this one to the directory ABOVE your blender source tree.
# I have this directory to hold my build tree, my GSoC files, etc.
# This assumes that the user does out-of-source builds (which are
# highly recommended).
ROOT='/home/gavin/Code/blender-svn'

# Change this one to the directory containing the source tree.
SRC="$ROOT/blender"

# This is the directory where the build tree is stored. Notice
# that it is contained in the same directory as the source tree.
# Change this if needed.
BUILD="$ROOT/build"

# This is the file that stores the number of the last revision that
# was merged into the branch. Change this if needed.
merge="$ROOT/.merge"

# This is the file that the current revision number is
# written to. Change this if needed.
revision="$ROOT/.rev"

# This is the location of the yesno script. I use this script to
# ask the user a yes/no question. Change this if needed.
yesno='/home/gavin/Scripts/yesno.sh'

# This sound plays when the merge is finished.
# Change to your preferred sound file.
sound='/usr/share/sounds/ubuntu/stereo/dialog-question.ogg'

# This is the file that stores the temporary file for the commit
# message. (When the user runs this script, they can add to the
# standard commit message. Change if needed.
FILE="/tmp/svn_merge"

# This is the extra part of the commit message. Don't change this.
message=""

# This sets the commit message intro. You can change this one if you want.
# You may want to keep $mergeRev and $curRev included in this. The first two
# variables will be replaced by $mergeRev and $curRev, respectively.
mergeStr="<mergeRev>"
curStr="<curRev>"
intro="Merged trunk into branch. Includes r$mergeStr to r$curStr."

# This is where the actual script begins.

# cd into the directory.
cd $SRC

# Get the current revision, as well as the last revision we merged.
read curRev < $revision
read mergeRev < $merge

# Switch back to branch.
echo -e "\nNow switching...\n"
svn switch $branch

# Merge trunk
echo -e "\nNow merging...\n"
svn merge $trunk

# Play an alert sound to let me know it's done merging.
paplay $sound

# Make sure the new revision is after the last merge.
# If so, add one to the last merge revision.
if [ $mergeRev -lt $curRev ]
then
	mergeRev=$( expr $mergeRev + 1 )
fi

# Inserts the revision numbers in the intro to the commit message.
intro=$(echo -e ${intro//$mergeStr/$mergeRev})
intro=$(echo -e ${intro//$curStr/$curRev})

# Allow the user to write a commit message.
if $yesno --timeout 30 --default no "Add to commit message [y/n]: ";
then
	echo -e "# Write your commit message below. (This line is ignored.)" > $FILE
	
	# This command makes it so you cannot have a commit
	# message go beyond 72 characters on one line.
	nano --tabstospaces --tabsize=4 --fill=72 +2,1 $FILE
	
	# Delete the first line in the file.
	sed -i 1d $FILE
	
	count=0
	while read line; do
		if [[ count -eq 0 ]];
		then
			message="\n"$message
		fi
		message=$message"\n"$line
		let count+=1
	done < $FILE

	# Commit.
	echo -e "\nNow committing...\n"
	echo -e "$intro$message" > $FILE
	svn commit -F $FILE
	
	# Delete the temp file.
	rm $FILE
else
	# Commit.
	svn commit -m $intro
fi

# Put the new revision into the file.
echo $curRev > $merge

Blender Release (blender_release.sh)

This script compiles a release build for me. It will handle custom splashes (comment out the code for the custom splash if you don't want it). It also copies all of the files to the install folder.

#!/bin/bash

# Define a function to get the revision numbers.
get_revisions() {

	echo -e "\nType the release revision number: "
	read revision

	echo -e "\nType the addons revision number: "
	read addons

	echo -e "\nType the locale revision number: "
	read locale
}

# Set variables.

# Don't change this one. It is the URL for the trunk.
trunk='https://svn.blender.org/svnroot/bf-blender/trunk/blender'

# Change this one to the directory ABOVE your blender source tree.
# I have this directory to hold my build tree, my GSoC files, etc.
# This assumes that the user does out-of-source builds (which are
# highly recommended).
ROOT='/home/gavin/Code/blender-svn'

# Change this one to the directory containing the source tree.
SRC="$ROOT/blender"

# This is the name of the file that contains the list of all of the
# releases that have been built. Change if needed.
RELEASE="$ROOT/.release"

# This is the directory where the release build is stored. Notice
# that it is contained in the same directory as the source tree.
# Change this if needed.
BUILD="$ROOT/release"

# This is the relative path to Blender's splash image. This is in
# the source tree. (On my computer, the source tree is in the folder
# $SRC/blender. Change this one if needed.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
SPLASH="$SRC/release/datafiles/splash.png"

# This is how many threads the user wants to use for building.
# Change this if needed.
THREADS=8

# This sound plays when the merge is finished.
# Change to your preferred sound file.
sound='/usr/share/sounds/ubuntu/stereo/dialog-question.ogg'

# This is the location of the yesno script. I use this script to
# ask the user a yes/no question. Change this if needed.
yesno='/home/gavin/Scripts/yesno.sh'

# This is the directory where Blender will be installed.
# Change this if needed.
install='/home/gavin/.blender'

# This are for installing a custom splash. Don't edit these.
# ONLY USE IF YOU WANT A CUSTOM SPLASH!
useSplash=1
editSplash=0

# This is where the actual script begins.

# Get into the blender root directory.
cd $SRC

# Switch to trunk.
echo -e "\nSwitching to trunk...\n"
svn switch $trunk

# Get all of the revision numbers.

# If the user just presses enter, the script will build the latest release.
echo -e "\nLeave inputs blank for current settings."

# The version string is something like "2.67a".
echo -e "\nType the version string:"
read version

# If the user didn't enter anything, just read from the .release file.
# Otherwise, write to the .release file.
if [ -z "$version" ] ;
then

	# We do not need to edit the splash screen
	# because we are on the same version as last time.
	editSplash=0

	version=$(cat $RELEASE | grep -m 1 "Version:" | awk {'print $2'})

	echo -e "Using version ""$version"".\n"

	if [ -z $revision ] ;
	then
		revision=$(cat $RELEASE | grep -m 1 "Revision:" | awk {'print $2'})
	fi

	if [ -z $addons ];
	then
		addons=$(cat $RELEASE | grep -m 1 "Addons:" | awk {'print $2'})
	fi

	if [ -z $locale ];
	then
		locale=$(cat $RELEASE | grep -m 1 "Locale:" | awk {'print $2'})
	fi
else
	
	# We need to edit the splash screen.
	editSplash=1

	section=$(cat $RELEASE | grep "$version" -A3)
	
	if [ -z "$section" ] ;
	then
	
		get_revisions
	
		string="Version:\t"$version" \nRevision:\t"$revision"\nAddons:\t\t"$addons"\nLocale:\t\t"$locale"\n"
		
		while read line; do 
			if [ -n "$line" ];
			then
				if [[ $line == Version:* ]];
				then
					line="\n"$line
				fi
				string=$string$line"\n"
			fi
		done < $RELEASE
		
		echo -e "$string" | tee $RELEASE
	else
	
		if [ -z "$revision" ] ;
		then
			revision=$( echo $section | grep -m 1 "Revision:" | awk {'print $4'})
		fi

		if [ -z $addons ] ;
		then
			addons=$( echo $section | grep -m 1 "Addons:" | awk {'print $6'})
		fi

		if [ -z $locale ];
		then
			locale=$( echo $section | grep -m 1 "Locale:" | awk {'print $8'})
		fi
	fi
fi
	
# Update svn to the revision numbers.
svn switch $trunk
svn update -r $revision --ignore-externals
svn update release/scripts/addons -r $addons
svn update addons_contrib -r $addons
svn update release/datafiles/locale -r $locale

# Go to the root directory.
cd $ROOT

# ONLY USE IF YOU WANT A CUSTOM SPLASH!
# Play a sound to let me know it's waiting.
paplay $sound
if $yesno --timeout 30 --default yes "Use your own release splash [y/n]: ";
then
	echo -e "\nUsing custom splash...\n"
else
    editSplash=0
    useSplash=0
fi

# ONLY USE IF YOU WANT A CUSTOM SPLASH!
if [ $editSplash -eq 1 ];
then

	# Change the splash to reflect the new version.
	gimp ./splash_template.xcf
fi

# ONLY USE IF YOU WANT A CUSTOM SPLASH!
if [ $useSplash -eq 1 ];
then

	# Move the actual splash out and put our splash in.
	mv -f $SPLASH ./current.png
	cp ./splash.png $SPLASH
fi

# Remove the directory where we install blender.
rm -r $install

# Build the release.
cd $BUILD
cmake $SRC
make install -j$THREADS

# ONLY USE IF YOU WANT A CUSTOM SPLASH!
if [ $useSplash -eq 1 ];
then
	# Put the real splash back.
	cd $ROOT
	rm $SPLASH
	mv -f ./current.png $SPLASH
	svn revert $SPLASH
fi

# Move the compiled release to the install directory.
echo -e "\nInstalling Blender...\n"
cp -r $BUILD/bin $install

# Play a sound to let me know it's done building.
paplay $sound

Svn Diff (svd.sh)

This script runs an svn diff, and it stores it in a patch. The patch name can be specified.

#!/bin/bash

# Use: svd [diff_name]

# Set variables.

# This is the string that will be used to display the help.
# You probably don't want to change it.
helpString='help'

# This is the directory of the source tree.
# You will need to change this one to match yours.
SRC='/home/gavin/Code/blender-svn/blender'
file=''

# Display help or set the patch name according to user's preference.
if [ $1 ] ;
then
	if [ $1 = $helpString ] ;
	then
		echo -e "\nUsage: svd [name of patch]\n"
		exit
	else
		file="../$1.diff"
	fi
else
   file="../patch.diff"
fi

# If file exists, delete it.
cd $SRC
if [ -e "$file" ]
then
   rm $file
fi

# Generate the patch.
svn diff > $file

# View the patch.
nano -v $file

Bash Aliases

These are the aliases I use in day-to-day development. They refer to the scripts above as well as some other things.

# Run my release build of Blender.
alias blender='/home/gavin/.blender/blender'

# Run my debug (development) build of BLender.
alias blend='/home/gavin/Code/blender-svn/build/bin/blender'

# Run my blender_builder script, which compiles Blender.
alias blenb='/home/gavin/Scripts/blender/blender_builder.sh'

# Runs my blender_builder script, automatically
# running Blender after instead of asking.
alias blenby='/home/gavin/Scripts/blender/blender_builder.sh --yesrun'

# Runs my blender_updater script, which updates trunk to the latest revision.
alias blenu='/home/gavin/Scripts/blender/blender_updater.sh'

# Runs my blender_release script, which compiles a release build and installs it.
alias blenr='/home/gavin/Scripts/blender/blender_release.sh'

# Runs my blender_merge script, which merges trunk into my branch.
alias blenm='/home/gavin/Scripts/blender/blender_merge.sh'

# Runs my svd script, which runs an svn diff.
alias svd='/home/gavin/Scripts/blender/svd.sh'

# Changes into my ROOT directory.
alias bdir='cd /home/gavin/Code/blender-svn/'

# Changes into my build directory.
alias budir='cd /home/gavin/Code/blender-svn/build'

# Changes into my source directory.
alias bldir='cd /home/gavin/Code/blender-svn/blender'

# Changes into the Cycles directory.
alias cydir='cd /home/gavin/Code/blender-svn/blender/intern/cycles'

# Changes into my release build directory.
alias redir='cd /home/gavin/Code/blender-svn/release'

# Switches to trunk.
alias strunk='cd /home/gavin/Code/blender-svn/blender; svn switch https://svn.blender.org/svnroot/bf-blender/trunk/blender'

# Switches to my branch.
alias smblur='cd /home/gavin/Code/blender-svn/blender; svn switch https://svn.blender.org/svnroot/bf-blender/branches/soc-2013-cycles_mblur'