[go: nahoru, domu]

blob: f76fba38637d5029cac221645c281a4be3ad3921 [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
Fred Sladkeye82df612022-07-14 14:50:36 -040046 echo
47 echo " native"
Fred Sladkey8478a142022-08-30 17:27:22 -040048 echo " Open the project subset for native projects"
Fred Sladkeye82df612022-07-14 14:50:36 -040049 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050050 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050051 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050052 echo
53 exit 1
54}
55
Jeff Gaston1db6bb82020-12-22 13:12:23 -050056cd "$(dirname $0)"
57
58subsetArg=""
Jeff Gaston05651442022-01-26 12:56:58 -050059clearCaches=false
60cleanSettings=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050061reinstall=false
62projectSubset=""
Jeff Gaston616585c2021-12-10 12:27:27 -050063profile=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050064while [ "$1" != "" ]; do
65 arg="$1"
66 shift
67 # parse options
Jeff Gaston05651442022-01-26 12:56:58 -050068 if [ "$arg" == "--clear-caches" ]; then
69 clearCaches=true
70 continue
71 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050072 if [ "$arg" == "--clean" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050073 clearCaches=true
74 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050075 continue
76 fi
77 if [ "$arg" == "--reinstall" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050078 clearCaches=true
79 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050080 reinstall=true
81 continue
82 fi
Jeff Gaston616585c2021-12-10 12:27:27 -050083 if [ "$arg" == "--profile" ]; then
84 profile=true
85 continue
86 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050087 # parse arguments
88 subsetArg="$arg"
89 newSubset=""
90 if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050091 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050092 fi
93 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050094 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050095 fi
Aurimas Liutikasbf1dfd42022-07-06 13:35:35 -070096 if [ "$subsetArg" == "ca" -o "$subsetArg" == "camera" ]; then
97 newSubset=camera
98 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050099 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -0500100 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500101 fi
Gyumin Simff92d182021-02-02 19:27:59 +0900102 if [ "$subsetArg" == "media" ]; then
103 newSubset=media
104 fi
Flavio Lerda726911b2021-01-18 18:15:06 +0000105 if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
106 newSubset=wear
107 fi
Zak Cohenb87e89a2022-02-18 14:24:13 -0800108 if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then
109 newSubset=glance
110 fi
Yigit Boyarf08b9a02022-06-02 09:16:59 -0700111 if [ "$subsetArg" == "k" -o "$subsetArg" == "kmp" ]; then
112 newSubset=kmp
113 fi
Fred Sladkeye82df612022-07-14 14:50:36 -0400114 if [ "$subsetArg" == "native" ]; then
115 newSubset=native
116 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500117 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -0500118 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500119 fi
David Saffc4b29f22022-05-19 12:23:37 -0400120 if [ "$subsetArg" == "t" -o "$subsetArg" == "tools" ]; then
121 newSubset=tools
122 fi
Yaoda WANG7432b8c2023-01-18 13:20:47 +0800123 if [ "$subsetArg" == "wm" -o "$subsetArg" == "window" ]; then
124 newSubset=window
125 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500126 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
135done
136
137if [ "$projectSubset" == "" ]; then
138 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -0500139 usage
140fi
141
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500142export ANDROIDX_PROJECTS=$projectSubset
143
144# ensures the nonexistence of a file or directory, and makes a backup
145function remove() {
146 path="$1"
147 backup="$(dirname $path)/studio-backup/$(basename $path)"
148 if [ -e "$path" ]; then
149 echo "Moving $path to $backup"
Flavio Lerda833bae42021-11-11 15:55:34 +0000150 rm -rf "$backup"
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500151 mkdir -p "$(dirname $backup)"
152 mv "$path" "$backup"
153 fi
154}
155
156if [ "$reinstall" == "true" ]; then
157 # remove Studio itself so Gradle will re-download it
Flavio Lerda833bae42021-11-11 15:55:34 +0000158 rm -rf studio
Jeff Gastond25425c2020-12-02 09:53:57 -0500159fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500160
Jeff Gaston616585c2021-12-10 12:27:27 -0500161if [ "$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}"
172fi
173
Jeff Gaston05651442022-01-26 12:56:58 -0500174# remove studio-specific caches
175if [ "$cleanSettings" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500176 # make backups of files that users might have customized
177 remove ~/.AndroidStudioAndroidX
178 remove ~/.AndroidStudioAndroidXPlayground
179 remove ~/.android
Jeff Gaston05651442022-01-26 12:56:58 -0500180fi
181
182if [ "$clearCaches" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500183 # delete (without backup) files that users won't have customized
184 git clean -fdX .idea/
Jeff Gaston616585c2021-12-10 12:27:27 -0500185
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500186 # remove gradle caches too and build
187 ./cleanBuild.sh -y studio
188else
Jeff Gaston616585c2021-12-10 12:27:27 -0500189 # 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 Gaston1db6bb82020-12-22 13:12:23 -0500196 # ask gradle to launch studio
Aurimas Liutikas0db05722021-07-20 13:06:27 -0700197 ./gradlew :studio
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500198fi