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