Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/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 Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 9 | safe_run verify_env |
| 10 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 11 | prog=`basename $0` |
| 12 | syntax() { |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 13 | 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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | # Dirs and links into LLVM |
| 36 | clang_dir=clang |
| 37 | clang_link=tools/clang |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 38 | clang_extra_dir=clang-tools-extra |
| 39 | clang_extra_link=tools/clang/tools/extra |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 40 | rt_dir=compiler-rt |
| 41 | rt_link=projects/compiler-rt |
| 42 | libcxx_dir=libcxx |
| 43 | libcxx_link=projects/libcxx |
| 44 | libcxxabi_dir=libcxxabi |
| 45 | libcxxabi_link=projects/libcxxabi |
| 46 | libunwind_dir=libunwind |
| 47 | libunwind_link=projects/libunwind |
| 48 | lld_dir=lld |
| 49 | lld_link=tools/lld |
| 50 | lldb_dir=lldb |
| 51 | lldb_link=tools/lldb |
| 52 | tests_dir=test-suite |
| 53 | tests_link=projects/test-suite |
| 54 | |
| 55 | # Check if link exists |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 56 | has_link() { |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 57 | link=$1 |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 58 | [ -d "$LLVM_SRC/$link" ] |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | # Initialise status |
| 62 | init() { |
| 63 | link=$1 |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 64 | if has_link $link; then |
| 65 | echo "ON"; |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 66 | else |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 67 | echo "OFF" |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 68 | fi |
| 69 | } |
| 70 | |
| 71 | # Link/Unlink upon need |
| 72 | update() { |
| 73 | dir=$1 |
| 74 | link=$2 |
| 75 | need=$3 |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 76 | 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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 84 | else |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 85 | safe_run remove_worktree $LLVM_ROOT/repos/$dir $LLVM_SRC/$link |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 86 | fi |
| 87 | } |
| 88 | |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 89 | # Enable/disable projects in the CMake cache |
| 90 | update_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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 101 | list_all() { |
| 102 | echo "Projects linked:" |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 103 | 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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 112 | echo |
| 113 | } |
| 114 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 115 | need_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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 128 | # No args, list |
| 129 | if [ "$1" = "" ]; then |
| 130 | echo "Use $prog -h for options" |
| 131 | echo |
| 132 | list_all |
| 133 | exit |
| 134 | fi |
| 135 | |
| 136 | # Need/not need |
| 137 | clang=`init $clang_link` |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 138 | clang_extra=`init $clang_extra_link` |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 139 | rt=`init $rt_link` |
| 140 | libcxx=`init $libcxx_link` |
| 141 | libcxxabi=`init $libcxxabi_link` |
| 142 | libunwind=`init $libunwind_link` |
| 143 | lld=`init $lld_link` |
| 144 | lldb=`init $lldb_link` |
| 145 | tests=`init $tests_link` |
| 146 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 147 | # See if the first option is one of the long options |
| 148 | opt=$1 |
| 149 | case $opt in |
| 150 | clang) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 151 | need_all OFF |
| 152 | clang=ON |
| 153 | clang_extra=ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 154 | shift |
| 155 | ;; |
| 156 | lldb) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 157 | need_all OFF |
| 158 | clang=ON |
| 159 | lldb=ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 160 | shift |
| 161 | ;; |
| 162 | lld) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 163 | need_all OFF |
| 164 | clang=ON |
| 165 | lld=ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 166 | shift |
| 167 | ;; |
| 168 | rt) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 169 | need_all OFF |
| 170 | clang=ON |
| 171 | rt=ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 172 | shift |
| 173 | ;; |
| 174 | libs) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 175 | need_all OFF |
| 176 | clang=ON |
| 177 | libcxx=ON |
| 178 | libcxxabi=ON |
| 179 | libunwind=ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 180 | shift |
| 181 | ;; |
| 182 | all) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 183 | need_all ON |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 184 | shift |
| 185 | ;; |
| 186 | none) |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 187 | need_all OFF |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 188 | shift |
| 189 | ;; |
| 190 | list) |
| 191 | list_all |
| 192 | exit |
| 193 | ;; |
| 194 | -h) |
| 195 | syntax |
| 196 | exit |
| 197 | ;; |
| 198 | esac |
| 199 | |
| 200 | # Parse short options, if any |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 201 | while ! test -z $1; do |
| 202 | opt=$1 |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 203 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 204 | sign=${opt:0:1} |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 205 | flag=ON |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 206 | if [ "$sign" = "-" ]; then |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 207 | flag=OFF |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 208 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 209 | elif [ "$sign" = "+" ]; then |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 210 | opt=${opt:1} |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 211 | else |
| 212 | # Doesn't look like one of our short options |
| 213 | syntax |
| 214 | exit |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 215 | fi |
| 216 | |
| 217 | case $opt in |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 218 | c) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 219 | clang=$flag |
| 220 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 221 | x) |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 222 | clang_extra=$flag |
| 223 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 224 | r) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 225 | rt=$flag |
| 226 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 227 | k) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 228 | lld=$flag |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 229 | ;; |
| 230 | d) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 231 | lldb=$flag |
| 232 | ;; |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 233 | l) |
| 234 | libcxx=$flag |
| 235 | ;; |
| 236 | a) |
| 237 | libcxxabi=$flag |
| 238 | ;; |
| 239 | u) |
| 240 | libunwind=$flag |
| 241 | ;; |
| 242 | t) |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 243 | tests=$flag |
| 244 | ;; |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 245 | *) |
| 246 | syntax |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 247 | exit |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 248 | esac |
| 249 | shift |
| 250 | done |
| 251 | |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 252 | # 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 Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 255 | if [ "$clang_extra" = ON -a "$clang" = OFF ]; then |
Diana Picus | df02ca0 | 2016-05-03 13:44:42 +0300 | [diff] [blame] | 256 | echo "Can't have Clang Tools Extra without Clang! Try to add +c or -x" |
| 257 | exit |
| 258 | fi |
| 259 | |
| 260 | |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 261 | # Update links |
| 262 | update $tests_dir $tests_link $tests |
| 263 | update $lldb_dir $lldb_link $lldb |
| 264 | update $lld_dir $lld_link $lld |
| 265 | update $libunwind_dir $libunwind_link $libunwind |
| 266 | update $libcxxabi_dir $libcxxabi_link $libcxxabi |
| 267 | update $libcxx_dir $libcxx_link $libcxx |
| 268 | update $rt_dir $rt_link $rt |
| 269 | update $clang_dir $clang_link $clang |
Diana Picus | 3124fb8 | 2016-04-25 15:37:25 +0300 | [diff] [blame] | 270 | update $clang_extra_dir $clang_extra_link $clang_extra |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame^] | 271 | update_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 Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 279 | list_all |