blob: 3429b895fc0e708e1c5db8304a2c8624deb6895d [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/usr/bin/env bash
2
3# This script keeps track of all projects that are linked to the llvm src
4# directory. It can detect, enable, disable and map to specific projects,
5# so different builds get to see the source dir as they saw originally.
6
7. llvm-common
8
Diana Picus72189fd2016-05-23 19:32:46 +03009safe_run verify_env
10
Renato Golin94cc1042016-04-26 11:02:23 +010011prog=`basename $0`
12syntax() {
Diana Picusdf02ca02016-05-03 13:44:42 +030013 echo "Syntax: $prog [clang|lldb|lld|rt|libs|all|none] {+/-}[c|x|r|k|d|l|a|u|t]"
14 echo " no args: List linked projects"
15 echo " clang: Clang + Clang Tools Extra"
16 echo " lldb: Clang + lldb"
17 echo " lld: Clang + lld"
18 echo " rt: Clang + compiler-rt"
19 echo " libs: Clang + libcxx + libcxxabi + libunwind"
20 echo " all: Link all projects"
21 echo " none: Unlink all projects"
22 echo " {+/-}: link / unlink projects (default: link)"
23 echo " c Clang"
24 echo " x Clang Tools Extra"
25 echo " r Compiler-rt"
26 echo " k lld"
27 echo " d lldb"
28 echo " l libcxx"
29 echo " a libcxxabi"
30 echo " u libunwind"
31 echo " t test-suite"
32 echo " Long options unlink everything before proceeding. Use the short options for fine-tuning"
Renato Golin94cc1042016-04-26 11:02:23 +010033}
34
35# Dirs and links into LLVM
36clang_dir=clang
37clang_link=tools/clang
Diana Picus3124fb82016-04-25 15:37:25 +030038clang_extra_dir=clang-tools-extra
39clang_extra_link=tools/clang/tools/extra
Renato Golin94cc1042016-04-26 11:02:23 +010040rt_dir=compiler-rt
41rt_link=projects/compiler-rt
42libcxx_dir=libcxx
43libcxx_link=projects/libcxx
44libcxxabi_dir=libcxxabi
45libcxxabi_link=projects/libcxxabi
46libunwind_dir=libunwind
47libunwind_link=projects/libunwind
48lld_dir=lld
49lld_link=tools/lld
50lldb_dir=lldb
51lldb_link=tools/lldb
52tests_dir=test-suite
53tests_link=projects/test-suite
54
55# Check if link exists
Diana Picus72189fd2016-05-23 19:32:46 +030056has_link() {
Renato Golin94cc1042016-04-26 11:02:23 +010057 link=$1
Diana Picus72189fd2016-05-23 19:32:46 +030058 [ -d "$LLVM_SRC/$link" ]
Renato Golin94cc1042016-04-26 11:02:23 +010059}
60
61# Initialise status
62init() {
63 link=$1
Diana Picus72189fd2016-05-23 19:32:46 +030064 if has_link $link; then
65 echo "ON";
Renato Golin94cc1042016-04-26 11:02:23 +010066 else
Diana Picus72189fd2016-05-23 19:32:46 +030067 echo "OFF"
Renato Golin94cc1042016-04-26 11:02:23 +010068 fi
69}
70
71# Link/Unlink upon need
72update() {
73 dir=$1
74 link=$2
75 need=$3
Diana Picus72189fd2016-05-23 19:32:46 +030076 if [ "$need" = ON ]; then
77 if ! has_link $link; then
78 pushdq $LLVM_SRC
79 branch=`get_branch`
80 popdq
81
82 safe_run add_worktree $LLVM_ROOT/repos/$dir $LLVM_SRC/$link $branch
83 fi
Renato Golin94cc1042016-04-26 11:02:23 +010084 else
Diana Picus72189fd2016-05-23 19:32:46 +030085 safe_run remove_worktree $LLVM_ROOT/repos/$dir $LLVM_SRC/$link
Renato Golin94cc1042016-04-26 11:02:23 +010086 fi
87}
88
Diana Picus72189fd2016-05-23 19:32:46 +030089# Enable/disable projects in the CMake cache
90update_build_dirs() {
91 if [ -d $LLVM_BLD/../build ]; then
92 safe_run cmake $* $LLVM_BLD/../build
93 fi
94
95 if [ -d $LLVM_BLD/../debug ]; then
96 safe_run cmake $* $LLVM_BLD/../debug
97 fi
98}
99
100# Lists linked projects
Renato Golin94cc1042016-04-26 11:02:23 +0100101list_all() {
102 echo "Projects linked:"
Diana Picus72189fd2016-05-23 19:32:46 +0300103 has_link $clang_link && echo " + Clang"
104 has_link $clang_extra_link && echo " + Clang Tools Extra"
105 has_link $rt_link && echo " + Compiler-RT"
106 has_link $libcxx_link && echo " + LibC++"
107 has_link $libcxxabi_link && echo " + LibC++abi"
108 has_link $libunwind_link && echo " + LibUnwind"
109 has_link $lld_link && echo " + LLD"
110 has_link $lldb_link && echo " + LLDB"
111 has_link $tests_link && echo " + Test-Suite"
Renato Golin94cc1042016-04-26 11:02:23 +0100112 echo
113}
114
Diana Picusdf02ca02016-05-03 13:44:42 +0300115need_all() {
116 need=$1
117 clang=$need
118 clang_extra=$need
119 rt=$need
120 libcxx=$need
121 libcxxabi=$need
122 libunwind=$need
123 lld=$need
124 lldb=$need
125 tests=$need
126}
127
Renato Golin94cc1042016-04-26 11:02:23 +0100128# No args, list
129if [ "$1" = "" ]; then
130 echo "Use $prog -h for options"
131 echo
132 list_all
133 exit
134fi
135
136# Need/not need
137clang=`init $clang_link`
Diana Picus3124fb82016-04-25 15:37:25 +0300138clang_extra=`init $clang_extra_link`
Renato Golin94cc1042016-04-26 11:02:23 +0100139rt=`init $rt_link`
140libcxx=`init $libcxx_link`
141libcxxabi=`init $libcxxabi_link`
142libunwind=`init $libunwind_link`
143lld=`init $lld_link`
144lldb=`init $lldb_link`
145tests=`init $tests_link`
146
Diana Picusdf02ca02016-05-03 13:44:42 +0300147# See if the first option is one of the long options
148opt=$1
149case $opt in
150 clang)
Diana Picus72189fd2016-05-23 19:32:46 +0300151 need_all OFF
152 clang=ON
153 clang_extra=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300154 shift
155 ;;
156 lldb)
Diana Picus72189fd2016-05-23 19:32:46 +0300157 need_all OFF
158 clang=ON
159 lldb=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300160 shift
161 ;;
162 lld)
Diana Picus72189fd2016-05-23 19:32:46 +0300163 need_all OFF
164 clang=ON
165 lld=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300166 shift
167 ;;
168 rt)
Diana Picus72189fd2016-05-23 19:32:46 +0300169 need_all OFF
170 clang=ON
171 rt=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300172 shift
173 ;;
174 libs)
Diana Picus72189fd2016-05-23 19:32:46 +0300175 need_all OFF
176 clang=ON
177 libcxx=ON
178 libcxxabi=ON
179 libunwind=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300180 shift
181 ;;
182 all)
Diana Picus72189fd2016-05-23 19:32:46 +0300183 need_all ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300184 shift
185 ;;
186 none)
Diana Picus72189fd2016-05-23 19:32:46 +0300187 need_all OFF
Diana Picusdf02ca02016-05-03 13:44:42 +0300188 shift
189 ;;
190 list)
191 list_all
192 exit
193 ;;
194 -h)
195 syntax
196 exit
197 ;;
198esac
199
200# Parse short options, if any
Renato Golin94cc1042016-04-26 11:02:23 +0100201while ! test -z $1; do
202 opt=$1
Diana Picusdf02ca02016-05-03 13:44:42 +0300203
Renato Golin94cc1042016-04-26 11:02:23 +0100204 sign=${opt:0:1}
Diana Picus72189fd2016-05-23 19:32:46 +0300205 flag=ON
Renato Golin94cc1042016-04-26 11:02:23 +0100206 if [ "$sign" = "-" ]; then
Diana Picus72189fd2016-05-23 19:32:46 +0300207 flag=OFF
Renato Golin94cc1042016-04-26 11:02:23 +0100208 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300209 elif [ "$sign" = "+" ]; then
Renato Golin94cc1042016-04-26 11:02:23 +0100210 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300211 else
212 # Doesn't look like one of our short options
213 syntax
214 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100215 fi
216
217 case $opt in
Diana Picusdf02ca02016-05-03 13:44:42 +0300218 c)
Renato Golin94cc1042016-04-26 11:02:23 +0100219 clang=$flag
220 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300221 x)
Diana Picus3124fb82016-04-25 15:37:25 +0300222 clang_extra=$flag
223 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300224 r)
Renato Golin94cc1042016-04-26 11:02:23 +0100225 rt=$flag
226 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300227 k)
Renato Golin94cc1042016-04-26 11:02:23 +0100228 lld=$flag
Diana Picusdf02ca02016-05-03 13:44:42 +0300229 ;;
230 d)
Renato Golin94cc1042016-04-26 11:02:23 +0100231 lldb=$flag
232 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300233 l)
234 libcxx=$flag
235 ;;
236 a)
237 libcxxabi=$flag
238 ;;
239 u)
240 libunwind=$flag
241 ;;
242 t)
Renato Golin94cc1042016-04-26 11:02:23 +0100243 tests=$flag
244 ;;
Renato Golin94cc1042016-04-26 11:02:23 +0100245 *)
246 syntax
Diana Picusdf02ca02016-05-03 13:44:42 +0300247 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100248 esac
249 shift
250done
251
Diana Picusdf02ca02016-05-03 13:44:42 +0300252# clang and clang-tools-extra have a special relationship: we can't enable
253# clang-tools-extra without enabling clang, and we also can't disable clang
254# without also disabling clang-tools-extra
Diana Picus72189fd2016-05-23 19:32:46 +0300255if [ "$clang_extra" = ON -a "$clang" = OFF ]; then
Diana Picusdf02ca02016-05-03 13:44:42 +0300256 echo "Can't have Clang Tools Extra without Clang! Try to add +c or -x"
257 exit
258fi
259
260
Renato Golin94cc1042016-04-26 11:02:23 +0100261# Update links
262update $tests_dir $tests_link $tests
263update $lldb_dir $lldb_link $lldb
264update $lld_dir $lld_link $lld
265update $libunwind_dir $libunwind_link $libunwind
266update $libcxxabi_dir $libcxxabi_link $libcxxabi
267update $libcxx_dir $libcxx_link $libcxx
268update $rt_dir $rt_link $rt
269update $clang_dir $clang_link $clang
Diana Picus3124fb82016-04-25 15:37:25 +0300270update $clang_extra_dir $clang_extra_link $clang_extra
Diana Picus72189fd2016-05-23 19:32:46 +0300271update_build_dirs -DLLVM_TOOL_LLDB_BUILD=$lldb \
272 -DLLVM_TOOL_LLD_BUILD=$lld \
273 -DLLVM_TOOL_LIBUNWIND_BUILD=$libunwind \
274 -DLLVM_TOOL_LIBCXXABI_BUILD=$libcxxabi \
275 -DLLVM_TOOL_LIBCXX_BUILD=$libcxx \
276 -DLLVM_TOOL_COMPILER_RT_BUILD=$rt \
277 -DLLVM_TOOL_CLANG_BUILD=$clang \
278 -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=$clang_extra
Renato Golin94cc1042016-04-26 11:02:23 +0100279list_all