blob: 98a95047db7fc861fbe678d6e7154bf555f274d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
#!/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
|