OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This a simple script to make building/testing Mojo components easier (on | 6 python "$(dirname "$0")/mojob.py" "$@" |
7 # Linux). | 7 echo "" |
8 | 8 echo "" |
9 # TODO(vtl): Maybe make the test runner smart and not run unchanged test | 9 echo "NOTE: mojob.sh is deprecated, use mojob.py instead. The arguments also ch
anged order, see mojob.py --help" |
10 # binaries. | |
11 # TODO(vtl) Maybe also provide a way to pass command-line arguments to the test | |
12 # binaries. | |
13 | |
14 do_help() { | |
15 cat << EOF | |
16 Usage: $(basename "$0") [command|option ...] | |
17 | |
18 command should be one of: | |
19 build - Build. | |
20 test - Run unit tests (does not build). | |
21 perftest - Run perf tests (does not build). | |
22 pytest - Run Python unit tests (does not build). | |
23 gn - Run gn for mojo (does not sync). | |
24 sync - Sync using gclient (does not run gn). | |
25 show-bash-alias - Outputs an appropriate bash alias for mojob. In bash do: | |
26 \$ eval \`mojo/tools/mojob.sh show-bash-alias\` | |
27 | |
28 option (which will only apply to commands which follow) should be one of: | |
29 General options (specify before everything): | |
30 --debug / --release - Debug (default) / Release build. | |
31 gn options (specify before gn): | |
32 --asan / --no-asan - Uses Address Sanitizer / don't use asan. | |
33 --clang / --gcc - Use clang (default) / gcc. | |
34 --goma / --no-goma - Use goma (if \$GOMA_DIR is set or \$HOME/goma exists; | |
35 default) / don't use goma. | |
36 --with-dart - Configure the Dart bindings. | |
37 | |
38 Note: It will abort on the first failure (if any). | |
39 EOF | |
40 } | |
41 | |
42 get_gn_arg_value() { | |
43 grep -m 1 "^[[:space:]]*\<$2\>" "$1/args.gn" | \ | |
44 sed -n 's/.* = "\?\([^"]*\)"\?$/\1/p' | |
45 } | |
46 | |
47 get_outdir() { | |
48 if [ $TARGET != linux ]; then | |
49 echo "out/${TARGET}_$1" | |
50 else | |
51 echo "out/$1" | |
52 fi | |
53 } | |
54 | |
55 do_build() { | |
56 local out_dir=$(get_outdir $1) | |
57 echo "Building in ${out_dir} ..." | |
58 if [ "$(get_gn_arg_value ${out_dir} use_goma)" = "true" ]; then | |
59 # Use the configured goma directory. | |
60 local goma_dir="$(get_gn_arg_value ${out_dir} goma_dir)" | |
61 echo "Ensuring goma (in ${goma_dir}) started ..." | |
62 "${goma_dir}/goma_ctl.py" ensure_start | |
63 | |
64 ninja -j 1000 -l 100 -C "${out_dir}" root || exit 1 | |
65 else | |
66 ninja -C "${out_dir}" root || exit 1 | |
67 fi | |
68 } | |
69 | |
70 do_unittests() { | |
71 local out_dir=$(get_outdir $1) | |
72 echo "Running unit tests in ${out_dir} ..." | |
73 ./testing/xvfb.py "${out_dir}" mojo/tools/test_runner.py \ | |
74 mojo/tools/data/unittests "${out_dir}" mojob_test_successes || exit 1 | |
75 } | |
76 | |
77 do_perftests() { | |
78 local out_dir=$(get_outdir $1) | |
79 echo "Running perf tests in ${out_dir} ..." | |
80 "${out_dir}/mojo_public_system_perftests" || exit 1 | |
81 } | |
82 | |
83 do_pytests() { | |
84 local out_dir=$(get_outdir $1) | |
85 echo "Running python tests in ${out_dir} ..." | |
86 python mojo/tools/run_mojo_python_tests.py || exit 1 | |
87 python mojo/tools/run_mojo_python_bindings_tests.py \ | |
88 "--build-dir=${out_dir}" || exit 1 | |
89 } | |
90 | |
91 do_skytests() { | |
92 local out_dir=$(get_outdir $1) | |
93 if [ $TARGET == linux ]; then | |
94 ./testing/xvfb.py "${out_dir}" sky/tools/test_sky -t $1 \ | |
95 --no-new-test-results --no-show-results --verbose || exit 1 | |
96 fi | |
97 } | |
98 | |
99 do_darttests() { | |
100 echo "Running dart tests in out/$1 ..." | |
101 dart mojo/tools/dart_test_runner.dart out/$1/gen || exit 1 | |
102 } | |
103 | |
104 do_gn() { | |
105 local gn_args="$(make_gn_args $1)" | |
106 local out_dir="$(get_outdir $1)" | |
107 echo "Running gn gen ${out_dir} with --args=\"${gn_args}\" ..." | |
108 gn gen --args="${gn_args}" "${out_dir}" | |
109 } | |
110 | |
111 do_sync() { | |
112 gclient sync || exit 1 | |
113 } | |
114 | |
115 # Valid values: Debug or Release. | |
116 BUILD_TYPE=Debug | |
117 # Valid values: clang or gcc. | |
118 COMPILER=clang | |
119 # Valid values: linux, android or chromeos | |
120 TARGET=linux | |
121 # Valid values: auto or disabled. | |
122 GOMA=auto | |
123 # Valid values: enabled or disabled. | |
124 ASAN=disabled | |
125 # Whether the Dart bindings should be built. | |
126 DART=disabled | |
127 make_gn_args() { | |
128 local args=() | |
129 # TODO(vtl): It's a bit of a hack to infer the build type from the output | |
130 # directory name, but it's what we have right now (since we support "debug and | |
131 # release" mode). | |
132 case "$1" in | |
133 Debug) | |
134 args+=("is_debug=true") | |
135 ;; | |
136 Release) | |
137 args+=("is_debug=false") | |
138 ;; | |
139 esac | |
140 case "$ASAN" in | |
141 enabled) | |
142 args+=("is_asan=true") | |
143 ;; | |
144 disabled) | |
145 args+=("is_asan=false") | |
146 ;; | |
147 esac | |
148 case "$COMPILER" in | |
149 clang) | |
150 args+=("is_clang=true") | |
151 ;; | |
152 gcc) | |
153 args+=("is_clang=false") | |
154 ;; | |
155 esac | |
156 case "$GOMA" in | |
157 auto) | |
158 if [ -v GOMA_DIR ]; then | |
159 args+=("use_goma=true" "goma_dir=\"${GOMA_DIR}\"") | |
160 elif [ -d "${HOME}/goma" ]; then | |
161 args+=("use_goma=true" "goma_dir=\"${HOME}/goma\"") | |
162 else | |
163 args+=("use_goma=false") | |
164 fi | |
165 ;; | |
166 disabled) | |
167 args+=("use_goma=false") | |
168 ;; | |
169 esac | |
170 case "$DART" in | |
171 enabled) | |
172 args+=("mojo_use_dart=true") | |
173 ;; | |
174 esac | |
175 case "$TARGET" in | |
176 android) | |
177 args+=("os=\"android\"" "cpu_arch=\"arm\"") | |
178 ;; | |
179 chromeos) | |
180 args+=("os=\"chromeos\"" "ui_base_build_ime=false" \ | |
181 "use_system_harfbuzz=false") | |
182 ;; | |
183 esac | |
184 echo "${args[*]}" | |
185 } | |
186 | |
187 # We're in src/mojo/tools. We want to get to src. | |
188 cd "$(readlink -e "$(dirname "$0")")/../.." | |
189 | |
190 if [ $# -eq 0 ]; then | |
191 do_help | |
192 exit 0 | |
193 fi | |
194 | |
195 for arg in "$@"; do | |
196 case "$arg" in | |
197 # Commands ----------------------------------------------------------------- | |
198 help|--help) | |
199 do_help | |
200 exit 0 | |
201 ;; | |
202 build) | |
203 do_build "$BUILD_TYPE" | |
204 ;; | |
205 test) | |
206 do_unittests "$BUILD_TYPE" | |
207 do_pytests "$BUILD_TYPE" | |
208 do_skytests "$BUILD_TYPE" | |
209 ;; | |
210 perftest) | |
211 do_perftests "$BUILD_TYPE" | |
212 ;; | |
213 pytest) | |
214 do_pytests "$BUILD_TYPE" | |
215 ;; | |
216 darttest) | |
217 do_darttests "$BUILD_TYPE" | |
218 ;; | |
219 gn) | |
220 do_gn "$BUILD_TYPE" | |
221 ;; | |
222 sync) | |
223 do_sync | |
224 ;; | |
225 show-bash-alias) | |
226 # You want to type something like: | |
227 # alias mojob=\ | |
228 # '"$(pwd | sed '"'"'s/\(.*\/src\).*/\1/'"'"')/mojo/tools/mojob.sh"' | |
229 # This is quoting hell, so we simply escape every non-alphanumeric | |
230 # character. | |
231 echo alias\ mojob\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\)\ | |
232 \.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojob\.sh\"\' | |
233 ;; | |
234 # Options ------------------------------------------------------------------ | |
235 --debug) | |
236 BUILD_TYPE=Debug | |
237 ;; | |
238 --release) | |
239 BUILD_TYPE=Release | |
240 ;; | |
241 --asan) | |
242 ASAN=enabled | |
243 ;; | |
244 --no-asan) | |
245 ASAN=disabled | |
246 ;; | |
247 --clang) | |
248 COMPILER=clang | |
249 ;; | |
250 --gcc) | |
251 COMPILER=gcc | |
252 ;; | |
253 --goma) | |
254 GOMA=auto | |
255 ;; | |
256 --no-goma) | |
257 GOMA=disabled | |
258 ;; | |
259 --with-dart) | |
260 DART=enabled | |
261 ;; | |
262 --android) | |
263 TARGET=android | |
264 COMPILER=gcc | |
265 ;; | |
266 --chromeos) | |
267 TARGET=chromeos | |
268 ;; | |
269 *) | |
270 echo "Unknown command \"${arg}\". Try \"$(basename "$0") help\"." | |
271 exit 1 | |
272 ;; | |
273 esac | |
274 done | |
275 | |
276 exit 0 | |
OLD | NEW |