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 15THIRD_PARTY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" 16STAGING_DIR="/tmp/llvm-10-update" 17CLEAN_BRANCH="llvm10-clean" 18SOURCE_DIR="${STAGING_DIR}/llvm" 19TARGET_DIR="${THIRD_PARTY_DIR}/llvm-10.0/llvm" 20LLVM_REPO_BRANCH="release/10.x" 21BUG_NUMBER="b/152339534" 22 23SWIFTSHADER_HEAD=`git rev-parse HEAD` 24 25# Check there are no local changes 26if ! git diff --quiet HEAD; then 27 echo "Git workspace not clean" 28 exit 1 29fi 30 31# Clone or update the staging directory 32if [[ -d "$STAGING_DIR" ]]; then 33 pushd "$STAGING_DIR" 34else 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 42fi 43git pull origin $LLVM_REPO_BRANCH 44LLVM_HEAD=`git log HEAD -n 1 --pretty=format:'%h'` 45popd 46 47if [[ -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 64fi 65 66COMMIT_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. 69git fetch "https://swiftshader.googlesource.com/SwiftShader" $CLEAN_BRANCH 70git checkout FETCH_HEAD 71 72# Delete the target directory. We're going to re-populate it. 73rm -fr "$TARGET_DIR" 74 75# Update SwiftShader's $TARGET_DIR with a clean copy of latest LLVM 76mkdir -p "$TARGET_DIR" 77cp -r "$SOURCE_DIR/." "$TARGET_DIR" 78git add "$TARGET_DIR" 79git commit -m "$COMMIT_MSG" 80MERGE_SOURCE=`git log HEAD -n 1 --pretty=format:'%h'` 81 82# Push llvm-10-clean branch. 83git push "https://swiftshader.googlesource.com/SwiftShader" $CLEAN_BRANCH 84 85# Switch to the branch in use when calling the script. 86git checkout $SWIFTSHADER_HEAD 87 88# Update SwiftShader's $TARGET_DIR with a clean copy of latest LLVM 89git merge -m "$COMMIT_MSG" "$MERGE_SOURCE" 90 91# We're now done with the staging dir. Delete it. 92rm -fr "$STAGING_DIR" 93