| #!/usr/bin/env bash |
| |
| # This script helps you check which branches are checked out on git and make |
| # sure they're coherent with the feature you're developing. For instance, |
| # if a feature spans across both LLVM and Clang, you could name the branch on |
| # each repo the same and use this script to seamlessly move between them. |
| |
| # Syntax: llvm-branch [-d] [branch] |
| # -d: delete chosen branch |
| # branch: find on llvm and clang and check it out |
| # Without arguments, the script lists all branches and highlight the current one |
| |
| . llvm-common |
| |
| function print_branches() { |
| local current=$1 |
| shift |
| local space=0 |
| for each in $*; do |
| if [[ $space = 1 ]]; then |
| echo -n " " |
| fi |
| if [[ $each = $current ]]; then |
| echo -n "[$each]" |
| else |
| echo -n $each |
| fi |
| space=1 |
| done |
| } |
| |
| function has() { |
| if [[ $1 = '' || $2 = '' ]]; then |
| echo no |
| return |
| fi |
| local item=$1 |
| shift |
| for each in $*; do |
| if [[ $item = $each ]]; then |
| echo yes |
| return |
| fi |
| done |
| echo no |
| } |
| |
| function switch() { |
| SRC=$1 |
| branch=$2 |
| in=$3 |
| if [ -d $SRC ]; then |
| cd $SRC |
| pwd |
| if [[ $in = 'yes' ]]; then |
| if [[ $DEL = '' ]]; then |
| safe_run git checkout $branch |
| else |
| safe_run git checkout master |
| safe_run git branch $DEL $branch |
| fi |
| else |
| if [[ $DEL = '' ]]; then |
| safe_run git checkout master |
| fi |
| fi |
| fi |
| } |
| |
| # Gather info |
| cd $LLVM_SRC |
| llvm_branch=`get_branch` |
| llvm_branches=`get_branches` |
| |
| CLANG_SRC=$LLVM_SRC/tools/clang |
| if [ -d $CLANG_SRC ]; then |
| cd $CLANG_SRC |
| clang_branch=`get_branch` |
| clang_branches=`get_branches` |
| fi |
| |
| CLANG_EXTRA_SRC=$LLVM_SRC/tools/clang/tools/extra |
| if [ -d $CLANG_EXTRA_SRC ]; then |
| cd $CLANG_EXTRA_SRC |
| clang_extra_branch=`get_branch` |
| clang_extra_branches=`get_branches` |
| fi |
| |
| RT_SRC=$LLVM_SRC/projects/compiler-rt |
| if [ -d $RT_SRC ]; then |
| cd $RT_SRC |
| rt_branch=`get_branch` |
| rt_branches=`get_branches` |
| fi |
| |
| CXX_SRC=$LLVM_SRC/projects/libcxx |
| if [ -d $CXX_SRC ]; then |
| cd $CXX_SRC |
| cxx_branch=`get_branch` |
| cxx_branches=`get_branches` |
| fi |
| |
| CXXABI_SRC=$LLVM_SRC/projects/libcxxabi |
| if [ -d $CXXABI_SRC ]; then |
| cd $CXXABI_SRC |
| cxxabi_branch=`get_branch` |
| cxxabi_branches=`get_branches` |
| fi |
| |
| UNW_SRC=$LLVM_SRC/projects/libunwind |
| if [ -d $UNW_SRC ]; then |
| cd $UNW_SRC |
| unw_branch=`get_branch` |
| unw_branches=`get_branches` |
| fi |
| |
| LLD_SRC=$LLVM_SRC/tools/lld |
| if [ -d $LLD_SRC ]; then |
| cd $LLD_SRC |
| lld_branch=`get_branch` |
| lld_branches=`get_branches` |
| fi |
| |
| LLDB_SRC=$LLVM_SRC/tools/lldb |
| if [ -d $LLDB_SRC ]; then |
| cd $LLDB_SRC |
| lldb_branch=`get_branch` |
| lldb_branches=`get_branches` |
| fi |
| |
| # Delete chosen branch |
| DEL='' |
| if [[ $1 = '-d' || $1 = '-D' ]]; then |
| DEL=$1 |
| shift |
| fi |
| |
| # No branch chosen, list all |
| if [[ $1 = '' ]]; then |
| echo -n "LLVM branches: " |
| print_branches $llvm_branch $llvm_branches |
| echo |
| if [ -d $CLANG_SRC ]; then |
| echo -n "Clang branches: " |
| print_branches $clang_branch $clang_branches |
| echo |
| fi |
| if [ -d $CLANG_EXTRA_SRC ]; then |
| echo -n "Clang tools extra branches: " |
| print_branches $clang_extra_branch $clang_extra_branches |
| echo |
| fi |
| if [ -d $RT_SRC ]; then |
| echo -n "Compiler-RT branches: " |
| print_branches $rt_branch $rt_branches |
| echo |
| fi |
| if [ -d $CXX_SRC ]; then |
| echo -n "LibC++ branches: " |
| print_branches $cxx_branch $cxx_branches |
| echo |
| fi |
| if [ -d $CXXABI_SRC ]; then |
| echo -n "LibC++ABI branches: " |
| print_branches $cxxabi_branch $cxxabi_branches |
| echo |
| fi |
| if [ -d $UNW_SRC ]; then |
| echo -n "LibUnwind branches: " |
| print_branches $unw_branch $unw_branches |
| echo |
| fi |
| if [ -d $LLD_SRC ]; then |
| echo -n "LLD branches: " |
| print_branches $lld_branch $lld_branches |
| echo |
| fi |
| if [ -d $LLDB_SRC ]; then |
| echo -n "LLDB branches: " |
| print_branches $lldb_branch $lldb_branches |
| echo |
| fi |
| exit |
| fi |
| |
| # Search for branch name |
| branch=$1 |
| |
| if [[ $DEL = 1 && $branch = 'master' ]]; then |
| echo "Cannot delete the master branch" |
| exit 1 |
| fi |
| |
| # Check which projects the branch is |
| in_llvm=`has $branch $llvm_branches` |
| in_clang=`has $branch $clang_branches` |
| in_clang_extra=`has $branch $clang_extra_branches` |
| in_rt=`has $branch $rt_branches` |
| in_cxx=`has $branch $cxx_branches` |
| in_cxxabi=`has $branch $cxxabi_branches` |
| in_unw=`has $branch $unw_branches` |
| in_lld=`has $branch $lld_branches` |
| in_lldb=`has $branch $lldb_branches` |
| if [[ $in_clang = 'no' && $in_clang_extra && $in_llvm = 'no' && \ |
| $in_rt = 'no' && $in_cxx = 'no' && $in_cxxabi = 'no' && \ |
| $in_unw = 'no' && $in_lld = 'no' && $in_lldb = 'no' ]]; then |
| echo "Branch $branch doesn't exist on any repository" |
| exit 1 |
| fi |
| |
| # DO IT |
| switch $LLVM_SRC $branch $in_llvm |
| switch $CLANG_SRC $branch $in_clang |
| switch $CLANG_EXTRA_SRC $branch $in_clang_extra |
| switch $RT_SRC $branch $in_rt |
| switch $CXX_SRC $branch $in_cxx |
| switch $CXXABI_SRC $branch $in_cxxabi |
| switch $UNW_SRC $branch $in_unw |
| switch $LLD_SRC $branch $in_lld |
| switch $LLDB_SRC $branch $in_lldb |