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. 23 gyp - Run gyp for mojo (does not sync), with clang. 24 sync - Sync using gclient (does not run gyp). 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 following commands) should be one of: 29 Build/test options (specified before build/test/perftest): 30 --debug - Build/test in Debug mode. 31 --release - Build/test in Release mode. 32 --debug-and-release - Build/test in both Debug and Release modes (default). 33 Compiler options (specified before gyp): 34 --clang - Use clang (default). 35 --gcc - Use gcc. 36 Component options: 37 --shared Build components as shared libraries (default). 38 --static Build components as static libraries. 39 Mojo in chromium/content (crbug.com/353602): 40 --use-mojo - Enabled (default). 41 --no-use-mojo - Disabled. 42 43 Note: It will abort on the first failure (if any). 44 EOF 45 } 46 47 do_build() { 48 echo "Building in out/$1 ..." 49 ninja -C "out/$1" mojo || exit 1 50 } 51 52 do_unittests() { 53 echo "Running unit tests in out/$1 ..." 54 mojo/tools/test_runner.py mojo/tools/data/unittests "out/$1" \ 55 mojob_test_successes || exit 1 56 } 57 58 do_perftests() { 59 echo "Running perf tests in out/$1 ..." 60 "out/$1/mojo_public_system_perftests" || exit 1 61 } 62 63 do_pytests() { 64 python mojo/tools/run_mojo_python_tests.py || exit 1 65 } 66 67 do_gyp() { 68 local gyp_defines="$(make_gyp_defines)" 69 echo "Running gyp with GYP_DEFINES=$gyp_defines ..." 70 GYP_DEFINES="$gyp_defines" build/gyp_chromium mojo/mojo.gyp || exit 1 71 } 72 73 do_sync() { 74 # Note: sync only (with hooks, but no gyp-ing). 75 GYP_CHROMIUM_NO_ACTION=1 gclient sync || exit 1 76 } 77 78 # Valid values: Debug, Release, or Debug_and_Release. 79 BUILD_TEST_TYPE=Debug_and_Release 80 should_do_Debug() { 81 test "$BUILD_TEST_TYPE" = Debug -o "$BUILD_TEST_TYPE" = Debug_and_Release 82 } 83 should_do_Release() { 84 test "$BUILD_TEST_TYPE" = Release -o "$BUILD_TEST_TYPE" = Debug_and_Release 85 } 86 87 # Valid values: clang or gcc. 88 COMPILER=clang 89 # Valid values: shared or static. 90 COMPONENT=shared 91 make_gyp_defines() { 92 local options=() 93 # Always include these options. 94 options+=("use_aura=1") 95 case "$COMPILER" in 96 clang) 97 options+=("clang=1") 98 ;; 99 gcc) 100 options+=("clang=0") 101 ;; 102 esac 103 case "$COMPONENT" in 104 shared) 105 options+=("component=shared_library") 106 ;; 107 static) 108 options+=("component=static_library") 109 ;; 110 esac 111 echo ${options[*]} 112 } 113 114 # We're in src/mojo/tools. We want to get to src. 115 cd "$(realpath "$(dirname "$0")")/../.." 116 117 if [ $# -eq 0 ]; then 118 do_help 119 exit 0 120 fi 121 122 for arg in "$@"; do 123 case "$arg" in 124 # Commands ----------------------------------------------------------------- 125 help|--help) 126 do_help 127 exit 0 128 ;; 129 build) 130 should_do_Debug && do_build Debug 131 should_do_Release && do_build Release 132 ;; 133 test) 134 should_do_Debug && do_unittests Debug 135 should_do_Release && do_unittests Release 136 ;; 137 perftest) 138 should_do_Debug && do_perftests Debug 139 should_do_Release && do_perftests Release 140 ;; 141 pytest) 142 do_pytests 143 ;; 144 gyp) 145 do_gyp 146 ;; 147 sync) 148 do_sync 149 ;; 150 show-bash-alias) 151 # You want to type something like: 152 # alias mojob=\ 153 # '"$(pwd | sed '"'"'s/\(.*\/src\).*/\1/'"'"')/mojo/tools/mojob.sh"' 154 # This is quoting hell, so we simply escape every non-alphanumeric 155 # character. 156 echo alias\ mojob\=\'\"\$\(pwd\ \|\ sed\ \'\"\'\"\'s\/\\\(\.\*\\\/src\\\)\ 157 \.\*\/\\1\/\'\"\'\"\'\)\/mojo\/tools\/mojob\.sh\"\' 158 ;; 159 # Options ------------------------------------------------------------------ 160 --debug) 161 BUILD_TEST_TYPE=Debug 162 ;; 163 --release) 164 BUILD_TEST_TYPE=Release 165 ;; 166 --debug-and-release) 167 BUILD_TEST_TYPE=Debug_and_Release 168 ;; 169 --clang) 170 COMPILER=clang 171 ;; 172 --gcc) 173 COMPILER=gcc 174 ;; 175 --shared) 176 COMPONENT=shared 177 ;; 178 --static) 179 COMPONENT=static 180 ;; 181 *) 182 echo "Unknown command \"${arg}\". Try \"$(basename "$0") help\"." 183 exit 1 184 ;; 185 esac 186 done 187