-
Notifications
You must be signed in to change notification settings - Fork 2
/
lnbuild
executable file
·201 lines (180 loc) · 5.08 KB
/
lnbuild
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
# Script variables.
: "${NOMP_SOURCE_DIR:="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"}"
: "${NOMP_SHELL_CONFIG_FILE:="${HOME}/.bashrc"}"
# Terminal output colors.
red=$(tput setaf 1)
green=$(tput setaf 2)
cyan=$(tput setaf 6)
reset=$(tput sgr0)
# Read state variables created by lncfg.
NOMP_LNSTATE_PATH="${NOMP_SOURCE_DIR}/.lnstate"
if [[ -f "${NOMP_LNSTATE_PATH}" ]]; then
source "${NOMP_LNSTATE_PATH}"
else
echo "${red}You should run ./lncfg before running ${0}${reset}."
exit 1
fi
if [[ -z "${NOMP_INSTALL_DIR}" ]]; then
echo "${red}NOMP_INSTALL_DIR is not set in .lnstate file${reset}."
exit 1
fi
# Create commands which goes in shell configuration.
NOMP_ENVIRONMENT=$(cat <<-END
# Setup nomp environment variables.
export NOMP_INSTALL_DIR=${NOMP_INSTALL_DIR}
# Add lnrun script to path.
export PATH=${NOMP_INSTALL_DIR}/bin:\${PATH}
END
)
# Check if the specified shell configuration file exists. If not, look for
# common config files.
if [[ ! -f "${NOMP_SHELL_CONFIG_FILE}" ]]; then
if [[ -f "${HOME}/.bashrc" ]]; then
NOMP_SHELL_CONFIG_FILE="${HOME}/.bashrc"
elif [[ -f "${HOME}/.zshrc" ]]; then
NOMP_SHELL_CONFIG_FILE="${HOME}/.zshrc"
else
NOMP_SHELL_CONFIG_FILE=""
fi
fi
function print_help() {
echo -e "Usage: ${0} [options]\n" \
"${cyan}--help ${reset}\tPrint help for lnbuild script.\n" \
"${cyan}--install ${reset}\tInstall libnomp.\n" \
"${cyan}--format ${reset}\tFormat C code using clang-format.\n" \
"${cyan}--format-check ${reset}\tCheck if C code is formatted correctly.\n" \
"${cyan}--tidy-check ${reset}\tRun clang-tidy to perform static" \
"analysis on C source.\n" \
"${cyan}--black ${reset}\tFormat python code using black.\n" \
"${cyan}--black-check ${reset}\tCheck if python code is formatted" \
"correctly.\n" \
"${cyan}--isort ${reset}\tRun isort to format python imports.\n" \
"${cyan}--isort-check ${reset}\tCheck if python imports are formatted" \
"correctly.\n" \
"${cyan}--flake8-check ${reset}\tRun flake8 tests on python source.\n" \
"${cyan}--pylint-check ${reset}\tRun pylint to perform static analysis" \
"on python source.\n" \
"${cyan}--update-shell ${reset}\tUpdate shell configuration file."
}
# Read in command line arguments.
: ${NOMP_INSTALL:="no"}
: ${NOMP_FORMAT:="no"}
: ${NOMP_FORMAT_CHECK:="no"}
: ${NOMP_TIDY:="no"}
: ${NOMP_PYLINT:="no"}
: ${NOMP_BLACK:="no"}
: ${NOMP_BLACK_CHECK:="no"}
: ${NOMP_ISORT:="no"}
: ${NOMP_ISORT_CHECK:="no"}
: ${NOMP_FLAKE8:="no"}
: ${NOMP_PROMPT:="no"}
if [[ $# -eq 0 ]]; then
print_help
exit 1
fi
while [[ $# -gt 0 ]]; do
case $1 in
--help)
shift
print_help
exit 0
;;
--install)
NOMP_INSTALL="yes"
shift
;;
--format)
NOMP_FORMAT="yes"
shift
;;
--format-check)
NOMP_FORMAT_CHECK="yes"
shift
;;
--tidy-check)
NOMP_TIDY="yes"
shift
;;
--black)
NOMP_BLACK="yes"
shift
;;
--black-check)
NOMP_BLACK_CHECK="yes"
shift
;;
--isort)
NOMP_ISORT="yes"
shift
;;
--isort-check)
NOMP_ISORT_CHECK="yes"
shift
;;
--flake8-check)
NOMP_FLAKE8="yes"
shift
;;
--pylint-check)
NOMP_PYLINT="yes"
shift
;;
--update-shell)
NOMP_PROMPT="yes"
shift
;;
*) echo "${red}Invalid option: ${1}${reset}."
echo "See ${cyan}${0} --help${reset} for the accepted options."
exit 1 ;;
esac
done
if [[ ${NOMP_FORMAT} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target format
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_FORMAT_CHECK} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target format-check
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_TIDY} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target tidy
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_BLACK} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target black
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_BLACK_CHECK} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target black-check
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_ISORT} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target isort
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_ISORT_CHECK} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target isort-check
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_FLAKE8} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target flake8
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_PYLINT} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target pylint
[[ $? -ne 0 ]] && exit 1
fi
if [[ ${NOMP_INSTALL} == "yes" ]]; then
cmake --build "${NOMP_BUILD_DIR}" --target install
[[ $? -ne 0 ]] && exit 1
[[ "${NOMP_PROMPT}" != "yes" ]] && exit 0
if [[ -f ${NOMP_SHELL_CONFIG_FILE} ]]; then
echo -e "${NOMP_ENVIRONMENT}" >> "${NOMP_SHELL_CONFIG_FILE}"
echo "${green}Successfully exported variables to ${NOMP_SHELL_CONFIG_FILE}${reset}."
exit 0
else
echo "${red}Shell configration file ${NOMP_SHELL_CONFIG_FILE} doesn't exist{reset}."
exit 1
fi
fi