-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·115 lines (98 loc) · 2.83 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
#
# © 2018 Konstantin Gredeskoul, All Rights Reserved.
# MIT License
#
# WARNING: This BASH script is completely optional. You don't need it to build this project.
#
# If you choose to run this script to build the project, run:
#
# $ ./run.sh
#
# It will clean, build and run the tests.
#
#
( [[ -n ${ZSH_EVAL_CONTEXT} && ${ZSH_EVAL_CONTEXT} =~ :file$ ]] || \
[[ -n $BASH_VERSION && $0 != "$BASH_SOURCE" ]]) && _s_=1 || _s_=0
export _s_
export ProjectRoot=$(pwd)
export BuildDir="${ProjectRoot}/build/run"
export BashLibRoot="${ProjectRoot}/bin/lib-bash"
export LibBashRepo="https://github.com/kigster/lib-bash"
# We are using an awesome BASH library `lib-bash` for prettifying the output, and
# running commands through their LibRun framework.
divider::lib-bash() {
[[ ! -d ${BashLibRoot} ]] && curl -fsSL https://git.io/fxZSi | /usr/bin/env bash
[[ ! -d ${BashLibRoot} ]] && {
printf "Unable to git clone lib-bash repo from ${LibBashRepo}"
exit 1
}
if [[ -f ${BashLibRoot}/Loader.bash ]]; then
cd ${BashLibRoot} > /dev/null
git reset --hard origin/master 2>&1 | cat >/dev/null
git pull 2>&1 | cat >/dev/null
[[ -f Loader.bash ]] && source Loader.bash
cd ${ProjectRoot}
else
printf "\nERROR: unable to find lib-bash library from ${LibBashRepo}!\n"
exit 1
fi
run::set-all show-output-off abort-on-error
}
divider::header() {
h1::purple "Fractional Division With Remainder: A CMake Project Template with Tests"
local OIFC=${IFC}
IFS="|" read -r -a gcc_info <<< "$(gcc --version 2>&1 | tr '\n' '|')"
export IFC=${OIFC}
h1 "${bldylw}GCC" "${gcc_info[1]}" "${gcc_info[2]}" "${gcc_info[3]}" "${gcc_info[4]}"
h1 "${bldylw}GIT: ${bldblu}$(git --version)"
h1 "${bldylw}CMAKE: ${bldblu}$(cmake --version | tr '\n' ' ')"
}
divider::setup() {
hl::subtle "Creating Build Folder..."
run "mkdir -p build/run"
[[ -f .idea/workspace.xml ]] || cp .idea/workspace.xml.example .idea/workspace.xml
}
divider::clean() {
hl::subtle "Cleaning output folders..."
run 'rm -rf bin/d* include/d* lib/*'
}
divider::build() {
run "cd build/run"
run "cmake ../.. "
run "make -j 12"
run "make install | egrep -v 'gmock|gtest'"
run "cd ${ProjectRoot}"
}
divider::tests() {
if [[ -f bin/divider_tests ]]; then
run::set-next show-output-on
run "echo && bin/divider_tests"
else
printf "${bldred}Can't find installed executable ${bldylw}bin/divider_tests.${clr}\n"
exit 2
fi
}
divider::examples() {
[[ ! -f bin/divider ]] && {
error "You don't have the cmpiled binary yet".
exit 3
}
run::set-all show-output-on
hr
run "bin/divider 11 7"
hr
run "bin/divider 1298798375 94759897"
hr
run "bin/divider 78 17"
hr
}
main() {
divider::lib-bash
divider::header
divider::setup
divider::build
divider::tests
divider::examples
}
(( $_s_ )) || main