blob: 9ff41c2d4ca007b5fef0bb8107e80058e2255100 [file] [log] [blame]
Alan Viverettea693ece2020-11-17 16:23:42 -05001#!/usr/bin/env bash
Alan Viverettea693ece2020-11-17 16:23:42 -05002
Jeff Gastond25425c2020-12-02 09:53:57 -05003function usage() {
Jeff Gaston05651442022-01-26 12:56:58 -05004 echo "Usage: studiow [--clear-caches] [--clean] [--reinstall] [--profile] <project subset>"
Jeff Gaston1db6bb82020-12-22 13:12:23 -05005 echo
6 echo "OPTIONS"
Jeff Gaston05651442022-01-26 12:56:58 -05007 echo
8 echo " --clear-caches"
9 echo " Clear generated caches (but not user settings) before launching"
10 echo
Jeff Gaston1db6bb82020-12-22 13:12:23 -050011 echo " --clean"
12 echo " Clear (with backup) generated files (settings, caches, etc) before launching"
Jeff Gaston05651442022-01-26 12:56:58 -050013 echo " Also implies --clear-caches"
Jeff Gaston1db6bb82020-12-22 13:12:23 -050014 echo
15 echo " --reinstall"
16 echo " Remove and re-download Studio itself. Also implies --clean"
Jeff Gaston05651442022-01-26 12:56:58 -050017 echo
Jeff Gaston616585c2021-12-10 12:27:27 -050018 echo " --profile"
19 echo " Enables profiling of Studio"
Jeff Gastond25425c2020-12-02 09:53:57 -050020 echo
21 echo "Project subsets:"
22 echo " m, main"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050023 echo " Open the project subset main: non-Compose Jetpack libraries"
Jeff Gastond25425c2020-12-02 09:53:57 -050024 echo
25 echo " c, compose"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050026 echo " Open the project subset compose"
Jeff Gastond25425c2020-12-02 09:53:57 -050027 echo
Aurimas Liutikasbf1dfd42022-07-06 13:35:35 -070028 echo " ca, camera"
29 echo " Open the project subset camera"
30 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050031 echo " f, flan"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050032 echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation"
Jeff Gastond25425c2020-12-02 09:53:57 -050033 echo
Gyumin Simff92d182021-02-02 19:27:59 +090034 echo " media"
35 echo " Open the project subset media: Media, Media2, and MediaRouter"
36 echo
Yigit Boyarf08b9a02022-06-02 09:16:59 -070037 echo " kmp"
38 echo " Open the project subset KMP: Projects that have KMP builds"
39 echo
Flavio Lerda726911b2021-01-18 18:15:06 +000040 echo " w, wear"
41 echo " Open the project subset for Wear OS libraries"
42 echo
Zak Cohenb87e89a2022-02-18 14:24:13 -080043 echo " g, glance"
44 echo " Open the project subset for glance projects"
45 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050046 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050047 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050048 echo
49 exit 1
50}
51
Jeff Gaston1db6bb82020-12-22 13:12:23 -050052cd "$(dirname $0)"
53
54subsetArg=""
Jeff Gaston05651442022-01-26 12:56:58 -050055clearCaches=false
56cleanSettings=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050057reinstall=false
58projectSubset=""
Jeff Gaston616585c2021-12-10 12:27:27 -050059profile=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050060while [ "$1" != "" ]; do
61 arg="$1"
62 shift
63 # parse options
Jeff Gaston05651442022-01-26 12:56:58 -050064 if [ "$arg" == "--clear-caches" ]; then
65 clearCaches=true
66 continue
67 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050068 if [ "$arg" == "--clean" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050069 clearCaches=true
70 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050071 continue
72 fi
73 if [ "$arg" == "--reinstall" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050074 clearCaches=true
75 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050076 reinstall=true
77 continue
78 fi
Jeff Gaston616585c2021-12-10 12:27:27 -050079 if [ "$arg" == "--profile" ]; then
80 profile=true
81 continue
82 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050083 # parse arguments
84 subsetArg="$arg"
85 newSubset=""
86 if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050087 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050088 fi
89 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050090 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050091 fi
Aurimas Liutikasbf1dfd42022-07-06 13:35:35 -070092 if [ "$subsetArg" == "ca" -o "$subsetArg" == "camera" ]; then
93 newSubset=camera
94 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050095 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050096 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -050097 fi
Gyumin Simff92d182021-02-02 19:27:59 +090098 if [ "$subsetArg" == "media" ]; then
99 newSubset=media
100 fi
Flavio Lerda726911b2021-01-18 18:15:06 +0000101 if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
102 newSubset=wear
103 fi
Zak Cohenb87e89a2022-02-18 14:24:13 -0800104 if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then
105 newSubset=glance
106 fi
Yigit Boyarf08b9a02022-06-02 09:16:59 -0700107 if [ "$subsetArg" == "k" -o "$subsetArg" == "kmp" ]; then
108 newSubset=kmp
109 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500110 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -0500111 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500112 fi
David Saffc4b29f22022-05-19 12:23:37 -0400113 if [ "$subsetArg" == "t" -o "$subsetArg" == "tools" ]; then
114 newSubset=tools
115 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500116 if [ "$newSubset" == "" ]; then
117 echo "Unrecognized argument: '$subsetArg'"
118 usage
119 fi
120 if [ "$projectSubset" != "" ]; then
121 echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once"
122 usage
123 fi
124 projectSubset=$newSubset
125done
126
127if [ "$projectSubset" == "" ]; then
128 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -0500129 usage
130fi
131
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500132export ANDROIDX_PROJECTS=$projectSubset
133
134# ensures the nonexistence of a file or directory, and makes a backup
135function remove() {
136 path="$1"
137 backup="$(dirname $path)/studio-backup/$(basename $path)"
138 if [ -e "$path" ]; then
139 echo "Moving $path to $backup"
Flavio Lerda833bae42021-11-11 15:55:34 +0000140 rm -rf "$backup"
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500141 mkdir -p "$(dirname $backup)"
142 mv "$path" "$backup"
143 fi
144}
145
146if [ "$reinstall" == "true" ]; then
147 # remove Studio itself so Gradle will re-download it
Flavio Lerda833bae42021-11-11 15:55:34 +0000148 rm -rf studio
Jeff Gastond25425c2020-12-02 09:53:57 -0500149fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500150
Jeff Gaston616585c2021-12-10 12:27:27 -0500151if [ "$profile" == "true" ]; then
152 PROFILE_FILE=/tmp/report.json
153 traceConfig="$(cd development/studio && pwd)/profile.config"
154 rm -f "$PROFILE_FILE"
155 echo "Profile file will be $PROFILE_FILE , which will be able to be loaded into chrome://tracing"
156 echo
157 echo "If you find that too many or too few function calls are included in the trace, modify $traceConfig"
158 echo
159 tracerJar="$(cd ../../prebuilts/androidx/external/com/android/tools/tracer/agent && pwd)/trace_agent.jar"
160 # Make sure to set _JAVA_OPTIONS before starting Gradle
161 export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:${tracerJar}=${traceConfig}"
162fi
163
Jeff Gaston05651442022-01-26 12:56:58 -0500164# remove studio-specific caches
165if [ "$cleanSettings" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500166 # make backups of files that users might have customized
167 remove ~/.AndroidStudioAndroidX
168 remove ~/.AndroidStudioAndroidXPlayground
169 remove ~/.android
Jeff Gaston05651442022-01-26 12:56:58 -0500170fi
171
172if [ "$clearCaches" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500173 # delete (without backup) files that users won't have customized
174 git clean -fdX .idea/
Jeff Gaston616585c2021-12-10 12:27:27 -0500175
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500176 # remove gradle caches too and build
177 ./cleanBuild.sh -y studio
178else
Jeff Gaston616585c2021-12-10 12:27:27 -0500179 # If not a clean launch, then a Gradle daemon might be running.
180 # If profiling, we need to stop the Gradle daemon to make sure any changes to the
181 # profiling properties will be used.
182 if [ "$profile" == "true" ]; then
183 ./gradlew --stop
184 fi
185
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500186 # ask gradle to launch studio
Aurimas Liutikas0db05722021-07-20 13:06:27 -0700187 ./gradlew :studio
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500188fi