| 1 | #!/bin/bash |
| 2 | |
| 3 | export SOURCE_DIR="$(dirname "$0")" |
| 4 | if test -z "$BUILD_DIR"; then |
| 5 | BUILD_DIR="$SOURCE_DIR" |
| 6 | fi |
| 7 | export BUILD_DIR |
| 8 | |
| 9 | source_top_dir="$SOURCE_DIR/../.." |
| 10 | source_top_dir=$(cd -P "$source_top_dir" 2>/dev/null || cd "$source_top_dir"; pwd) |
| 11 | |
| 12 | build_top_dir="$(dirname "$(dirname "$BUILD_DIR")")" |
| 13 | build_top_dir=$(cd -P "$build_top_dir" 2>/dev/null || cd "$build_top_dir"; pwd) |
| 14 | |
| 15 | # For backward compatibility |
| 16 | : ${NO_BUILD:=$NO_MAKE} |
| 17 | if [ "${NO_BUILD}" != "yes" ]; then |
| 18 | echo "${build_top_dir}/build.ninja" |
| 19 | if [ -f "${build_top_dir}/build.ninja" ]; then |
| 20 | ninja -C "${build_top_dir}" || exit 1 |
| 21 | else |
| 22 | MAKE_ARGS= |
| 23 | n_processors=1 |
| 24 | case $(uname) in |
| 25 | Linux) |
| 26 | n_processors="$(nproc)" |
| 27 | ;; |
| 28 | Darwin) |
| 29 | n_processors="$(/usr/sbin/sysctl -n hw.ncpu)" |
| 30 | ;; |
| 31 | *) |
| 32 | : |
| 33 | ;; |
| 34 | esac |
| 35 | if [ ${n_processors} -gt 1 ]; then |
| 36 | MAKE_ARGS="${MAKE_ARGS} -j${n_processors}" |
| 37 | fi |
| 38 | make -C $build_top_dir ${MAKE_ARGS} > /dev/null || exit 1 |
| 39 | fi |
| 40 | fi |
| 41 | |
| 42 | . "${build_top_dir}/config.sh" |
| 43 | |
| 44 | GRN_GGML_BACKENDS_DIR="$build_top_dir/bin" |
| 45 | export GRN_GGML_BACKENDS_DIR |
| 46 | |
| 47 | GRN_PLUGINS_DIR="$source_top_dir/plugins" |
| 48 | GRN_PLUGINS_PATH="$build_top_dir/plugins" |
| 49 | export GRN_PLUGINS_DIR |
| 50 | export GRN_PLUGINS_PATH |
| 51 | |
| 52 | GRN_RUBY_SCRIPTS_DIR="$source_top_dir/lib/mrb/scripts" |
| 53 | export GRN_RUBY_SCRIPTS_DIR |
| 54 | |
| 55 | case `uname` in |
| 56 | Linux|*BSD) |
| 57 | # llama-cpp |
| 58 | LD_LIBRARY_PATH="$build_top_dir/bin:$LD_LIBRARY_PATH" |
| 59 | # libgroonga |
| 60 | LD_LIBRARY_PATH="$build_top_dir/lib/.libs:$LD_LIBRARY_PATH" |
| 61 | LD_LIBRARY_PATH="$build_top_dir/lib:$LD_LIBRARY_PATH" |
| 62 | export LD_LIBRARY_PATH |
| 63 | ;; |
| 64 | Darwin) |
| 65 | # llama-cpp |
| 66 | DYLD_LIBRARY_PATH="$build_top_dir/bin:$DYLD_LIBRARY_PATH" |
| 67 | # libgroonga |
| 68 | DYLD_LIBRARY_PATH="$build_top_dir/lib/.libs:$DYLD_LIBRARY_PATH" |
| 69 | DYLD_LIBRARY_PATH="$build_top_dir/lib:$DYLD_LIBRARY_PATH" |
| 70 | export DYLD_LIBRARY_PATH |
| 71 | ;; |
| 72 | *) |
| 73 | : |
| 74 | ;; |
| 75 | esac |
| 76 | |
| 77 | if grntest --version > /dev/null 2>&1; then |
| 78 | grntest=(grntest) |
| 79 | else |
| 80 | if test -z "$RUBY"; then |
| 81 | exit 1 |
| 82 | fi |
| 83 | |
| 84 | if ! type bundle > /dev/null 2>&1; then |
| 85 | $RUBY -S gem install bundler |
| 86 | fi |
| 87 | |
| 88 | grntest_dir="$SOURCE_DIR/grntest" |
| 89 | if ! test -d "$grntest_dir"; then |
| 90 | grntest_dir="$BUILD_DIR/grntest" |
| 91 | git clone --depth 1 https://github.com/groonga/grntest.git "$grntest_dir" |
| 92 | (cd "$grntest_dir" && bundle install) |
| 93 | fi |
| 94 | (cd "$grntest_dir"; |
| 95 | if [ "Gemfile" -nt "Gemfile.lock" ]; then |
| 96 | $RUBY -S bundle update |
| 97 | fi) |
| 98 | |
| 99 | groonga_command_dir="$SOURCE_DIR/groonga-command" |
| 100 | if ! test -d "$groonga_command_dir"; then |
| 101 | groonga_command_dir="$BUILD_DIR/groonga-command" |
| 102 | fi |
| 103 | if ! test -d "$groonga_command_dir"; then |
| 104 | git clone --depth 1 \ |
| 105 | https://github.com/groonga/groonga-command.git \ |
| 106 | "$groonga_command_dir" |
| 107 | fi |
| 108 | |
| 109 | groonga_command_parser_dir="$SOURCE_DIR/groonga-command-parser" |
| 110 | if ! test -d "$groonga_command_parser_dir"; then |
| 111 | groonga_command_parser_dir="$BUILD_DIR/groonga-command-parser" |
| 112 | fi |
| 113 | if ! test -d "$groonga_command_parser_dir"; then |
| 114 | git clone --depth 1 \ |
| 115 | https://github.com/groonga/groonga-command-parser.git \ |
| 116 | "$groonga_command_parser_dir" |
| 117 | fi |
| 118 | |
| 119 | gqtp_dir="$SOURCE_DIR/gqtp" |
| 120 | if ! test -d "$gqtp_dir"; then |
| 121 | gqtp_dir="$BUILD_DIR/gqtp" |
| 122 | fi |
| 123 | if ! test -d "$gqtp_dir"; then |
| 124 | git clone --depth 1 \ |
| 125 | https://github.com/ranguba/gqtp.git \ |
| 126 | "$gqtp_dir" |
| 127 | fi |
| 128 | |
| 129 | groonga_client_dir="$SOURCE_DIR/groonga-client" |
| 130 | if ! test -d "$groonga_client_dir"; then |
| 131 | groonga_client_dir="$BUILD_DIR/groonga-client" |
| 132 | fi |
| 133 | if ! test -d "$groonga_client_dir"; then |
| 134 | git clone --depth 1 \ |
| 135 | https://github.com/ranguba/groonga-client.git \ |
| 136 | "$groonga_client_dir" |
| 137 | fi |
| 138 | |
| 139 | groonga_log_dir="$SOURCE_DIR/groonga-log" |
| 140 | if ! test -d "$groonga_log_dir"; then |
| 141 | groonga_log_dir="$BUILD_DIR/groonga-log" |
| 142 | fi |
| 143 | if ! test -d "$groonga_log_dir"; then |
| 144 | git clone --depth 1 \ |
| 145 | https://github.com/groonga/groonga-log.git \ |
| 146 | "$groonga_log_dir" |
| 147 | fi |
| 148 | |
| 149 | groonga_query_log_dir="$SOURCE_DIR/groonga-query-log" |
| 150 | if ! test -d "$groonga_query_log_dir"; then |
| 151 | groonga_query_log_dir="$BUILD_DIR/groonga-query-log" |
| 152 | fi |
| 153 | if ! test -d "$groonga_query_log_dir"; then |
| 154 | git clone --depth 1 \ |
| 155 | https://github.com/groonga/groonga-query-log.git \ |
| 156 | "$groonga_query_log_dir" |
| 157 | fi |
| 158 | |
| 159 | grntest=( |
| 160 | $RUBY |
| 161 | -I "$grntest_dir/lib" |
| 162 | -I "$groonga_command_dir/lib" |
| 163 | -I "$groonga_command_parser_dir/lib" |
| 164 | -I "$gqtp_dir/lib" |
| 165 | -I "$groonga_client_dir/lib" |
| 166 | -I "$groonga_log_dir/lib" |
| 167 | -I "$groonga_query_log_dir/lib" |
| 168 | "$grntest_dir/bin/grntest" |
| 169 | ) |
| 170 | fi |
| 171 | |
| 172 | have_targets="false" |
| 173 | use_gdb="false" |
| 174 | use_rr="false" |
| 175 | use_valgrind="false" |
| 176 | benchmark_mode="false" |
| 177 | next_argument_is_long_option_value="false" |
| 178 | for argument in "$@"; do |
| 179 | case "$argument" in |
| 180 | --*=*) |
| 181 | ;; |
| 182 | --keep-database|--stop-on-failure|--no-*|--version|--help) |
| 183 | # no argument options |
| 184 | ;; |
| 185 | --gdb) |
| 186 | # no argument options |
| 187 | use_gdb="true" |
| 188 | ;; |
| 189 | --rr) |
| 190 | # no argument options |
| 191 | use_rr="true" |
| 192 | ;; |
| 193 | --valgrind) |
| 194 | # no argument options |
| 195 | use_valgrind="true" |
| 196 | ;; |
| 197 | --benchmark) |
| 198 | # no argument options |
| 199 | benchmark_mode="true" |
| 200 | ;; |
| 201 | --*) |
| 202 | next_argument_is_long_option_value="true" |
| 203 | continue |
| 204 | ;; |
| 205 | -*) |
| 206 | ;; |
| 207 | *) |
| 208 | if test "$next_argument_is_long_option_value" != "true"; then |
| 209 | have_targets="true" |
| 210 | fi |
| 211 | ;; |
| 212 | esac |
| 213 | next_argument_is_long_option_value="false" |
| 214 | done |
| 215 | |
| 216 | grntest_options=() |
| 217 | if test "$use_gdb" = "true" -o \ |
| 218 | "$use_rr" = "true" -o \ |
| 219 | "$use_valgrind" = "true"; then |
| 220 | grntest_options+=("--n-workers" "1") |
| 221 | grntest_options+=("--reporter" "stream") |
| 222 | fi |
| 223 | if test "$CI" = "true"; then |
| 224 | grntest_options+=("--reporter" "mark") |
| 225 | fi |
| 226 | grntest_options+=("$@") |
| 227 | if test "$have_targets" != "true"; then |
| 228 | if test "$benchmark_mode" = "true"; then |
| 229 | grntest_options+=("${SOURCE_DIR}/suite_benchmark") |
| 230 | else |
| 231 | grntest_options+=("${SOURCE_DIR}/suite") |
| 232 | fi |
| 233 | fi |
| 234 | |
| 235 | tmpfs_candidates=("/dev/shm" "/run/shm") |
| 236 | for tmpfs in "${tmpfs_candidates[@]}"; do |
| 237 | if test -d $tmpfs -a -w $tmpfs; then |
| 238 | rm -rf "tmp" |
| 239 | ln -s $tmpfs "tmp" |
| 240 | fi |
| 241 | done |
| 242 | |
| 243 | export TZ=Asia/Tokyo |
| 244 | |
| 245 | "${grntest[@]}" \ |
| 246 | --groonga "$GROONGA" \ |
| 247 | --groonga-httpd "$GROONGA_HTTPD" \ |
| 248 | --groonga-suggest-create-dataset "$GROONGA_SUGGEST_CREATE_DATASET" \ |
| 249 | --base-directory "$SOURCE_DIR" \ |
| 250 | "${grntest_options[@]}" |