forked from Konstantin8105/c4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkilo.sh
executable file
·114 lines (103 loc) · 3.06 KB
/
kilo.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
#!/bin/bash
set -e
go build
mkdir -p ./testdata/
# prepare variables
export C4GO_DIR=$GOPATH/src/github.com/Konstantin8105/c4go
export C4GO=$C4GO_DIR/c4go
export GIT_SOURCE="https://github.com/antirez/kilo.git"
export NAME="kilo"
export TEMP_FOLDER="./testdata/$NAME"
export GO_FILE="$TEMP_FOLDER/$NAME.go"
export GO_APP="$TEMP_FOLDER/$NAME.app"
# prepare C code
if [ ! -d $TEMP_FOLDER ]; then
mkdir -p $TEMP_FOLDER
git clone $GIT_SOURCE $TEMP_FOLDER
sed -i.bak '370iif(row->rsize > 0)' $TEMP_FOLDER/kilo.c
fi
# remove go files from last transpilation
echo "***** remove go files"
rm -f $TEMP_FOLDER/*.go
rm -f $TEMP_FOLDER/*.app
# transpilation of all projects
echo "Transpile to $GO_FILE"
$C4GO transpile \
-o="$GO_FILE" \
$TEMP_FOLDER/kilo.c
# show warnings comments in Go source
echo "Calculate warnings in file: $GO_FILE"
WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l`
echo " After transpiling : $WARNINGS warnings."
# show other warnings
# show amount error from `go build`:
echo "Build to $GO_APP file"
WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
echo " Go build : $WARNINGS_GO warnings"
# amount unsafe
UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
echo " Unsafe : $UNSAFE"
# debugging
if [ "$1" == "-d" ]; then
# try to run
echo " move to folder"
cd ./testdata/kilo/
echo "step 1: create debug file"
$C4GO debug kilo.c
echo "step 2: prepare output data"
echo "" > output.txt
echo "" > output.g.txt
echo "" > output.c.txt
echo "step 3: prepare test script"
echo -e 'Hello my dear friend\x0D\x13\x11' > script.txt
echo "step 4: run Go application"
$C4GO transpile -o=debug.kilo.go debug.kilo.c
go build -o kilo.go.app debug.kilo.go
echo "" > debug.txt
cat script.txt | ./kilo.go.app output.txt 2>&1 && echo "ok" || echo "not ok"
cp output.txt output.g.txt
echo "" > output.txt
cp debug.txt debug.go.txt
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo "step 5: run C application"
clang -o kilo.c.app debug.kilo.c 2>&1
echo "" > debug.txt
cat script.txt | ./kilo.c.app output.txt 2>&1 && echo "ok" || echo "not ok"
cp output.txt output.c.txt
echo "" > output.txt
cp debug.txt debug.c.txt
echo "step 5"
echo "-----------------------------"
echo "debug"
diff -y -t debug.c.txt debug.go.txt 2>&1 > debug.diff && echo "ok" || echo "not ok"
# cat debug.diff
echo "-----------------------------"
echo "output"
diff -y -t output.c.txt output.g.txt 2>&1 > output.diff && echo "ok" || echo "not ok"
cat output.diff
echo "-----------------------------"
echo "step 6: move back"
cd ../../
fi
# Arguments menu
echo " -s for show detail of Go build errors"
if [ "$1" == "-s" ]; then
# show go build warnings
# c4go warnings
cat $GO_FILE | grep "^// Warning" | sort | uniq
# show amount error from `go build`:
go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
fi