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