forked from cpmech/gosl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruncommandall.bash
More file actions
executable file
·162 lines (146 loc) · 2.97 KB
/
runcommandall.bash
File metadata and controls
executable file
·162 lines (146 loc) · 2.97 KB
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
#!/bin/bash
set -e
echo "usage:"
echo " $0 JOB"
echo "where JOB is:"
echo " 0 -- count lines [default]"
echo " 1 -- execute gofmt"
echo " 2 -- execute golint"
echo " 3 -- execute go vet"
echo " 4 -- execute gocyclo"
echo " 5 -- execute goimports"
echo " 6 -- generate depedency graphs"
echo " 7 -- fix links in README files"
JOB=0
if [[ $# != 0 ]]; then
JOB=$1
if [[ $JOB -lt 0 || $JOB -gt 7 ]]; then
echo
echo "Job number $1 is invalid"
echo
exit 1
fi
fi
echo "current JOB = $JOB"
if [[ $JOB == 0 ]]; then
totnfiles=0
totnlines=0
for f in `find . -iname "*.go"`; do
totnfiles=$(($totnfiles+1))
totnlines=$(($totnlines+`wc -l $f | awk '{print $1}'`))
done
echo
echo "Total number of go files = $totnfiles"
echo "Total number of go lines = $totnlines"
exit 0
fi
ALL="
chk \
io \
utl \
plt \
ml \
mpi \
la \
la/mkl \
la/oblas \
num/qpck \
num \
fun \
fun/dbf \
fun/fftw \
gm \
gm/msh \
gm/tri \
gm/rw \
graph \
opt \
rnd \
rnd/sfmt \
rnd/dsfmt \
vtk \
pde \
examples \
tools \
"
rungofmt() {
pkg=$1
for f in *.go; do
gofmt -s -w $f
done
}
rungolint() {
golint .
}
rungovet() {
go vet .
}
rungocyclo() {
level=`gocyclo -top 1 . | awk '{print $1}'`
if [[ $level -gt 15 ]]; then
echo "PROBLEM: level = $level"
fi
}
rungoimports() {
pkg=$1
for f in *.go; do
echo $f
goimports -w $f
done
}
depgraph(){
if [[ $1 == "examples" || $1 == "tools" ]]; then
return
fi
pkg=$1
fna="/tmp/gosl/depgraph-${pkg/\//_}-A.png"
fnb="/tmp/gosl/depgraph-${pkg/\//_}-B.svg"
godepgraph -s github.com/cpmech/gosl/$pkg | dot -Tpng -o $fna
graphpkg -stdout -match 'gosl' github.com/cpmech/gosl/$pkg > $fnb
echo "file <$fna> generated"
echo "file <$fnb> generated"
}
fixreadme() {
pkg=$1
#old="http://rawgit.com/cpmech/gosl/master/doc/xx${pkg/\//-}.html"
#new="https://godoc.org/github.com/cpmech/gosl/${pkg}"
#sed -i 's,'"$old"','"$new"',' README.md
# prepend link before key
#key="More information is available in"
#lnk="[](https://godoc.org/github.com/cpmech/gosl/${pkg})"
#lnk=$(echo "$lnk" | sed 's/\//\\\//g')
#sed -i "/More information is available in/i $lnk \n" README.md
}
if [[ $JOB == 6 ]]; then # graphs
mkdir -p /tmp/gosl
fi
idx=1
for pkg in $ALL; do
HERE=`pwd`
cd $pkg
echo
echo ">>> $idx $pkg <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
if [[ $JOB == 1 ]]; then
rungofmt $pkg
fi
if [[ $JOB == 2 ]]; then
rungolint $pkg
fi
if [[ $JOB == 3 ]]; then
rungovet $pkg
fi
if [[ $JOB == 4 ]]; then
rungocyclo $pkg
fi
if [[ $JOB == 5 ]]; then
rungoimports $pkg
fi
if [[ $JOB == 6 ]]; then
depgraph $pkg
fi
if [[ $JOB == 7 ]]; then
fixreadme $pkg
fi
cd $HERE
(( idx++ ))
done