blob: ecc9d0e2cc477060601abe5976f5509da19bcd35 [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"
Renato Golin000477d2018-03-01 18:03:55 +000015 echo " clang: Clang"
Diana Picusdf02ca02016-05-03 13:44:42 +030016 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"
Diana Picusdf02ca02016-05-03 13:44:42 +030024 echo " r Compiler-rt"
25 echo " k lld"
26 echo " d lldb"
27 echo " l libcxx"
28 echo " a libcxxabi"
29 echo " u libunwind"
30 echo " t test-suite"
31 echo " Long options unlink everything before proceeding. Use the short options for fine-tuning"
Renato Golin94cc1042016-04-26 11:02:23 +010032}
33
34# Dirs and links into LLVM
35clang_dir=clang
36clang_link=tools/clang
37rt_dir=compiler-rt
38rt_link=projects/compiler-rt
39libcxx_dir=libcxx
40libcxx_link=projects/libcxx
41libcxxabi_dir=libcxxabi
42libcxxabi_link=projects/libcxxabi
43libunwind_dir=libunwind
44libunwind_link=projects/libunwind
45lld_dir=lld
46lld_link=tools/lld
47lldb_dir=lldb
48lldb_link=tools/lldb
49tests_dir=test-suite
50tests_link=projects/test-suite
51
52# Check if link exists
Diana Picus72189fd2016-05-23 19:32:46 +030053has_link() {
Renato Golin94cc1042016-04-26 11:02:23 +010054 link=$1
Diana Picus72189fd2016-05-23 19:32:46 +030055 [ -d "$LLVM_SRC/$link" ]
Renato Golin94cc1042016-04-26 11:02:23 +010056}
57
58# Initialise status
59init() {
60 link=$1
Diana Picus72189fd2016-05-23 19:32:46 +030061 if has_link $link; then
62 echo "ON";
Renato Golin94cc1042016-04-26 11:02:23 +010063 else
Diana Picus72189fd2016-05-23 19:32:46 +030064 echo "OFF"
Renato Golin94cc1042016-04-26 11:02:23 +010065 fi
66}
67
68# Link/Unlink upon need
69update() {
70 dir=$1
71 link=$2
72 need=$3
Diana Picus72189fd2016-05-23 19:32:46 +030073 if [ "$need" = ON ]; then
74 if ! has_link $link; then
75 pushdq $LLVM_SRC
76 branch=`get_branch`
77 popdq
78
79 safe_run add_worktree $LLVM_ROOT/repos/$dir $LLVM_SRC/$link $branch
80 fi
Renato Golin94cc1042016-04-26 11:02:23 +010081 else
Diana Picus72189fd2016-05-23 19:32:46 +030082 safe_run remove_worktree $LLVM_ROOT/repos/$dir $LLVM_SRC/$link
Renato Golin94cc1042016-04-26 11:02:23 +010083 fi
84}
85
Diana Picus72189fd2016-05-23 19:32:46 +030086# Enable/disable projects in the CMake cache
87update_build_dirs() {
88 if [ -d $LLVM_BLD/../build ]; then
89 safe_run cmake $* $LLVM_BLD/../build
90 fi
91
92 if [ -d $LLVM_BLD/../debug ]; then
93 safe_run cmake $* $LLVM_BLD/../debug
94 fi
95}
96
97# Lists linked projects
Renato Golin94cc1042016-04-26 11:02:23 +010098list_all() {
99 echo "Projects linked:"
Diana Picus72189fd2016-05-23 19:32:46 +0300100 has_link $clang_link && echo " + Clang"
Diana Picus72189fd2016-05-23 19:32:46 +0300101 has_link $rt_link && echo " + Compiler-RT"
102 has_link $libcxx_link && echo " + LibC++"
103 has_link $libcxxabi_link && echo " + LibC++abi"
104 has_link $libunwind_link && echo " + LibUnwind"
105 has_link $lld_link && echo " + LLD"
106 has_link $lldb_link && echo " + LLDB"
107 has_link $tests_link && echo " + Test-Suite"
Renato Golin94cc1042016-04-26 11:02:23 +0100108 echo
109}
110
Diana Picusdf02ca02016-05-03 13:44:42 +0300111need_all() {
112 need=$1
113 clang=$need
Diana Picusdf02ca02016-05-03 13:44:42 +0300114 rt=$need
115 libcxx=$need
116 libcxxabi=$need
117 libunwind=$need
118 lld=$need
119 lldb=$need
120 tests=$need
121}
122
Renato Golin94cc1042016-04-26 11:02:23 +0100123# No args, list
124if [ "$1" = "" ]; then
125 echo "Use $prog -h for options"
126 echo
127 list_all
128 exit
129fi
130
131# Need/not need
132clang=`init $clang_link`
133rt=`init $rt_link`
134libcxx=`init $libcxx_link`
135libcxxabi=`init $libcxxabi_link`
136libunwind=`init $libunwind_link`
137lld=`init $lld_link`
138lldb=`init $lldb_link`
139tests=`init $tests_link`
140
Diana Picusdf02ca02016-05-03 13:44:42 +0300141# See if the first option is one of the long options
142opt=$1
143case $opt in
144 clang)
Diana Picus72189fd2016-05-23 19:32:46 +0300145 need_all OFF
146 clang=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300147 shift
148 ;;
149 lldb)
Diana Picus72189fd2016-05-23 19:32:46 +0300150 need_all OFF
151 clang=ON
152 lldb=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300153 shift
154 ;;
155 lld)
Diana Picus72189fd2016-05-23 19:32:46 +0300156 need_all OFF
157 clang=ON
158 lld=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300159 shift
160 ;;
161 rt)
Diana Picus72189fd2016-05-23 19:32:46 +0300162 need_all OFF
163 clang=ON
164 rt=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300165 shift
166 ;;
167 libs)
Diana Picus72189fd2016-05-23 19:32:46 +0300168 need_all OFF
169 clang=ON
170 libcxx=ON
171 libcxxabi=ON
172 libunwind=ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300173 shift
174 ;;
175 all)
Diana Picus72189fd2016-05-23 19:32:46 +0300176 need_all ON
Diana Picusdf02ca02016-05-03 13:44:42 +0300177 shift
178 ;;
179 none)
Diana Picus72189fd2016-05-23 19:32:46 +0300180 need_all OFF
Diana Picusdf02ca02016-05-03 13:44:42 +0300181 shift
182 ;;
183 list)
184 list_all
185 exit
186 ;;
187 -h)
188 syntax
189 exit
190 ;;
191esac
192
193# Parse short options, if any
Renato Golin94cc1042016-04-26 11:02:23 +0100194while ! test -z $1; do
195 opt=$1
Diana Picusdf02ca02016-05-03 13:44:42 +0300196
Renato Golin94cc1042016-04-26 11:02:23 +0100197 sign=${opt:0:1}
Diana Picus72189fd2016-05-23 19:32:46 +0300198 flag=ON
Renato Golin94cc1042016-04-26 11:02:23 +0100199 if [ "$sign" = "-" ]; then
Diana Picus72189fd2016-05-23 19:32:46 +0300200 flag=OFF
Renato Golin94cc1042016-04-26 11:02:23 +0100201 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300202 elif [ "$sign" = "+" ]; then
Renato Golin94cc1042016-04-26 11:02:23 +0100203 opt=${opt:1}
Diana Picusdf02ca02016-05-03 13:44:42 +0300204 else
205 # Doesn't look like one of our short options
206 syntax
207 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100208 fi
209
210 case $opt in
Diana Picusdf02ca02016-05-03 13:44:42 +0300211 c)
Renato Golin94cc1042016-04-26 11:02:23 +0100212 clang=$flag
213 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300214 r)
Renato Golin94cc1042016-04-26 11:02:23 +0100215 rt=$flag
216 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300217 k)
Renato Golin94cc1042016-04-26 11:02:23 +0100218 lld=$flag
Diana Picusdf02ca02016-05-03 13:44:42 +0300219 ;;
220 d)
Renato Golin94cc1042016-04-26 11:02:23 +0100221 lldb=$flag
222 ;;
Diana Picusdf02ca02016-05-03 13:44:42 +0300223 l)
224 libcxx=$flag
225 ;;
226 a)
227 libcxxabi=$flag
228 ;;
229 u)
230 libunwind=$flag
231 ;;
232 t)
Renato Golin94cc1042016-04-26 11:02:23 +0100233 tests=$flag
234 ;;
Renato Golin94cc1042016-04-26 11:02:23 +0100235 *)
236 syntax
Diana Picusdf02ca02016-05-03 13:44:42 +0300237 exit
Renato Golin94cc1042016-04-26 11:02:23 +0100238 esac
239 shift
240done
241
242# Update links
243update $tests_dir $tests_link $tests
244update $lldb_dir $lldb_link $lldb
245update $lld_dir $lld_link $lld
246update $libunwind_dir $libunwind_link $libunwind
247update $libcxxabi_dir $libcxxabi_link $libcxxabi
248update $libcxx_dir $libcxx_link $libcxx
249update $rt_dir $rt_link $rt
250update $clang_dir $clang_link $clang
Diana Picus72189fd2016-05-23 19:32:46 +0300251update_build_dirs -DLLVM_TOOL_LLDB_BUILD=$lldb \
252 -DLLVM_TOOL_LLD_BUILD=$lld \
253 -DLLVM_TOOL_LIBUNWIND_BUILD=$libunwind \
254 -DLLVM_TOOL_LIBCXXABI_BUILD=$libcxxabi \
255 -DLLVM_TOOL_LIBCXX_BUILD=$libcxx \
256 -DLLVM_TOOL_COMPILER_RT_BUILD=$rt \
257 -DLLVM_TOOL_CLANG_BUILD=$clang \
Renato Golin94cc1042016-04-26 11:02:23 +0100258list_all