OLD | NEW |
| (Empty) |
1 #!/bin/bash | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 # This a simple script to make building/testing Mojo components easier (on | |
7 # Linux). | |
8 | |
9 # TODO(vtl): Maybe make the test runner smart and not run unchanged test | |
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-and-release - Debug (default) build / | |
31 Release build / Debug and Release builds. | |
32 gn options (specify before gn): | |
33 --clang / --gcc - Use clang (default) / gcc. | |
34 --use-goma / --no-use-goma - Use goma (if \$GOMA_DIR is set or \$HOME/goma | |
35 exists; default) / don't use goma. | |
36 | |
37 Note: It will abort on the first failure (if any). | |
38 EOF | |
39 } | |
40 | |
41 get_gn_arg_value() { | |
42 grep -m 1 "^[[:space:]]*\<$2\>" "$1/args.gn" | \ | |
43 sed -n 's/.* = "\?\([^"]*\)"\?$/\1/p' | |
44 } | |
45 | |
46 do_build() { | |
47 echo "Building in out/$1 ..." | |
48 if [ "$(get_gn_arg_value "out/$1" use_goma)" = "true" ]; then | |
49 # Use the configured goma directory. | |
50 local goma_dir="$(get_gn_arg_value "out/$1" goma_dir)" | |
51 echo "Ensuring goma (in ${goma_dir}) started ..." | |
52 "${goma_dir}/goma_ctl.py" ensure_start | |
53 | |
54 ninja -j 1000 -l 100 -C "out/$1" mojo || exit 1 | |
55 else | |
56 ninja -C "out/$1" mojo || exit 1 | |
57 fi | |
58 } | |
59 | |
60 do_unittests() { | |
61 echo "Running unit tests in out/$1 ..." | |
62 mojo/tools/test_runner.py mojo/tools/data/unittests "out/$1" \ | |
63 mojob_test_successes || exit 1 | |
64 } | |
65 | |
66 do_perftests() { | |
67 echo "Running perf tests in out/$1 ..." | |
68 "out/$1/mojo_public_system_perftests" || exit 1 | |
69 } | |
70 | |
71 do_gn() { | |
72 local gn_args="$(make_gn_args $1)" | |
73 echo "Running gn with --args=\"${gn_args}\" ..." | |
74 gn gen --args="${gn_args}" "out/$1" | |
75 } | |
76 | |
77 do_sync() { | |
78 # Note: sync only (with hooks, but no gyp-ing). | |
79 GYP_CHROMIUM_NO_ACTION=1 gclient sync || exit 1 | |
80 } | |
81 | |
82 # Valid values: Debug, Release, or Debug_and_Release. | |
83 BUILD_TYPE=Debug_and_Release | |
84 should_do_Debug() { | |
85 test "$BUILD_TYPE" = Debug -o "$BUILD_TYPE" = Debug_and_Release | |
86 } | |
87 should_do_Release() { | |
88 test "$BUILD_TYPE" = Release -o "$BUILD_TYPE" = Debug_and_Release | |
89 } | |
90 | |
91 # Valid values: clang or gcc. | |
92 COMPILER=clang | |
93 # Valid values: auto or disabled. | |
94 GOMA=auto | |
95 make_gn_args() { | |
96 local args=() | |
97 # TODO(vtl): It's a bit of a hack to infer the build type from the output | |
98 # directory name, but it's what we have right now (since we support "debug and | |
99 # release" mode). | |
100 case "$1" in | |
101 Debug) | |
102 # (Default.) | |
103 ;; | |
104 Release) | |
105 args+=("is_debug=false") | |
106 ;; | |
107 esac | |
108 case "$COMPILER" in | |
109 clang) | |
110 # (Default.) | |
111 ;; | |
112 gcc) | |
113 args+=("is_clang=false") | |
114 ;; | |
115 esac | |
116 case "$GOMA" in | |
117 auto) | |
118 if [ -v GOMA_DIR ]; then | |
119 args+=("use_goma=true" "goma_dir=\"${GOMA_DIR}\"") | |
120 elif [ -d "${HOME}/goma" ]; then | |
121 args+=("use_goma=true" "goma_dir=\"${HOME}/goma\"") | |
122 else | |
123 : # (Default.) | |
124 fi | |
125 ;; | |
126 disabled) | |
127 # (Default.) | |
128 ;; | |
129 esac | |
130 echo "${args[*]}" | |
131 } | |
132 | |
133 # We're in src/mojo/tools. We want to get to src. | |
134 cd "$(realpath "$(dirname "$0")")/../.." | |
135 | |
136 if [ $# -eq 0 ]; then | |
137 do_help | |
138 exit 0 | |
139 fi | |
140 | |
141 for arg in "$@"; do | |
142 case "$arg" in | |
143 # Commands ----------------------------------------------------------------- | |
144 help|--help) | |
145 do_help | |
146 exit 0 | |
147 ;; | |
148 build) | |
149 should_do_Debug && do_build Debug | |
150 should_do_Release && do_build Release | |
151 ;; | |
152 test) | |
153 should_do_Debug && do_unittests Debug | |
154 should_do_Release && do_unittests Release | |
155 ;; | |
156 perftest) | |
157 should_do_Debug && do_perftests Debug | |
158 should_do_Release && do_perftests Release | |
159 ;; | |
160 gn) | |
161 should_do_Debug && do_gn Debug | |
162 should_do_Release && do_gn Release | |
163 ;; | |
164 sync) | |
165 do_sync | |
166 ;; | |
167 show-bash-alias) | |
168 # You want to type something like: | |
169 # alias mojob=\ | |
170 # '"$(pwd | sed '"'"'s/\(.*\/src\).*/\1/'"'"')/mojo/tools/mojob.sh"' | |
171 # This is quoting hell, so we simply escape every non-alphanumeric | |
172 # character. | |
173 echo alias\ mojob\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\)\ | |
174 \.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojob\.sh\"\' | |
175 ;; | |
176 # Options ------------------------------------------------------------------ | |
177 --debug) | |
178 BUILD_TYPE=Debug | |
179 ;; | |
180 --release) | |
181 BUILD_TYPE=Release | |
182 ;; | |
183 --debug-and-release) | |
184 BUILD_TYPE=Debug_and_Release | |
185 ;; | |
186 --clang) | |
187 COMPILER=clang | |
188 ;; | |
189 --gcc) | |
190 COMPILER=gcc | |
191 ;; | |
192 --use-goma) | |
193 GOMA=auto | |
194 ;; | |
195 --no-use-goma) | |
196 GOMA=disabled | |
197 ;; | |
198 *) | |
199 echo "Unknown command \"${arg}\". Try \"$(basename "$0") help\"." | |
200 exit 1 | |
201 ;; | |
202 esac | |
203 done | |
204 | |
205 exit 0 | |
OLD | NEW |