Ben Clayton | 088add4 | 2020-03-25 12:40:18 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # llvm now lives in a mono-repo along with clang, libc, lldb and a whole bunch |
| 4 | # of other projects (~90k files at time of writing). |
| 5 | # SwiftShader only requires the llvm project from this repo, and does not wish |
| 6 | # to pull in everything else. |
| 7 | # This script performs the following: |
| 8 | # * The llvm10-clean branch is fetched and checked out. |
| 9 | # * A sparse checkout of the llvm project is made to a temporary directory. |
| 10 | # * The third_party/llvm-10.0/llvm is replaced with the latest LLVM version. |
| 11 | # * This is committed and pushed. |
| 12 | # * The original branch is checked out again, and a merge from llvm10-clean to |
| 13 | # the original branch is made. |
| 14 | |
| 15 | THIRD_PARTY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" |
| 16 | STAGING_DIR="/tmp/llvm-10-update" |
| 17 | CLEAN_BRANCH="llvm10-clean" |
| 18 | SOURCE_DIR="${STAGING_DIR}/llvm" |
| 19 | TARGET_DIR="${THIRD_PARTY_DIR}/llvm-10.0/llvm" |
| 20 | LLVM_REPO_BRANCH="release/10.x" |
| 21 | BUG_NUMBER="b/152339534" |
| 22 | |
| 23 | SWIFTSHADER_HEAD=`git rev-parse HEAD` |
| 24 | |
| 25 | # Check there are no local changes |
| 26 | if ! git diff --quiet HEAD; then |
| 27 | echo "Git workspace not clean" |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | # Clone or update the staging directory |
| 32 | if [[ -d "$STAGING_DIR" ]]; then |
| 33 | pushd "$STAGING_DIR" |
| 34 | else |
| 35 | mkdir "$STAGING_DIR" |
| 36 | pushd "$STAGING_DIR" |
| 37 | git init |
| 38 | git remote add origin https://github.com/llvm/llvm-project.git |
| 39 | git config core.sparsecheckout true |
| 40 | echo "/llvm/lib" >> .git/info/sparse-checkout |
| 41 | echo "/llvm/include" >> .git/info/sparse-checkout |
| 42 | fi |
| 43 | git pull origin $LLVM_REPO_BRANCH |
| 44 | LLVM_HEAD=`git log HEAD -n 1 --pretty=format:'%h'` |
| 45 | popd |
| 46 | |
| 47 | if [[ -d "$TARGET_DIR" ]]; then |
| 48 | # Look for the last update change. |
| 49 | LAST_TARGET_UPDATE=`git log --grep="^llvm-10-update: [0-9a-f]\{9\}$" -n 1 --pretty=format:'%h' ${TARGET_DIR}` |
| 50 | if [[ ! -z "$LAST_TARGET_UPDATE" ]]; then |
| 51 | # Get the LLVM commit hash from the update change. |
| 52 | LAST_SOURCE_UPDATE=`git log $LAST_TARGET_UPDATE -n 1 | grep -oP "llvm-10-update: \K([0-9a-f]{9})"` |
| 53 | if [ $LLVM_HEAD == $LAST_SOURCE_UPDATE ]; then |
| 54 | echo "No new LLVM changes to apply" |
| 55 | exit 0 |
| 56 | fi |
| 57 | |
| 58 | # Gather list of changes since last update |
| 59 | pushd "$STAGING_DIR" |
| 60 | LLVM_CHANGE_LOG=`git log $LAST_SOURCE_UPDATE..$LLVM_HEAD --pretty=format:' %h %s'` |
| 61 | LLVM_CHANGE_LOG="Changes:\n${LLVM_CHANGE_LOG}\n\n" |
| 62 | popd |
| 63 | fi |
| 64 | fi |
| 65 | |
| 66 | COMMIT_MSG=`echo -e "Update LLVM 10 to ${LLVM_HEAD}\n\n${LLVM_CHANGE_LOG}Commands:\n third_party/update-llvm-10.sh\n\nllvm-10-update: ${LLVM_HEAD}\nBug: ${BUG_NUMBER}"` |
| 67 | |
| 68 | # Switch to the llvm-10-clean branch. |
| 69 | git fetch "https://swiftshader.googlesource.com/SwiftShader" $CLEAN_BRANCH |
| 70 | git checkout FETCH_HEAD |
| 71 | |
| 72 | # Delete the target directory. We're going to re-populate it. |
| 73 | rm -fr "$TARGET_DIR" |
| 74 | |
| 75 | # Update SwiftShader's $TARGET_DIR with a clean copy of latest LLVM |
| 76 | mkdir -p "$TARGET_DIR" |
| 77 | cp -r "$SOURCE_DIR/." "$TARGET_DIR" |
| 78 | git add "$TARGET_DIR" |
| 79 | git commit -m "$COMMIT_MSG" |
| 80 | MERGE_SOURCE=`git log HEAD -n 1 --pretty=format:'%h'` |
| 81 | |
| 82 | # Push llvm-10-clean branch. |
| 83 | git push "https://swiftshader.googlesource.com/SwiftShader" $CLEAN_BRANCH |
| 84 | |
| 85 | # Switch to the branch in use when calling the script. |
| 86 | git checkout $SWIFTSHADER_HEAD |
| 87 | |
| 88 | # Update SwiftShader's $TARGET_DIR with a clean copy of latest LLVM |
| 89 | git merge -m "$COMMIT_MSG" "$MERGE_SOURCE" |
| 90 | |
| 91 | # We're now done with the staging dir. Delete it. |
| 92 | rm -fr "$STAGING_DIR" |