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 # This a simple script to make building/testing Mojo components easier (on |
7 # Linux). | 7 # Linux). |
8 | 8 |
9 # TODO(vtl): Maybe make the test runner smart and not run unchanged test | 9 # TODO(vtl): Maybe make the test runner smart and not run unchanged test |
10 # binaries. | 10 # binaries. |
11 # TODO(vtl) Maybe also provide a way to pass command-line arguments to the test | 11 # TODO(vtl) Maybe also provide a way to pass command-line arguments to the test |
12 # binaries. | 12 # binaries. |
13 | 13 |
14 do_help() { | 14 do_help() { |
15 cat << EOF | 15 cat << EOF |
16 Usage: $(basename "$0") [command|option ...] | 16 Usage: $(basename "$0") [command|option ...] |
17 | 17 |
18 command should be one of: | 18 command should be one of: |
19 build - Build. | 19 build - Build. |
20 test - Run unit tests (does not build). | 20 test - Run unit tests (does not build). |
21 perftest - Run perf tests (does not build). | 21 perftest - Run perf tests (does not build). |
22 pytest - Run Python unit tests (does not build). | 22 pytest - Run Python unit tests (does not build). |
23 gyp - Run gyp for mojo (does not sync). | 23 gn - Run gn for mojo (does not sync). |
24 gypall - Run gyp for all of chromium (does not sync). | 24 sync - Sync using gclient (does not run gn). |
25 sync - Sync using gclient (does not run gyp). | |
26 show-bash-alias - Outputs an appropriate bash alias for mojob. In bash do: | 25 show-bash-alias - Outputs an appropriate bash alias for mojob. In bash do: |
27 \$ eval \`mojo/tools/mojob.sh show-bash-alias\` | 26 \$ eval \`mojo/tools/mojob.sh show-bash-alias\` |
28 | 27 |
29 option (which will only apply to following commands) should be one of: | 28 option (which will only apply to commands which follow) should be one of: |
30 Build/test options (specified before build/test/perftest): | 29 General options (specify before everything): |
31 --debug - Build/test in Debug mode. | 30 --debug / --release / --debug-and-release - Debug (default) build / |
32 --release - Build/test in Release mode. | 31 Release build / Debug and Release builds. |
33 --debug-and-release - Build/test in both Debug and Release modes (default). | 32 gn options (specify before gn): |
34 Compiler options (specified before gyp): | 33 --clang / --gcc - Use clang (default) / gcc. |
35 --clang - Use clang (default). | 34 --use-goma / --no-use-goma - Use goma (if \$GOMA_DIR is set or \$HOME/goma |
36 --gcc - Use gcc. | 35 exists; default) / don't use goma. |
37 Component options: | |
38 --shared Build components as shared libraries (default). | |
39 --static Build components as static libraries. | |
40 Use goma: | |
41 --use-goma - Use goma if \$GOMA_DIR is set or \$HOME/goma exists (default). | |
42 --no-use-goma - Do not use goma. | |
43 | 36 |
44 Note: It will abort on the first failure (if any). | 37 Note: It will abort on the first failure (if any). |
45 EOF | 38 EOF |
46 } | 39 } |
47 | 40 |
| 41 get_gn_arg_value() { |
| 42 grep -m 1 "^[[:space:]]*\<$2\>" "$1/args.gn" | \ |
| 43 sed -n 's/.* = "\?\([^"]*\)"\?$/\1/p' |
| 44 } |
| 45 |
48 do_build() { | 46 do_build() { |
49 echo "Building in out/$1 ..." | 47 echo "Building in out/$1 ..." |
50 if [ "$GOMA" = "auto" -a -v GOMA_DIR ]; then | 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 |
51 ninja -j 1000 -l 100 -C "out/$1" mojo || exit 1 | 54 ninja -j 1000 -l 100 -C "out/$1" mojo || exit 1 |
52 else | 55 else |
53 ninja -C "out/$1" mojo || exit 1 | 56 ninja -C "out/$1" mojo || exit 1 |
54 fi | 57 fi |
55 } | 58 } |
56 | 59 |
57 do_unittests() { | 60 do_unittests() { |
58 echo "Running unit tests in out/$1 ..." | 61 echo "Running unit tests in out/$1 ..." |
59 mojo/tools/test_runner.py mojo/tools/data/unittests "out/$1" \ | 62 mojo/tools/test_runner.py mojo/tools/data/unittests "out/$1" \ |
60 mojob_test_successes || exit 1 | 63 mojob_test_successes || exit 1 |
61 } | 64 } |
62 | 65 |
63 do_perftests() { | 66 do_perftests() { |
64 echo "Running perf tests in out/$1 ..." | 67 echo "Running perf tests in out/$1 ..." |
65 "out/$1/mojo_public_system_perftests" || exit 1 | 68 "out/$1/mojo_public_system_perftests" || exit 1 |
66 } | 69 } |
67 | 70 |
68 do_pytests() { | 71 do_pytests() { |
69 echo "Running python tests in out/$1 ..." | 72 echo "Running python tests in out/$1 ..." |
70 python mojo/tools/run_mojo_python_tests.py || exit 1 | 73 python mojo/tools/run_mojo_python_tests.py || exit 1 |
71 # TODO(qsr) Remove this test when the component build is not supported | 74 python mojo/tools/run_mojo_python_bindings_tests.py "--build-dir=out/$1" || \ |
72 # anymore. | 75 exit 1 |
73 if [ -f "out/$1/python/mojo/system.so" ]; then | |
74 python mojo/tools/run_mojo_python_bindings_tests.py \ | |
75 "--build-dir=out/$1" || exit 1 | |
76 fi | |
77 } | 76 } |
78 | 77 |
79 do_gyp() { | 78 do_gn() { |
80 local gyp_defines="$(make_gyp_defines)" | 79 local gn_args="$(make_gn_args $1)" |
81 echo "Running gyp for mojo with GYP_DEFINES=$gyp_defines ..." | 80 echo "Running gn with --args=\"${gn_args}\" ..." |
82 GYP_DEFINES="$gyp_defines" build/gyp_chromium mojo/mojo.gyp || exit 1 | 81 gn gen --args="${gn_args}" "out/$1" |
83 } | |
84 | |
85 do_gypall() { | |
86 local gyp_defines="$(make_gyp_defines)" | |
87 echo "Running gyp for everything with GYP_DEFINES=$gyp_defines ..." | |
88 GYP_DEFINES="$gyp_defines" build/gyp_chromium || exit 1 | |
89 } | 82 } |
90 | 83 |
91 do_sync() { | 84 do_sync() { |
92 # Note: sync only (with hooks, but no gyp-ing). | 85 # Note: sync only (with hooks, but no gyp-ing). |
93 GYP_CHROMIUM_NO_ACTION=1 gclient sync || exit 1 | 86 GYP_CHROMIUM_NO_ACTION=1 gclient sync || exit 1 |
94 } | 87 } |
95 | 88 |
96 # Valid values: Debug, Release, or Debug_and_Release. | 89 # Valid values: Debug, Release, or Debug_and_Release. |
97 BUILD_TEST_TYPE=Debug_and_Release | 90 BUILD_TYPE=Debug_and_Release |
98 should_do_Debug() { | 91 should_do_Debug() { |
99 test "$BUILD_TEST_TYPE" = Debug -o "$BUILD_TEST_TYPE" = Debug_and_Release | 92 test "$BUILD_TYPE" = Debug -o "$BUILD_TYPE" = Debug_and_Release |
100 } | 93 } |
101 should_do_Release() { | 94 should_do_Release() { |
102 test "$BUILD_TEST_TYPE" = Release -o "$BUILD_TEST_TYPE" = Debug_and_Release | 95 test "$BUILD_TYPE" = Release -o "$BUILD_TYPE" = Debug_and_Release |
103 } | 96 } |
104 | 97 |
105 # Valid values: clang or gcc. | 98 # Valid values: clang or gcc. |
106 COMPILER=clang | 99 COMPILER=clang |
107 # Valid values: shared or static. | |
108 COMPONENT=shared | |
109 # Valid values: auto or disabled. | 100 # Valid values: auto or disabled. |
110 GOMA=auto | 101 GOMA=auto |
111 make_gyp_defines() { | 102 make_gn_args() { |
112 local options=() | 103 local args=() |
113 # Always include these options. | |
114 options+=("use_aura=1") | |
115 case "$COMPILER" in | 104 case "$COMPILER" in |
116 clang) | 105 clang) |
117 options+=("clang=1") | 106 args+=("is_clang=true") |
118 ;; | 107 ;; |
119 gcc) | 108 gcc) |
120 options+=("clang=0") | 109 args+=("is_clang=false") |
121 ;; | |
122 esac | |
123 case "$COMPONENT" in | |
124 shared) | |
125 options+=("component=shared_library") | |
126 ;; | |
127 static) | |
128 options+=("component=static_library") | |
129 ;; | 110 ;; |
130 esac | 111 esac |
131 case "$GOMA" in | 112 case "$GOMA" in |
132 auto) | 113 auto) |
133 if [ -v GOMA_DIR ]; then | 114 if [ -v GOMA_DIR ]; then |
134 options+=("use_goma=1" "gomadir=\"${GOMA_DIR}\"") | 115 args+=("use_goma=true" "goma_dir=\"${GOMA_DIR}\"") |
| 116 elif [ -d "${HOME}/goma" ]; then |
| 117 args+=("use_goma=true" "goma_dir=\"${HOME}/goma\"") |
135 else | 118 else |
136 options+=("use_goma=0") | 119 args+=("use_goma=false") |
137 fi | 120 fi |
138 ;; | 121 ;; |
139 disabled) | 122 disabled) |
140 options+=("use_goma=0") | 123 args+=("use_goma=false") |
141 ;; | 124 ;; |
142 esac | 125 esac |
143 echo "${options[*]}" | 126 echo "${args[*]}" |
144 } | |
145 | |
146 set_goma_dir_if_necessary() { | |
147 if [ "$GOMA" = "auto" -a ! -v GOMA_DIR ]; then | |
148 if [ -d "${HOME}/goma" ]; then | |
149 GOMA_DIR="${HOME}/goma" | |
150 fi | |
151 fi | |
152 } | |
153 | |
154 start_goma_if_necessary() { | |
155 if [ "$GOMA" = "auto" -a -v GOMA_DIR ]; then | |
156 "${GOMA_DIR}/goma_ctl.py" ensure_start | |
157 fi | |
158 } | 127 } |
159 | 128 |
160 # We're in src/mojo/tools. We want to get to src. | 129 # We're in src/mojo/tools. We want to get to src. |
161 cd "$(realpath "$(dirname "$0")")/../.." | 130 cd "$(realpath "$(dirname "$0")")/../.." |
162 | 131 |
163 if [ $# -eq 0 ]; then | 132 if [ $# -eq 0 ]; then |
164 do_help | 133 do_help |
165 exit 0 | 134 exit 0 |
166 fi | 135 fi |
167 | 136 |
168 for arg in "$@"; do | 137 for arg in "$@"; do |
169 case "$arg" in | 138 case "$arg" in |
170 # Commands ----------------------------------------------------------------- | 139 # Commands ----------------------------------------------------------------- |
171 help|--help) | 140 help|--help) |
172 do_help | 141 do_help |
173 exit 0 | 142 exit 0 |
174 ;; | 143 ;; |
175 build) | 144 build) |
176 set_goma_dir_if_necessary | |
177 start_goma_if_necessary | |
178 should_do_Debug && do_build Debug | 145 should_do_Debug && do_build Debug |
179 should_do_Release && do_build Release | 146 should_do_Release && do_build Release |
180 ;; | 147 ;; |
181 test) | 148 test) |
182 should_do_Debug && do_unittests Debug | 149 should_do_Debug && do_unittests Debug |
183 should_do_Release && do_unittests Release | 150 should_do_Release && do_unittests Release |
184 ;; | 151 ;; |
185 perftest) | 152 perftest) |
186 should_do_Debug && do_perftests Debug | 153 should_do_Debug && do_perftests Debug |
187 should_do_Release && do_perftests Release | 154 should_do_Release && do_perftests Release |
188 ;; | 155 ;; |
189 pytest) | 156 pytest) |
190 should_do_Debug && do_pytests Debug | 157 should_do_Debug && do_pytests Debug |
191 should_do_Release && do_pytests Release | 158 should_do_Release && do_pytests Release |
192 ;; | 159 ;; |
193 gyp) | 160 gn) |
194 set_goma_dir_if_necessary | 161 should_do_Debug && do_gn Debug |
195 do_gyp | 162 should_do_Release && do_gn Release |
196 ;; | |
197 gypall) | |
198 set_goma_dir_if_necessary | |
199 do_gypall | |
200 ;; | 163 ;; |
201 sync) | 164 sync) |
202 do_sync | 165 do_sync |
203 ;; | 166 ;; |
204 show-bash-alias) | 167 show-bash-alias) |
205 # You want to type something like: | 168 # You want to type something like: |
206 # alias mojob=\ | 169 # alias mojob=\ |
207 # '"$(pwd | sed '"'"'s/\(.*\/src\).*/\1/'"'"')/mojo/tools/mojob.sh"' | 170 # '"$(pwd | sed '"'"'s/\(.*\/src\).*/\1/'"'"')/mojo/tools/mojob.sh"' |
208 # This is quoting hell, so we simply escape every non-alphanumeric | 171 # This is quoting hell, so we simply escape every non-alphanumeric |
209 # character. | 172 # character. |
210 echo alias\ mojob\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\)\ | 173 echo alias\ mojob\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\)\ |
211 \.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojob\.sh\"\' | 174 \.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojob\.sh\"\' |
212 ;; | 175 ;; |
213 # Options ------------------------------------------------------------------ | 176 # Options ------------------------------------------------------------------ |
214 --debug) | 177 --debug) |
215 BUILD_TEST_TYPE=Debug | 178 BUILD_TYPE=Debug |
216 ;; | 179 ;; |
217 --release) | 180 --release) |
218 BUILD_TEST_TYPE=Release | 181 BUILD_TYPE=Release |
219 ;; | 182 ;; |
220 --debug-and-release) | 183 --debug-and-release) |
221 BUILD_TEST_TYPE=Debug_and_Release | 184 BUILD_TYPE=Debug_and_Release |
222 ;; | 185 ;; |
223 --clang) | 186 --clang) |
224 COMPILER=clang | 187 COMPILER=clang |
225 ;; | 188 ;; |
226 --gcc) | 189 --gcc) |
227 COMPILER=gcc | 190 COMPILER=gcc |
228 ;; | 191 ;; |
229 --shared) | |
230 COMPONENT=shared | |
231 ;; | |
232 --static) | |
233 COMPONENT=static | |
234 ;; | |
235 --use-goma) | 192 --use-goma) |
236 GOMA=auto | 193 GOMA=auto |
237 ;; | 194 ;; |
238 --no-use-goma) | 195 --no-use-goma) |
239 GOMA=disabled | 196 GOMA=disabled |
240 ;; | 197 ;; |
241 *) | 198 *) |
242 echo "Unknown command \"${arg}\". Try \"$(basename "$0") help\"." | 199 echo "Unknown command \"${arg}\". Try \"$(basename "$0") help\"." |
243 exit 1 | 200 exit 1 |
244 ;; | 201 ;; |
245 esac | 202 esac |
246 done | 203 done |
247 | 204 |
248 exit 0 | 205 exit 0 |
OLD | NEW |