Mojo: Improve my mojob script.
[chromium-blink-merge.git] / mojo / tools / mojob.sh
blob06b496c039475bfbf6a1ff81f538eee17b89b564
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.
6 # This a simple script to make building/testing Mojo components easier (on
7 # Linux).
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.
14 do_help() {
15 cat << EOF
16 Usage: $(basename "$0") [command|option ...]
18 command should be one of:
19 build - Build.
20 test - Run unit tests (does not build).
21 perftest - Run Release and Debug perf tests (does not build).
22 gyp - Run gyp for mojo (does not sync), with clang.
23 sync - Sync using gclient (does not run gyp).
24 show-bash-alias - Outputs an appropriate bash alias for mojob. In bash do:
25 \$ eval \`mojo/tools/mojob.sh show-bash-alias\`
27 option (which will only apply to following commands) should be one of:
28 Build/test options (specified before build/test/perftest):
29 --debug - Build/test in Debug mode.
30 --release - Build/test in Release mode.
31 --debug-and-release - Build/test in both Debug and Release modes (default).
32 Compiler options (specified before gyp):
33 --clang - Use clang (default).
34 --gcc - Use gcc.
35 Component options:
36 --shared Build components as shared libraries (default).
37 --static Build components as static libraries.
39 Note: It will abort on the first failure (if any).
40 EOF
43 do_build() {
44 echo "Building in out/$1 ..."
45 ninja -C "out/$1" mojo || exit 1
48 do_unittests() {
49 echo "Running unit tests in out/$1 ..."
50 "out/$1/mojo_system_unittests" || exit 1
51 "out/$1/mojo_public_unittests" || exit 1
52 "out/$1/mojo_bindings_test" || exit 1
53 "out/$1/mojo_js_bindings_unittests" || exit 1
56 do_perftests() {
57 echo "Running perf tests in out/$1 ..."
58 "out/$1/mojo_public_perftests" || exit 1
61 do_gyp() {
62 local gyp_defines="$(make_gyp_defines)"
63 echo "Running gyp with GYP_DEFINES=$gyp_defines ..."
64 GYP_DEFINES="$gyp_defines" build/gyp_chromium mojo/mojo.gyp
67 # Valid values: Debug, Release, or Debug_and_Release.
68 BUILD_TEST_TYPE=Debug_and_Release
69 should_do_Debug() {
70 test "$BUILD_TEST_TYPE" = Debug -o "$BUILD_TEST_TYPE" = Debug_and_Release
72 should_do_Release() {
73 test "$BUILD_TEST_TYPE" = Release -o "$BUILD_TEST_TYPE" = Debug_and_Release
76 # Valid values: clang or gcc.
77 COMPILER=clang
78 # Valid values: shared or static.
79 COMPONENT=shared
80 make_gyp_defines() {
81 local options=()
82 # Always include these options.
83 options+=("use_aura=1")
84 case "$COMPILER" in
85 clang)
86 options+=("clang=1")
88 gcc)
89 options+=("clang=0")
91 esac
92 case "$COMPONENT" in
93 shared)
94 options+=("component=shared_library")
96 static)
97 options+=("component=static_library")
99 esac
100 echo ${options[*]}
103 # We're in src/mojo/tools. We want to get to src.
104 cd "$(realpath "$(dirname "$0")")/../.."
106 if [ $# -eq 0 ]; then
107 do_help
108 exit 0
111 for arg in "$@"; do
112 case "$arg" in
113 # Commands -----------------------------------------------------------------
114 help|--help)
115 do_help
116 exit 0
118 build)
119 should_do_Debug && do_build Debug
120 should_do_Release && do_build Release
122 test)
123 should_do_Debug && do_unittests Debug
124 should_do_Release && do_unittests Release
126 perftest)
127 should_do_Debug && do_perftests Debug
128 should_do_Release && do_perftests Release
130 gyp)
131 do_gyp
133 sync)
134 # Note: sync only, no gyp-ing.
135 gclient sync --nohooks
137 show-bash-alias)
138 # You want to type something like:
139 # alias mojob=\
140 # '"$(pwd | sed '"'"'s/\(.*\/src\).*/\1/'"'"')/mojo/tools/mojob.sh"'
141 # This is quoting hell, so we simply escape every non-alphanumeric
142 # character.
143 echo alias\ mojob\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\)\
144 \.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojob\.sh\"\'
146 # Options ------------------------------------------------------------------
147 --debug)
148 BUILD_TEST_TYPE=Debug
150 --release)
151 BUILD_TEST_TYPE=Release
153 --debug-and-release)
154 BUILD_TEST_TYPE=Debug_and_Release
156 --clang)
157 COMPILER=clang
159 --gcc)
160 COMPILER=gcc
162 --shared)
163 COMPONENT=shared
165 --static)
166 COMPONENT=static
169 echo "Unknown command \"${arg}\". Try \"$(basename "$0") help\"."
170 exit 1
172 esac
173 done