Alan Viverette | a693ece | 2020-11-17 16:23:42 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Alan Viverette | a693ece | 2020-11-17 16:23:42 -0500 | [diff] [blame] | 2 | |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 3 | function usage() { |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 4 | echo "Usage: studiow [--clear-caches] [--clean] [--reinstall] [--profile] <project subset>" |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 5 | echo |
| 6 | echo "OPTIONS" |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 7 | echo |
| 8 | echo " --clear-caches" |
| 9 | echo " Clear generated caches (but not user settings) before launching" |
| 10 | echo |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 11 | echo " --clean" |
| 12 | echo " Clear (with backup) generated files (settings, caches, etc) before launching" |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 13 | echo " Also implies --clear-caches" |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 14 | echo |
| 15 | echo " --reinstall" |
| 16 | echo " Remove and re-download Studio itself. Also implies --clean" |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 17 | echo |
Jeff Gaston | 616585c | 2021-12-10 12:27:27 -0500 | [diff] [blame] | 18 | echo " --profile" |
| 19 | echo " Enables profiling of Studio" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 20 | echo |
| 21 | echo "Project subsets:" |
| 22 | echo " m, main" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 23 | echo " Open the project subset main: non-Compose Jetpack libraries" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 24 | echo |
| 25 | echo " c, compose" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 26 | echo " Open the project subset compose" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 27 | echo |
Aurimas Liutikas | bf1dfd4 | 2022-07-06 13:35:35 -0700 | [diff] [blame] | 28 | echo " ca, camera" |
| 29 | echo " Open the project subset camera" |
| 30 | echo |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 31 | echo " f, flan" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 32 | echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 33 | echo |
Gyumin Sim | ff92d18 | 2021-02-02 19:27:59 +0900 | [diff] [blame] | 34 | echo " media" |
| 35 | echo " Open the project subset media: Media, Media2, and MediaRouter" |
| 36 | echo |
Yigit Boyar | f08b9a0 | 2022-06-02 09:16:59 -0700 | [diff] [blame] | 37 | echo " kmp" |
| 38 | echo " Open the project subset KMP: Projects that have KMP builds" |
| 39 | echo |
Flavio Lerda | 726911b | 2021-01-18 18:15:06 +0000 | [diff] [blame] | 40 | echo " w, wear" |
| 41 | echo " Open the project subset for Wear OS libraries" |
| 42 | echo |
Zak Cohen | b87e89a | 2022-02-18 14:24:13 -0800 | [diff] [blame] | 43 | echo " g, glance" |
| 44 | echo " Open the project subset for glance projects" |
| 45 | echo |
Fred Sladkey | e82df61 | 2022-07-14 14:50:36 -0400 | [diff] [blame] | 46 | echo |
| 47 | echo " native" |
Fred Sladkey | 8478a14 | 2022-08-30 17:27:22 -0400 | [diff] [blame] | 48 | echo " Open the project subset for native projects" |
Fred Sladkey | e82df61 | 2022-07-14 14:50:36 -0400 | [diff] [blame] | 49 | echo |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 50 | echo " a, all" |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 51 | echo " Open the project subset all" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 52 | echo |
| 53 | exit 1 |
| 54 | } |
| 55 | |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 56 | cd "$(dirname $0)" |
| 57 | |
| 58 | subsetArg="" |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 59 | clearCaches=false |
| 60 | cleanSettings=false |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 61 | reinstall=false |
| 62 | projectSubset="" |
Jeff Gaston | 616585c | 2021-12-10 12:27:27 -0500 | [diff] [blame] | 63 | profile=false |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 64 | while [ "$1" != "" ]; do |
| 65 | arg="$1" |
| 66 | shift |
| 67 | # parse options |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 68 | if [ "$arg" == "--clear-caches" ]; then |
| 69 | clearCaches=true |
| 70 | continue |
| 71 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 72 | if [ "$arg" == "--clean" ]; then |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 73 | clearCaches=true |
| 74 | cleanSettings=true |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 75 | continue |
| 76 | fi |
| 77 | if [ "$arg" == "--reinstall" ]; then |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 78 | clearCaches=true |
| 79 | cleanSettings=true |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 80 | reinstall=true |
| 81 | continue |
| 82 | fi |
Jeff Gaston | 616585c | 2021-12-10 12:27:27 -0500 | [diff] [blame] | 83 | if [ "$arg" == "--profile" ]; then |
| 84 | profile=true |
| 85 | continue |
| 86 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 87 | # parse arguments |
| 88 | subsetArg="$arg" |
| 89 | newSubset="" |
| 90 | if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 91 | newSubset=main |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 92 | fi |
| 93 | if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 94 | newSubset=compose |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 95 | fi |
Aurimas Liutikas | bf1dfd4 | 2022-07-06 13:35:35 -0700 | [diff] [blame] | 96 | if [ "$subsetArg" == "ca" -o "$subsetArg" == "camera" ]; then |
| 97 | newSubset=camera |
| 98 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 99 | if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 100 | newSubset=flan |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 101 | fi |
Gyumin Sim | ff92d18 | 2021-02-02 19:27:59 +0900 | [diff] [blame] | 102 | if [ "$subsetArg" == "media" ]; then |
| 103 | newSubset=media |
| 104 | fi |
Flavio Lerda | 726911b | 2021-01-18 18:15:06 +0000 | [diff] [blame] | 105 | if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then |
| 106 | newSubset=wear |
| 107 | fi |
Zak Cohen | b87e89a | 2022-02-18 14:24:13 -0800 | [diff] [blame] | 108 | if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then |
| 109 | newSubset=glance |
| 110 | fi |
Yigit Boyar | f08b9a0 | 2022-06-02 09:16:59 -0700 | [diff] [blame] | 111 | if [ "$subsetArg" == "k" -o "$subsetArg" == "kmp" ]; then |
| 112 | newSubset=kmp |
| 113 | fi |
Fred Sladkey | e82df61 | 2022-07-14 14:50:36 -0400 | [diff] [blame] | 114 | if [ "$subsetArg" == "native" ]; then |
| 115 | newSubset=native |
| 116 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 117 | if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then |
Jeff Gaston | 4ac74c3 | 2021-01-29 12:12:20 -0500 | [diff] [blame] | 118 | newSubset=all |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 119 | fi |
David Saff | c4b29f2 | 2022-05-19 12:23:37 -0400 | [diff] [blame] | 120 | if [ "$subsetArg" == "t" -o "$subsetArg" == "tools" ]; then |
| 121 | newSubset=tools |
| 122 | fi |
Yaoda WANG | 7432b8c | 2023-01-18 13:20:47 +0800 | [diff] [blame] | 123 | if [ "$subsetArg" == "wm" -o "$subsetArg" == "window" ]; then |
| 124 | newSubset=window |
| 125 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 126 | if [ "$newSubset" == "" ]; then |
| 127 | echo "Unrecognized argument: '$subsetArg'" |
| 128 | usage |
| 129 | fi |
| 130 | if [ "$projectSubset" != "" ]; then |
| 131 | echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once" |
| 132 | usage |
| 133 | fi |
| 134 | projectSubset=$newSubset |
| 135 | done |
| 136 | |
| 137 | if [ "$projectSubset" == "" ]; then |
| 138 | echo "Project subset is required" |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 139 | usage |
| 140 | fi |
| 141 | |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 142 | export ANDROIDX_PROJECTS=$projectSubset |
| 143 | |
| 144 | # ensures the nonexistence of a file or directory, and makes a backup |
| 145 | function remove() { |
| 146 | path="$1" |
| 147 | backup="$(dirname $path)/studio-backup/$(basename $path)" |
| 148 | if [ -e "$path" ]; then |
| 149 | echo "Moving $path to $backup" |
Flavio Lerda | 833bae4 | 2021-11-11 15:55:34 +0000 | [diff] [blame] | 150 | rm -rf "$backup" |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 151 | mkdir -p "$(dirname $backup)" |
| 152 | mv "$path" "$backup" |
| 153 | fi |
| 154 | } |
| 155 | |
| 156 | if [ "$reinstall" == "true" ]; then |
| 157 | # remove Studio itself so Gradle will re-download it |
Flavio Lerda | 833bae4 | 2021-11-11 15:55:34 +0000 | [diff] [blame] | 158 | rm -rf studio |
Jeff Gaston | d25425c | 2020-12-02 09:53:57 -0500 | [diff] [blame] | 159 | fi |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 160 | |
Jeff Gaston | 616585c | 2021-12-10 12:27:27 -0500 | [diff] [blame] | 161 | if [ "$profile" == "true" ]; then |
| 162 | PROFILE_FILE=/tmp/report.json |
| 163 | traceConfig="$(cd development/studio && pwd)/profile.config" |
| 164 | rm -f "$PROFILE_FILE" |
| 165 | echo "Profile file will be $PROFILE_FILE , which will be able to be loaded into chrome://tracing" |
| 166 | echo |
| 167 | echo "If you find that too many or too few function calls are included in the trace, modify $traceConfig" |
| 168 | echo |
| 169 | tracerJar="$(cd ../../prebuilts/androidx/external/com/android/tools/tracer/agent && pwd)/trace_agent.jar" |
| 170 | # Make sure to set _JAVA_OPTIONS before starting Gradle |
| 171 | export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:${tracerJar}=${traceConfig}" |
| 172 | fi |
| 173 | |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 174 | # remove studio-specific caches |
| 175 | if [ "$cleanSettings" == "true" ]; then |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 176 | # make backups of files that users might have customized |
| 177 | remove ~/.AndroidStudioAndroidX |
| 178 | remove ~/.AndroidStudioAndroidXPlayground |
| 179 | remove ~/.android |
Jeff Gaston | 0565144 | 2022-01-26 12:56:58 -0500 | [diff] [blame] | 180 | fi |
| 181 | |
| 182 | if [ "$clearCaches" == "true" ]; then |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 183 | # delete (without backup) files that users won't have customized |
| 184 | git clean -fdX .idea/ |
Jeff Gaston | 616585c | 2021-12-10 12:27:27 -0500 | [diff] [blame] | 185 | |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 186 | # remove gradle caches too and build |
| 187 | ./cleanBuild.sh -y studio |
| 188 | else |
Jeff Gaston | 616585c | 2021-12-10 12:27:27 -0500 | [diff] [blame] | 189 | # If not a clean launch, then a Gradle daemon might be running. |
| 190 | # If profiling, we need to stop the Gradle daemon to make sure any changes to the |
| 191 | # profiling properties will be used. |
| 192 | if [ "$profile" == "true" ]; then |
| 193 | ./gradlew --stop |
| 194 | fi |
| 195 | |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 196 | # ask gradle to launch studio |
Aurimas Liutikas | 0db0572 | 2021-07-20 13:06:27 -0700 | [diff] [blame] | 197 | ./gradlew :studio |
Jeff Gaston | 1db6bb8 | 2020-12-22 13:12:23 -0500 | [diff] [blame] | 198 | fi |