Skip to content

Instantly share code, notes, and snippets.

@troystribling
Last active July 4, 2016 18:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troystribling/ef2f836c6aff455e956db0ccc1e8d3d0 to your computer and use it in GitHub Desktop.
Save troystribling/ef2f836c6aff455e956db0ccc1e8d3d0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Build open source Swift in a specified directory after cloning the appropriate Github repos.
# Select an alternative Github account (such as hpux735 for William Dillon's forks) to clone swift, swift-llvm, swift-lldb, and swift-corelibs-foundation repos from.
ALTREPO="apple"
# Interval for collecting vmstat, df, and CPU temperature data
STATINTERVAL=300
DATE=$(date +%F)
BUILDDIR=$(pwd)/$1
# Uncommment for a preset-based build
PRESET="buildbot_linux_armv7"
BUILDCOMMAND="swift/utils/build-script --preset=$PRESET install_destdir=$BUILDDIR/dest installable_package=$BUILDDIR/swift-$DATE.tar.gz"
# Uncomment to specify build script options individually
# BUILDCOMMAND="swift/utils/build-script --no-assertions --no-swift-stdlib-assertions --llbuild --xctest --lldb --release --foundation -- --swift-enable-ast-verifier=0 --install-swift --install-lldb --install-llbuild --install-xctest --install-foundation --install-prefix=/usr '--swift-install-components=compiler;clang-builtin-headers;stdlib;sdk-overlay;dev' --build-swift-static-stdlib=1 --skip-test-lldb=1 --install-destdir=$BUILDDIR/dest --installable-package=$BUILDDIR/swift-$DATE.tar.gz --reconfigure"
################################################################
# End of configuration
################################################################
################################################################
# Functions to clean things up on exit
################################################################
#
# We need to explicitly kill vmstat on Ctrl-C. Our loops will stop automatically
kill_vmstat()
{
kill $VMSTATPID
echo
exit 130
}
# Shutdown processes collecting system statistics
# For our while loops we actually need to kill the subprocesses as well (see http://stackoverflow.com/a/4452488 )
kill_all_stats()
{
DFCHILDPID=$(ps --ppid $DFPID -o pid --no-heading)
CPUTEMPCHILDPID=$(ps --ppid $CPUTEMPPID -o pid --no-heading)
kill $VMSTATPID $DFPID $DFCHILDPID $CPUTEMPPID $CPUTEMPCHILDPID
}
################################################################
# Script body
################################################################
# Some sanity checks
if [[ $# -eq 0 ]] ; then
echo "Usage: $(basename $BASH_SOURCE) [build directory]"
exit 1
fi
if [ -d $1 ]; then
echo "Build directory already exists. Please specify a new directory."
exit 1
fi
# Create build directory
echo "Creating build directory $BUILDDIR"
echo
mkdir -p $BUILDDIR/dest
cd $BUILDDIR
echo "ALTREPO: $ALTREPO"
echo
echo "BUILDCOMMAND:"
echo $BUILDCOMMAND
echo
echo "Starting build"
echo "--------------------"
# Start collecting statistics
vmstat $STATINTERVAL >> swift-build-vmstats-$DATE &
VMSTATPID=$!
(while df -h --output=avail / >> swift-build-df-$DATE; do sleep $STATINTERVAL; done; )&
DFPID=$!
(while cat /sys/class/thermal/thermal_zone0/temp >> swift-build-cputemp-$DATE; do sleep $STATINTERVAL; done; )&
CPUTEMPPID=$!
# Disown sub-processes so we don't get debugging messages when they're killed (see http://stackoverflow.com/a/23645819 )
disown $VMSTATPID $DFPID $CPUTEMPPID
# Make sure vmstat gets killed on Ctrl-C
trap kill_vmstat SIGINT
# Clone repos
git clone https://github.com/$ALTREPO/swift.git swift
git clone https://github.com/$ALTREPO/swift-llvm.git llvm
git clone https://github.com/apple/swift-clang.git clang
git clone https://github.com/$ALTREPO/swift-lldb.git lldb
git clone https://github.com/apple/swift-cmark.git cmark
git clone https://github.com/apple/swift-llbuild.git llbuild
git clone https://github.com/apple/swift-package-manager.git swiftpm
git clone https://github.com/apple/swift-corelibs-xctest.git
git clone https://github.com/$ALTREPO/swift-corelibs-foundation.git
time eval $BUILDCOMMAND
kill_all_stats
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment