|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# © 2018-2019 Konstantin Gredeskoul, All Rights Reserved. |
| 4 | +# MIT License |
| 5 | +# |
| 6 | +# WARNING: This BASH script is completely optional. You don't need it to build this project. |
| 7 | +# |
| 8 | +# If you choose to run this script to build the project, run: |
| 9 | +# |
| 10 | +# $ ./build-and-run |
| 11 | +# |
| 12 | +# It will clean, build and run the tests. |
| 13 | +# |
| 14 | + |
| 15 | +[[ -z $(which git) ]] && { |
| 16 | + echo "You need git installed. Please run 'xcode-select --install' first." |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +export BashMatic="${HOME}/.bashmatic" |
| 21 | +[[ ! -f "${BashMatic}/init.sh" ]] && { |
| 22 | + bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install" |
| 23 | +} |
| 24 | +source "${BashMatic}/init.sh" |
| 25 | + |
| 26 | +export ProjectRoot=$(pwd) |
| 27 | +export BuildDir="${ProjectRoot}/build/run" |
| 28 | +export BashLibRoot="${ProjectRoot}/bin/lib-bash" |
| 29 | +export LibBashRepo="https://github.com/kigster/lib-bash" |
| 30 | + |
| 31 | +simple.header() { |
| 32 | + h1.purple "Simple Tokenizer no jieba" |
| 33 | + local OIFC=${IFC} |
| 34 | + IFS="|" read -r -a gcc_info <<< "$(gcc --version 2>&1 | tr '\n' '|')" |
| 35 | + export IFC=${OIFC} |
| 36 | + h1 "${bldylw}GCC" "${gcc_info[1]}" "${gcc_info[2]}" "${gcc_info[3]}" "${gcc_info[4]}" |
| 37 | + h1 "${bldylw}GIT: ${bldblu}$(git --version)" |
| 38 | + h1 "${bldylw}CMAKE: ${bldblu}$(cmake --version | tr '\n' ' ')" |
| 39 | +} |
| 40 | + |
| 41 | +simple.setup() { |
| 42 | + hl.subtle "Creating Build Folder..." |
| 43 | + run "mkdir -p build/run-no-jieba" |
| 44 | +} |
| 45 | + |
| 46 | +simple.clean() { |
| 47 | + hl.subtle "Cleaning output folders..." |
| 48 | + run 'rm -rf bin-no-jieba/* include/* lib/* build/*' |
| 49 | +} |
| 50 | + |
| 51 | +simple.build() { |
| 52 | + hl.subtle "build..." |
| 53 | + run "cd build/run-no-jieba" |
| 54 | + find . -name "*.gcda" -print0 | xargs -0 rm |
| 55 | + run "cmake -DCODE_COVERAGE=ON -DSIMPLE_WITH_JIEBA=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=${ProjectRoot}/output-no-jieba ../.." |
| 56 | + run.set-next show-output-on |
| 57 | + run "make -j 12" |
| 58 | + run "make install | egrep -v 'gmock|gtest'" |
| 59 | + run "cd ${ProjectRoot}" |
| 60 | +} |
| 61 | + |
| 62 | +simple.tests() { |
| 63 | + hl.subtle "testing..." |
| 64 | + run.set-all show-output-on |
| 65 | + run "cd build/run-no-jieba" |
| 66 | + run "ctest . -V" |
| 67 | + run "cd ${ProjectRoot}" |
| 68 | +} |
| 69 | + |
| 70 | +simple.example() { |
| 71 | + [[ ! -f ./output-no-jieba/bin/sqlite3 ]] && { |
| 72 | + error "You don't have the cmpiled sqlite3 binary yet". |
| 73 | + exit 3 |
| 74 | + } |
| 75 | + hl.subtle "run example..." |
| 76 | + run "cd output-no-jieba/bin/" |
| 77 | + run "./sqlite3 < ${ProjectRoot}/example.sql" |
| 78 | + run "./simple_cpp_example" |
| 79 | + run "cd ${ProjectRoot}" |
| 80 | + |
| 81 | +} |
| 82 | + |
| 83 | +main() { |
| 84 | + simple.header |
| 85 | + simple.setup |
| 86 | + simple.build |
| 87 | + simple.tests |
| 88 | + simple.example |
| 89 | +} |
| 90 | + |
| 91 | +(( $_s_ )) || main |
0 commit comments