[go: nahoru, domu]

blob: 496c5e2de0c5fa5336f08756b5eac8123d30830a [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
Flavio Lerda726911b2021-01-18 18:15:06 +000034 echo " w, wear"
35 echo " Open the project subset for Wear OS libraries"
36 echo
Zak Cohenb87e89a2022-02-18 14:24:13 -080037 echo " g, glance"
38 echo " Open the project subset for glance projects"
39 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050040 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050041 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050042 echo
43 exit 1
44}
45
Jeff Gaston1db6bb82020-12-22 13:12:23 -050046cd "$(dirname $0)"
47
48subsetArg=""
Jeff Gaston05651442022-01-26 12:56:58 -050049clearCaches=false
50cleanSettings=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050051reinstall=false
52projectSubset=""
Jeff Gaston616585c2021-12-10 12:27:27 -050053profile=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050054while [ "$1" != "" ]; do
55 arg="$1"
56 shift
57 # parse options
Jeff Gaston05651442022-01-26 12:56:58 -050058 if [ "$arg" == "--clear-caches" ]; then
59 clearCaches=true
60 continue
61 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050062 if [ "$arg" == "--clean" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050063 clearCaches=true
64 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050065 continue
66 fi
67 if [ "$arg" == "--reinstall" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050068 clearCaches=true
69 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050070 reinstall=true
71 continue
72 fi
Jeff Gaston616585c2021-12-10 12:27:27 -050073 if [ "$arg" == "--profile" ]; then
74 profile=true
75 continue
76 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050077 # parse arguments
78 subsetArg="$arg"
79 newSubset=""
80 if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050081 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050082 fi
83 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050084 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050085 fi
86 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050087 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -050088 fi
Gyumin Simff92d182021-02-02 19:27:59 +090089 if [ "$subsetArg" == "media" ]; then
90 newSubset=media
91 fi
Flavio Lerda726911b2021-01-18 18:15:06 +000092 if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
93 newSubset=wear
94 fi
Zak Cohenb87e89a2022-02-18 14:24:13 -080095 if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then
96 newSubset=glance
97 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050098 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050099 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500100 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
110done
111
112if [ "$projectSubset" == "" ]; then
113 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -0500114 usage
115fi
116
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500117export ANDROIDX_PROJECTS=$projectSubset
118
119# ensures the nonexistence of a file or directory, and makes a backup
120function remove() {
121 path="$1"
122 backup="$(dirname $path)/studio-backup/$(basename $path)"
123 if [ -e "$path" ]; then
124 echo "Moving $path to $backup"
Flavio Lerda833bae42021-11-11 15:55:34 +0000125 rm -rf "$backup"
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500126 mkdir -p "$(dirname $backup)"
127 mv "$path" "$backup"
128 fi
129}
130
131if [ "$reinstall" == "true" ]; then
132 # remove Studio itself so Gradle will re-download it
Flavio Lerda833bae42021-11-11 15:55:34 +0000133 rm -rf studio
Jeff Gastond25425c2020-12-02 09:53:57 -0500134fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500135
Jeff Gaston616585c2021-12-10 12:27:27 -0500136if [ "$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}"
147fi
148
Jeff Gaston05651442022-01-26 12:56:58 -0500149# remove studio-specific caches
150if [ "$cleanSettings" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500151 # make backups of files that users might have customized
152 remove ~/.AndroidStudioAndroidX
153 remove ~/.AndroidStudioAndroidXPlayground
154 remove ~/.android
Jeff Gaston05651442022-01-26 12:56:58 -0500155fi
156
157if [ "$clearCaches" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500158 # delete (without backup) files that users won't have customized
159 git clean -fdX .idea/
Jeff Gaston616585c2021-12-10 12:27:27 -0500160
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500161 # remove gradle caches too and build
162 ./cleanBuild.sh -y studio
163else
Jeff Gaston616585c2021-12-10 12:27:27 -0500164 # 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 Gaston1db6bb82020-12-22 13:12:23 -0500171 # ask gradle to launch studio
Aurimas Liutikas0db05722021-07-20 13:06:27 -0700172 ./gradlew :studio
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500173fi