-
Notifications
You must be signed in to change notification settings - Fork 12
/
halut
executable file
·221 lines (191 loc) · 4.93 KB
/
halut
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# inspiration https://github.com/alajmo/template-generator/blob/master/tp
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
set -eEu
set -o pipefail
SAFER_IFS=$'\n\t'
IFS="${SAFER_IFS}"
# an example of a bash command-line script
# the help section is auto-formatted to look legit
# change the name of the app and the version number as needed...
declare -r app_name="halut"
declare -r version="0.1"
_die() {
# Prefix die message with "cross mark (U+274C)", often displayed as a red x.
printf "❌ "
"${@}" 1>&2
exit 1
}
die() {
_die echo "${@}"
}
check_env() {
default_name="halutmatmul"
if [ -z ${REPO_BASE_PATH+x} ]; then
echo "[ERROR] Halutmatmul env is not activated ❌"
echo "[INFO] activate with source halut.env"
exit 1
else
echo "[INFO] Halutmatmul env is activated ✅"
fi
}
_print_help() {
check_env
cat <<HEREDOC
template-generator - Template generator CLI
Usage: ${app_name} [command] [arguments]
Options:
-h, --help Print this help
-v, --version Print script version
Commands:
l|lint Lint cpp and python
t|test [path] Start pytests
e|env Set IIS env
Examples:
# Add here
HEREDOC
}
version() {
echo "$app_name version: $version"
}
compare_conda_env() {
default_name="halutmatmul"
if [[ $CONDA_DEFAULT_ENV == *"halutmatmul"* ]]; then
echo "[INFO] Conda env is activated ✅"
else
echo "[ERROR] Activate conda env halutmatmul ❌, ($CONDA_DEFAULT_ENV)"
exit 1
fi
}
lint_python() {
compare_conda_env
echo "[INFO] lint python with pylint"
pylint src/python/*
echo "[DONE] lint python with pylint"
echo "[INFO] check types with mypy"
mypy
echo "[DONE] check types with mypy"
}
test_python() {
compare_conda_env
echo "[INFO] testing python with pytest"
pytest -srPA
echo "[DONE] pytest finished"
}
lint_hw() {
compare_conda_env
echo "[INFO] lint python with pylint"
pylint hardware/util/* hardware/target/dv/**/*.py hardware/analysis/*.py
echo "[DONE] lint python with pylint"
echo "[INFO] check types with mypy"
mypy hardware/util hardware/target/dv/**/*.py
echo "[DONE] check types with mypy"
echo "[INFO] linting RTL with verilator"
fusesoc --cores-root=. run --target=lint --tool=verilator halut:ip:halut_top
echo "[DONE] linting RTL with verilator"
echo "[INFO] linting RTL with verible"
fusesoc --cores-root=. run --target=lint --tool=veriblelint halut:ip:halut_top
echo "[DONE] linting RTL with verible"
}
# Program option parameters.
_PRINT_OPTION=0
# Options
_VERSION_OPTION=0
# List
_LINT_OPTION=0
_LINT_ARG=""
# Test python
_TEST_OPTION=0
_TEST_ARG=""
# Test hw
_HW_OPTION=0
_HW_LINT=0
# Set environment
_ENV_OPTION=0
_require_argument() {
local _option="${1:-}"
local _argument="${2:-}"
if [[ -z "${_argument}" ]] || [[ "${_argument}" =~ ^- ]]
then
_die printf "Option requires a argument: %s\n" "${_option}"
fi
}
while [ ${#} -gt 0 ]
do
__option="${1:-}"
__maybe_param="${2:-}"
__maybe_param2="${3:-}"
__maybe_param3="${4:-}"
__maybe_param4="${5:-}"
__maybe_param5="${6:-}"
__maybe_param6="${7:-}"
# echo "${__option}"
# echo "${__maybe_param}"
# echo "${__maybe_param2}"
case "${__option}" in
-h|--help)
_PRINT_OPTION=1
;;
-v|--version)
_VERSION_OPTION=1;
;;
l|lint)
_LINT_OPTION=1;
_LINT_ARG="${__maybe_param}";
;;
t|test)
_TEST_OPTION=1;
# _require_argument "${__option}" "${__maybe_param}"
_TEST_ARG="${__maybe_param}";
;;
hw|hardware)
_HW_OPTION=1;
_require_argument "${__option}" "${__maybe_param}"
case "${__maybe_param}" in
l|lint)
_HW_LINT=1;
;;
--endopts)
break
;;
-*)
_die printf "Unexpected hw option: %s\n" "${__maybe_param}"
;;
esac
shift
;;
e|env)
_ENV_OPTION=1;
;;
--endopts)
break
;;
# -*)
# _die printf "Unexpected option: %s\n" "${__option}"
# ;;
esac
shift
done
_main() {
if ((_PRINT_OPTION))
then
_print_help
elif ((_VERSION_OPTION)); then
version
elif ((_LINT_OPTION)); then
lint_python
elif ((_TEST_OPTION)); then
test_python "$_TEST_ARG"
elif ((_ENV_OPTION)); then
check_env
elif ((_HW_OPTION)); then
if ((_HW_LINT)); then
lint_hw
else
_print_help
fi
else
_print_help
fi
}
_main "${@:-}"