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