From 618f7f085966068774f5dc91716308be3a945d67 Mon Sep 17 00:00:00 2001 From: Softonik Date: Sun, 3 Oct 2021 06:19:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=B2=20Go-translator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Magefile.go | 134 +++++++++++++++++++++++++++++++++++ Makefile | 15 ---- main.go => cmd/go-tr/main.go | 2 +- go.mod | 4 +- transpile/service_test.go | 9 ++- 5 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 Magefile.go delete mode 100644 Makefile rename main.go => cmd/go-tr/main.go (96%) diff --git a/Magefile.go b/Magefile.go new file mode 100644 index 0000000..8bff609 --- /dev/null +++ b/Magefile.go @@ -0,0 +1,134 @@ +// +build mage + +package main + +import ( + + // mage:import + . "magefile/docker" + + "github.com/magefile/mage/mg" +) + +var ( + GolangVolume = "golang.my" + MyGoImageName = "my/go" +) + +func init() { + AppName = "go-translator" + ImageName = "my/go" + + BuildFn = build +} + +func Imports() { + Bash(`sudo docker run -ti --rm \ + -h host \ + --net=bridge \ + -v /etc/localtime:/etc/localtime:ro \ + -v ` + GolangVolume + `:/usr/local/go:ro \ + \ + -v /gopath:/gopath:rw \ + -v ${PWD}:/app \ + \ + -e GOPATH=/gopath \ + -e HOME=/home/user \ + \ + -w /app \ + -u 1000 \ + \ + --entrypoint=/bin/bash \ + \ + \ + ` + ImageName + " -c '" + + `go get \ + github.com/onsi/ginkgo/ginkgo \ + github.com/onsi/gomega/... \ + github.com/davecgh/go-spew \ + github.com/h12w/go-socks5 \ + h12.io/socks \ + github.com/vishvananda/netns \ + github.com/milosgajdos/tenus \ + github.com/docker/libcontainer/netlink \ + github.com/go-ping/ping \ + github.com/sirupsen/logrus \ + github.com/songgao/water \ + github.com/aerogo/packet \ + github.com/undefinedlabs/go-mpatch \ + github.com/buger/goreplay \ + github.com/google/gopacket \ + && go list -m -json ... >/dev/null + '`) +} + +func ModTidy() { + Bash(`sudo docker run -ti --rm \ + -h host \ + --net=bridge \ + -v /etc/localtime:/etc/localtime:ro \ + -v ` + GolangVolume + `:/usr/local/go:ro \ + \ + -v /d1/d/gopath/_data:/gopath:rw \ + -v ${PWD}:/app \ + \ + -e GOPATH=/gopath \ + -e HOME=/home/user \ + \ + -w /app \ + -u 1000 \ + \ + --entrypoint=/usr/local/go/bin/go \ + \ + \ + ` + ImageName + " " + + `mod tidy`) + Imports() +} + +func Test() { + mg.Deps(TestLib) +} +func TestLib() { + Bash(`sudo docker run -ti --rm \ + -h host \ + --net=none \ + -v /etc/localtime:/etc/localtime:ro \ + -v ` + GolangVolume + `:/usr/local/go:ro \ + \ + -v /gopath:/gopath:rw \ + -v ${PWD}:/app \ + \ + -e GOPATH=/gopath \ + -e HOME=/home/user \ + \ + -w /app/transpile \ + -u 0 \ + \ + --entrypoint=/usr/local/go/bin/go \ + \ + ` + ImageName + " " + + `test -gcflags=-l`) +} + +func build() { + Bash(`sudo docker run -ti --rm \ + -h host \ + --net=none \ + -v /etc/localtime:/etc/localtime:ro \ + -v ` + GolangVolume + `:/usr/local/go:ro \ + \ + -v /gopath:/gopath:rw \ + -v ${PWD}:/app \ + \ + -e GOPATH=/gopath \ + -e HOME=/home/user \ + \ + -w /app/cmd/go-tr \ + -u 0 \ + \ + --entrypoint=/usr/local/go/bin/go \ + \ + ` + ImageName + " " + + `install`) +} diff --git a/Makefile b/Makefile deleted file mode 100644 index 5c440e2..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -TS=$(shell date -u '+%Y/%m/%d %H:%M:%S') - -all: install test - -install: - @echo $(TS) Installing... - @go get -u github.com/andygeiss/assert - @go get -u github.com/andygeiss/esp32-controller - @go get -u github.com/andygeiss/esp32-transpiler - @echo $(TS) Done. - -test: - @echo $(TS) Testing ... - @go test -v ./... - @echo $(TS) Done. diff --git a/main.go b/cmd/go-tr/main.go similarity index 96% rename from main.go rename to cmd/go-tr/main.go index 4dfd815..47e6416 100644 --- a/main.go +++ b/cmd/go-tr/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "fmt" - "github.com/andygeiss/esp32-transpiler/transpile" + "my/go-translator/transpile" "os" ) diff --git a/go.mod b/go.mod index 2e505f4..4349e35 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/andygeiss/esp32-transpiler +module my/go-translator -go 1.14 +go 1.17 diff --git a/transpile/service_test.go b/transpile/service_test.go index 6faba0f..e66e77b 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -1,8 +1,7 @@ -package transpile_test +package transpile import ( "bytes" - "github.com/andygeiss/esp32-transpiler/transpile" "reflect" "strings" "testing" @@ -22,7 +21,7 @@ func Trim(s string) string { func Validate(source, expected string, t *testing.T) { var in, out bytes.Buffer in.WriteString(source) - service := transpile.NewService(&in, &out) + service := NewService(&in, &out) err := service.Start() got := out.String() tgot, texpected := Trim(got), Trim(expected) @@ -364,7 +363,7 @@ func Test_IfStmt_With_Else(t *testing.T) { if (x == maxX) { Serial.println("1"); } else { - Serial.println("2"); + Serial.println("2"); } } ` @@ -432,7 +431,7 @@ func Test_ForLoop_WithoutInit_And_Post_Transpiles_To_While(t *testing.T) { } serial.Println("Connected!") return nil - } + } func Loop() error {} ` expected := `