[go: nahoru, domu]

blob: a64281945d790a69de78f0474aea19ec8ae96cbb [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
28 echo " f, flan"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050029 echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation"
Jeff Gastond25425c2020-12-02 09:53:57 -050030 echo
Gyumin Simff92d182021-02-02 19:27:59 +090031 echo " media"
32 echo " Open the project subset media: Media, Media2, and MediaRouter"
33 echo
Yigit Boyarf08b9a02022-06-02 09:16:59 -070034 echo " kmp"
35 echo " Open the project subset KMP: Projects that have KMP builds"
36 echo
Flavio Lerda726911b2021-01-18 18:15:06 +000037 echo " w, wear"
38 echo " Open the project subset for Wear OS libraries"
39 echo
Zak Cohenb87e89a2022-02-18 14:24:13 -080040 echo " g, glance"
41 echo " Open the project subset for glance projects"
42 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050043 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050044 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050045 echo
46 exit 1
47}
48
Jeff Gaston1db6bb82020-12-22 13:12:23 -050049cd "$(dirname $0)"
50
51subsetArg=""
Jeff Gaston05651442022-01-26 12:56:58 -050052clearCaches=false
53cleanSettings=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050054reinstall=false
55projectSubset=""
Jeff Gaston616585c2021-12-10 12:27:27 -050056profile=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050057while [ "$1" != "" ]; do
58 arg="$1"
59 shift
60 # parse options
Jeff Gaston05651442022-01-26 12:56:58 -050061 if [ "$arg" == "--clear-caches" ]; then
62 clearCaches=true
63 continue
64 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050065 if [ "$arg" == "--clean" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050066 clearCaches=true
67 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050068 continue
69 fi
70 if [ "$arg" == "--reinstall" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050071 clearCaches=true
72 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050073 reinstall=true
74 continue
75 fi
Jeff Gaston616585c2021-12-10 12:27:27 -050076 if [ "$arg" == "--profile" ]; then
77 profile=true
78 continue
79 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050080 # parse arguments
81 subsetArg="$arg"
82 newSubset=""
83 if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050084 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050085 fi
86 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050087 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050088 fi
89 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050090 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -050091 fi
Gyumin Simff92d182021-02-02 19:27:59 +090092 if [ "$subsetArg" == "media" ]; then
93 newSubset=media
94 fi
Flavio Lerda726911b2021-01-18 18:15:06 +000095 if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
96 newSubset=wear
97 fi
Zak Cohenb87e89a2022-02-18 14:24:13 -080098 if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then
99 newSubset=glance
100 fi
Yigit Boyarf08b9a02022-06-02 09:16:59 -0700101 if [ "$subsetArg" == "k" -o "$subsetArg" == "kmp" ]; then
102 newSubset=kmp
103 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500104 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -0500105 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500106 fi
David Saffc4b29f22022-05-19 12:23:37 -0400107 if [ "$subsetArg" == "t" -o "$subsetArg" == "tools" ]; then
108 newSubset=tools
109 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500110 if [ "$newSubset" == "" ]; then
111 echo "Unrecognized argument: '$subsetArg'"
112 usage
113 fi
114 if [ "$projectSubset" != "" ]; then
115 echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once"
116 usage
117 fi
118 projectSubset=$newSubset
119done
120
121if [ "$projectSubset" == "" ]; then
122 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -0500123 usage
124fi
125
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500126export ANDROIDX_PROJECTS=$projectSubset
127
128# ensures the nonexistence of a file or directory, and makes a backup
129function remove() {
130 path="$1"
131 backup="$(dirname $path)/studio-backup/$(basename $path)"
132 if [ -e "$path" ]; then
133 echo "Moving $path to $backup"
Flavio Lerda833bae42021-11-11 15:55:34 +0000134 rm -rf "$backup"
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500135 mkdir -p "$(dirname $backup)"
136 mv "$path" "$backup"
137 fi
138}
139
140if [ "$reinstall" == "true" ]; then
141 # remove Studio itself so Gradle will re-download it
Flavio Lerda833bae42021-11-11 15:55:34 +0000142 rm -rf studio
Jeff Gastond25425c2020-12-02 09:53:57 -0500143fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500144
Jeff Gaston616585c2021-12-10 12:27:27 -0500145if [ "$profile" == "true" ]; then
146 PROFILE_FILE=/tmp/report.json
147 traceConfig="$(cd development/studio && pwd)/profile.config"
148 rm -f "$PROFILE_FILE"
149 echo "Profile file will be $PROFILE_FILE , which will be able to be loaded into chrome://tracing"
150 echo
151 echo "If you find that too many or too few function calls are included in the trace, modify $traceConfig"
152 echo
153 tracerJar="$(cd ../../prebuilts/androidx/external/com/android/tools/tracer/agent && pwd)/trace_agent.jar"
154 # Make sure to set _JAVA_OPTIONS before starting Gradle
155 export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:${tracerJar}=${traceConfig}"
156fi
157
Jeff Gaston05651442022-01-26 12:56:58 -0500158# remove studio-specific caches
159if [ "$cleanSettings" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500160 # make backups of files that users might have customized
161 remove ~/.AndroidStudioAndroidX
162 remove ~/.AndroidStudioAndroidXPlayground
163 remove ~/.android
Jeff Gaston05651442022-01-26 12:56:58 -0500164fi
165
166if [ "$clearCaches" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500167 # delete (without backup) files that users won't have customized
168 git clean -fdX .idea/
Jeff Gaston616585c2021-12-10 12:27:27 -0500169
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500170 # remove gradle caches too and build
171 ./cleanBuild.sh -y studio
172else
Jeff Gaston616585c2021-12-10 12:27:27 -0500173 # If not a clean launch, then a Gradle daemon might be running.
174 # If profiling, we need to stop the Gradle daemon to make sure any changes to the
175 # profiling properties will be used.
176 if [ "$profile" == "true" ]; then
177 ./gradlew --stop
178 fi
179
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500180 # ask gradle to launch studio
Aurimas Liutikas0db05722021-07-20 13:06:27 -0700181 ./gradlew :studio
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500182fi