Skip to content

Instantly share code, notes, and snippets.

@Qix-
Last active April 9, 2018 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qix-/9ddbd430335a04296ccf8e3bd42dda8d to your computer and use it in GitHub Desktop.
Save Qix-/9ddbd430335a04296ccf8e3bd42dda8d to your computer and use it in GitHub Desktop.
LLVM Release Switcher
#!/usr/bin/env bash
set -e
function log {
echo -e "\x1b[36;1m""$@""\x1b[m"
}
function log2 {
echo -e "\x1b[36;2m""$@""\x1b[m"
}
cd "$(dirname "${0}")"
re='^[0-9]+$'
if ! [[ "$1" =~ $re ]]; then
echo "usage: ${0} <release_number>" >&2
echo "error: invalid release number: ${1}" >&2
exit 2
fi
RELEASE="${1}"
RELEASE_BRANCH="release_${RELEASE}"
log "Selected release ${RELEASE} (branch '${RELEASE_BRANCH}')"
function get_release {
if [[ ! -z "${1}" ]] && [[ ! -z "${2}" ]] && [[ ! -d "${2}" ]]; then
log2 "cloning ${1} into ${2}"
git clone --recursive -b "${RELEASE_BRANCH}" --depth=1 "${1}" "${2}"
log2 'listing branches'
git branch
log2 'done'
return $?
fi
cd "${2}"
if git checkout -b "${RELEASE_BRANCH}" 2>/dev/null; then
log2 'branch already created'
git checkout "${RELEASE_BRANCH}"
fi
log2 'fetching release'
git fetch --depth=1 origin "${RELEASE_BRANCH}"
log2 'hard resetting'
git reset --hard FETCH_HEAD
log2 'updating submodules'
git submodule update --init --recursive
git submodule foreach git pull origin "${RELEASE_BRANCH}"
log2 'listing branches'
git branch --list --color=always | cat
log2 'done'
cd -
}
log 'updating base release...'
get_release
log 'updating clang...'
get_release 'https://github.com/llvm-mirror/clang.git' tools/clang
log 'updating clang extras...'
get_release 'https://github.com/llvm-mirror/clang-tools-extra.git' tools/clang/tools/extra
log 'updating compiler-rt...'
get_release 'https://github.com/llvm-mirror/compiler-rt.git' projects/compiler-rt
log 'updating libcxx...'
get_release 'https://github.com/llvm-mirror/libcxx.git' projects/libcxx
if [[ -d build ]]; then
log 'cleaning build directory'
rm -rf build
fi
if ! command -v ninja > /dev/null && [[ "$(uname)" == "Darwin" ]] || [[ "$(uname)" == "Linux" ]]; then
read -p "Would you like to speed up builds by installing Ninja (optional)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "\x1b[32;1mThe system may ask for your password\!\x1b[m"
(
case "$(uname)" in
Darwin) brew install ninja; brew link ninja ;;
Linux) sudo apt-get install -y ninja ;;
*) exit 1;
esac
) || log2 "Could not install Ninja for you; you can try doing it manually and then re-run this script."
fi
fi
log 'initializing CMake'
mkdir -p build
if command -v ninja > /dev/null; then
(cd build && cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=lld)
else
(cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=lld)
fi
log 'building...'
if command -v ninja > /dev/null; then
(cd build && ninja)
else
cmake --build build
fi
log 'SUCCESS'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment