forked from tyoung3/streamwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.sh
executable file
·382 lines (287 loc) · 9.49 KB
/
sw.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash
# FBPGO.sh
pgm=fbpgo
version="0.0.4" ;
# NOTE: Go ignores files and directories beginning with '_', as in _OLD/
Die() {
echo "$0/Die $*"
exit 1
}
Verbose() {
if [ ! -z $verbose ]; then
echo "${pgm}.sh: $*"
fi
}
NotesFBP() {
cat << EOF
* * * * * * * * * * *
#TODO
##Tutorials
###Quick Start
See
### Ignore this
* git clone https://github.com/tyoung3/streamwork
* Run test 'go test ./..
* To update: 'git pull origin master'
###Build a component
####Component Skeleton Generation
* Run script with import path and component name(initial lower case letter). Ex. '... std foo' creates a new component, foo.go, and test, foo_test.go in .../std/
* Modify foo_test.go (test driven development)
* cd .../std; run 'go test foo*'
* Modify foo.go
* repeat until working
####Guidelines
* defer wg.Done() at the beginning
* Test w/-race before committing
* Avoid global variables
* Include process name in messages (standard error code @TODO)
##Trials
* Try nesting fbp calls within a component.
* Try method calls.
##Roadmap
###Frontend
* Develop as a separate module
* networkDefinition conversion to running program.
* networkDefinition > (AddSemiColons) > (expand variables)
> (tokeninize) > (interpret) > (buildGo) > (Launch)
###Backend
Backend prototype is working.
##Signals
. Trap signals
##Copyright
##Git
##Publish
* go mod tidy [Clean up go.sum]
* go list [-u] -m all . See all dependencies
* go get -u=patch . Update to latest patch version(s)
Check branch!!
* git status [must be master branch]
* git pull origin master
* git add --all
* git commit -m "Good commit message"
* git tag -a v1.2.3 -m "Version_Notice_wo_spaces"
* git push origin v0.0.1
##Changes
#DONE
* Run Go doc
* Replace Launch4
* Collate component
##GitHub Flow
###New branch
* git pull origin master
* git checkout -b "Usefull Branch Name"
* git push origin "Usefull Branch Name"
https://github.com/tyoung3/streamwork/pull/new/Fix_Comp_names
* Make changes
* git push --set-upstream origin Fix_Comp_names
* git branch -a [Check branch]
* git commit -m "Good commit message"
* git add --all
* git status
* git push origin Fix_Comp_names
* git checkout master
* $git pull origin master
* git merge --no-ff Fix_Comp_names
* git config --global merge.ff false [ one time ]
https://githubflow.github.io/
* Anything in the master branch is deployable
* To work on something new, create a descriptively named branch
off of master (ie: new-oauth2-scopes)
* Commit to that branch locally and regularly push your work
to the same named branch on the server
* When you need feedback or help, or you think the branch is
ready for merging, open a pull request
* After someone else has reviewed and signed off on the feature,
you can merge it into master
* Once it is merged and pushed to 'master', you can and
should deploy immediately
#$pgm
What follows are some thoughts on designing a comprehensive FBP-based Go language program, $pgm.
Such a system makes possible the direct invocation of a program from its editable flow graph or from the flow graph's stored network text file.
A comprehensive system would allow a wide community of developers to share code effectively.
##Goroutines
Goroutines are lightweight(green) threads communicating with each other within a single address space. Go may schedule goroutines onto multiple operating system threads and therefore onto multiple CPU cores.
Go provides a number of facilities to help solve and to avoid race and deadlock problems.
##Channels
Go design is very FBP-like. Goroutines typically communicate over
Go channels, which are ring buffers of specified capacity(default 1).
Channels and goroutines are built into the Golang syntax(unlike thread libraries in other languages) clarifying and simplifying their operation.
Channels can help to avoid extensive locking of critical code sections.
##Packaging
The basic Go unit is a package, which is imported into a main Go program or another Go package. The single main Go program defines a Go command, an executable program.
Go 'modules' are collections of related packages. Modules will default
with the advent of Go-2.0. Go modules are a recent development.
Go 'plugins' allow for third parties to create interfacing code.
The Go ecosystem avoids complex make files by the way it arranges dependent
code in sub-directories. Package libraries are compiled into the ../pkg directory tree.
$pgm uses modules to allow for third parties to develop $pgm code
independently.
##Performance
Much has been done to make Go programs fast.
A benchmark go program, available at ./github.com/tyoung3/flowfib, can run millions of goroutines communicating over millions of channels in a few seconds.
##Implementation
From a graphable text file, FOO.net (which may include other files
and reference subnets defined elsewhere), generate and run a Go
'main' program, FOO.go. FOO.go will import and invoke standard $pgm go components, passing a structure(interface), providing the component's process name, interface(s), and string arguments.
###Components
Each component is required to be reentrant. The same component may be invoked multiple times in the network definition, but each time with a different name.
Components should be pre-compiled or compiled on the fly and cached.
###Ports
FOO.go will connect component ports as specified in FOO.net. FOO.go will intercept OS signals, SIGUSR1, SIGUSR2, etc. and act accordingly.
###Nodes
FOO.go will also connect with external nodes and processes as specified(or not) in FOO.go.
EOF
}
Notesx() {
cat <<- EOF
Workflow: https://gist.github.com/blackfalcon/8428401
Code generation from BNF: https://github.com/goccmack/gocc
Using gocc: https://medium.freecodecamp.org/write-a-compiler-in-go-quick-guide-30d2f33ac6e0
Tutorial: https://tour.golang.org/welcome/1
Specification: https://golang.org/ref/spec#Notation
http://www.cs.sfu.ca/CourseCentral/383/tjd/ syntaxAndEBNF.html#defining-language-syntax-with-extended-backus-naur-form
FLOWGO:
Expand DVD (A go.comp1)out->in(B go.comp2)out=>in(S Stdout);
This will generate two system processes: 1)a GO process running
two goroutines, and 2)S, which sends B output to the console.
Generate a FBP in GO from a go.net definition.
. Use GOIMPORTS to generate inport lines.
. Generate a Go channel for each flow
. Connect components using goroutines
. SELECT to schedule goroutines
. ? provide for connections to external processes.
EOF
}
src=~/streamwork
MakeDir2() {
dir2=$1
ddate=`date`
Verbose Making $dir2
[ -d $dir2 ] \
|| ( mkdir -p $dir2 \
&& cat << EOF > $dir2/_README.md
$dir2 generated by ${pgm}.sh-v$version on $ddate
EOF
)
}
MakeDir() {
for dir in $*; do
MakeDir2 $dir
done
}
SeeDocs() {
URLS="
https://gist.github.com/blackfalcon/8428401/
https://appliedgo.net/flow/
https://golang.org/
https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1
http://reo.project.cwi.nl/v2/projects/
http://scipipe.org/
https://www.commonwl.org/
"
$BROWSER $* $URLS
go doc cmd/cgo |less
go help c |less
go --help |less
}
HTML=fbpgo.html
IdSkel() {
cat << EOF
/* Generated skeleton fbp component by fbpgo.sh on `date`
input ports: "$inp"
output ports: "$outp"
*/
EOF
}
# Generate a skeleton component
GenSkel() {
pkg=$1; shift;
name=$1
inp=$2
outp=$3
shift 3
[ -z $pkg ] && Die Usage: $0 gs PKG NAME ...
[ -z $name ] && Die Usage: $0 gs PKG NAME ...
[ -d $src/$pkg ] || Die $src/$pkg is missing.
src2=$src/$pkg
pushd $src2 || Die Cannot cd $src2
uname=name
[ -f ${name}.go ] || cat << EOF > ${name}.go
package $pkg
`IdSkel`
import "fmt"
import "sync"
var Version string="v$version"
func $uname(wg *sync.WaitGroup, arg []string, cs []chan interface{} ){
defer wg.Done()
fmt.Println("Running",arg[0])
c := cs[0]
c <- "out1 IP1"
c <- "out1 IP2"
close(c)
}
EOF
go fmt ${name}.go
[ -f ${name}_test.go ] ||cat << EOFY > ${name}_test.go
package $pkg
`IdSkel`
import "testing"
import "fmt"
import "sync"
func TestSkel_$name(t *testing.T) {
var cs []chan interface{}
var wg sync.WaitGroup
arg := []string{"$name","dummy arg[1]","dummy arg[2]"}
fmt.Println(arg[0])
cs = append(cs,make(chan interface{}))
c := cs[0]
go func() {
for {
s, ok := <-c
if ok == true {
fmt.Println("Out1", s)
} else {
fmt.Println("Test_$name Ended")
wg.Done()
return
}
}
}()
wg.Add(2)
go $uname(&wg, arg, cs)
wg.Wait()
}
EOFY
}
CheckOut() {
go get github.com/tyoung3/dummy_repository
}
case $1 in
d) shift; SeeDocs --new-window $*;;
gd)shift; godoc -http=:6060 &
pushd ../; $BROWSER taos:6060/streamwork
;;
gs|skel)shift;GenSkel $*;;
n)shift; NotesFBP | pandoc -s --toc -o $HTML \
&& $BROWSER --new-window $* $HTML;;
r) go run internal/$pgm/*.go;; #/* */
t) shift; go test $* ./... 2>&1 |less ;;
v) echo $pgm-v$version;;
x) $EDITOR ${pgm}.sh internal/${pgm}/${pgm}.go &;;
*) cat <<- EOFX
$0-v$version USAGE:
d . View GO docs
gd . Run and view 'godocs'
gs PKG COMPNAME [INPORTS [OUTPORTS]] . Generate skeleton components
COMPNAME must begin with an upper case letter
PKG directory mus exist
n . Browse $pgm notes
r . Run fbpgo.go
t . Test fbp packages
v . Display version
x . Edit $0
--help . Display this usage
Example: $0 x
EOFX
;;
esac