From ad65d1fa1f43177e507636fe4bbe4038629481b8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 21 Jan 2022 16:47:22 +0300 Subject: [PATCH] compiler: implement custom logic for go1.15 For some reason `foo.go` is interpreted as an http URL, and even if we replace it with `./foo.go` there is an errors with file missing on disk. Because `CompileWithOptions` should be able to compile file under any circumstances, we allocate temporary directory base on version used to compile a binary. Signed-off-by: Evgeniy Stratonikov --- examples/engine/go.mod | 2 +- examples/events/go.mod | 2 +- examples/iterator/go.mod | 2 +- examples/nft-nd-nns/go.mod | 2 +- examples/nft-nd/go.mod | 2 +- examples/oracle/go.mod | 2 +- examples/runtime/go.mod | 2 +- examples/storage/go.mod | 2 +- examples/timer/go.mod | 2 +- examples/token-sale/go.mod | 2 +- examples/token/go.mod | 2 +- pkg/compiler/compiler.go | 13 ++++++++++++- pkg/compiler/debug_test.go | 3 ++- pkg/interop/go.mod | 2 +- pkg/vm/cli/cli_test.go | 4 ++-- 15 files changed, 28 insertions(+), 16 deletions(-) diff --git a/examples/engine/go.mod b/examples/engine/go.mod index c2d338ea3..cb7243d33 100644 --- a/examples/engine/go.mod +++ b/examples/engine/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/engine -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/events/go.mod b/examples/events/go.mod index 24f82ef86..08a6ce2d8 100644 --- a/examples/events/go.mod +++ b/examples/events/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/events -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/iterator/go.mod b/examples/iterator/go.mod index 6aca60c26..ea7d67f35 100644 --- a/examples/iterator/go.mod +++ b/examples/iterator/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/iterator -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/nft-nd-nns/go.mod b/examples/nft-nd-nns/go.mod index 5e5357db8..fc9d8edfd 100644 --- a/examples/nft-nd-nns/go.mod +++ b/examples/nft-nd-nns/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd-nns -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 // indirect diff --git a/examples/nft-nd/go.mod b/examples/nft-nd/go.mod index 3b8d79b43..5a862a7e2 100644 --- a/examples/nft-nd/go.mod +++ b/examples/nft-nd/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/oracle/go.mod b/examples/oracle/go.mod index 4cacd4765..c59a09835 100644 --- a/examples/oracle/go.mod +++ b/examples/oracle/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/oracle -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/runtime/go.mod b/examples/runtime/go.mod index b9462a7fa..4475f5822 100644 --- a/examples/runtime/go.mod +++ b/examples/runtime/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/runtime -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/storage/go.mod b/examples/storage/go.mod index 81a280bfa..0193774c7 100644 --- a/examples/storage/go.mod +++ b/examples/storage/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/storage -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/timer/go.mod b/examples/timer/go.mod index 71f5e39dc..4241e1183 100644 --- a/examples/timer/go.mod +++ b/examples/timer/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/timer -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/token-sale/go.mod b/examples/token-sale/go.mod index 21a0b948e..5f84b10d2 100644 --- a/examples/token-sale/go.mod +++ b/examples/token-sale/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/token-sale -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/examples/token/go.mod b/examples/token/go.mod index 324c07ce3..f66053fc4 100644 --- a/examples/token/go.mod +++ b/examples/token/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/token -go 1.15 +go 1.16 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 689c910e7..47ba5db21 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strings" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -157,7 +158,17 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) { default: panic(fmt.Sprintf("unsupported src type: %T", s)) } - names = append(names, name) + if strings.HasPrefix(runtime.Version(), "go1.15") { + dir, err = ioutil.TempDir("", "*") + if err != nil { + return nil, err + } + name = filepath.Join(dir, filepath.Base(name)) + absName = name + names = append(names, "file="+name) + } else { + names = append(names, name) + } conf.Overlay[absName] = buf } else { if strings.HasSuffix(name, ".go") { diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 447d4490f..b52cde0b9 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -303,7 +303,8 @@ func TestSequencePoints(t *testing.T) { require.NoError(t, err) require.NotNil(t, d) - require.Equal(t, d.Documents, []string{"foo.go"}) + require.Equal(t, 1, len(d.Documents)) + require.True(t, strings.HasSuffix(d.Documents[0], "foo.go")) // Main func has 2 return on 4-th and 6-th lines. ps := d.Methods[0].SeqPoints diff --git a/pkg/interop/go.mod b/pkg/interop/go.mod index 44cb08c10..6aa0ab4c8 100644 --- a/pkg/interop/go.mod +++ b/pkg/interop/go.mod @@ -1,3 +1,3 @@ module github.com/nspcc-dev/neo-go/pkg/interop -go 1.15 \ No newline at end of file +go 1.16 \ No newline at end of file diff --git a/pkg/vm/cli/cli_test.go b/pkg/vm/cli/cli_test.go index e31af479d..28cda13a8 100644 --- a/pkg/vm/cli/cli_test.go +++ b/pkg/vm/cli/cli_test.go @@ -209,7 +209,7 @@ func TestLoad(t *testing.T) { require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm)) filenameErr = "'" + filenameErr + "'" goMod := []byte(`module test.example/vmcli -go 1.15`) +go 1.16`) require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) e := newTestVMCLI(t) @@ -242,7 +242,7 @@ require ( github.com/nspcc-dev/neo-go/pkg/interop v0.0.0 ) replace github.com/nspcc-dev/neo-go/pkg/interop => ` + filepath.Join(wd, "../../interop") + ` -go 1.15`) +go 1.16`) require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) e := newTestVMCLI(t)