summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test/ci-scripts/build_embeded_go.py
blob: 1fc70bca27fba93cea0c55944154ba142a4c6c97 (plain)
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
import sys
import os
from subprocess import call

def cut(filename, out):
    with open(filename, 'r') as f:
        flag = False
        codes = []
        for line in f.readlines():
            if line.strip() == '```go':
                flag = True
            elif line.strip() == '```':
                with open(out, 'w') as g:
                    g.write("".join(codes))
                return
            elif flag:
                codes.append(line)

if __name__ == '__main__':
    filename = sys.argv[1]
    out = '/tmp/test.go'
    cut(filename, out)
    ret = call(['go', 'build', '-o', '/tmp/test', out])
    os.remove(out)
    os.remove('/tmp/test')
    sys.exit(ret)