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 <evgeniy@nspcc.ru>
This commit is contained in:
Evgeniy Stratonikov 2022-01-21 16:47:22 +03:00
parent cae5b8541d
commit ad65d1fa1f
15 changed files with 28 additions and 16 deletions

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/engine 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/events 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/iterator 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/nft-nd-nns 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652 // indirect

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/nft-nd 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/oracle 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/runtime 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/storage 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/timer 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/token-sale 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/token 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 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220118080652-4eddfdbbc652

View file

@ -12,6 +12,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
@ -157,7 +158,17 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) {
default: default:
panic(fmt.Sprintf("unsupported src type: %T", s)) 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 conf.Overlay[absName] = buf
} else { } else {
if strings.HasSuffix(name, ".go") { if strings.HasSuffix(name, ".go") {

View file

@ -303,7 +303,8 @@ func TestSequencePoints(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, d) 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. // Main func has 2 return on 4-th and 6-th lines.
ps := d.Methods[0].SeqPoints ps := d.Methods[0].SeqPoints

View file

@ -1,3 +1,3 @@
module github.com/nspcc-dev/neo-go/pkg/interop module github.com/nspcc-dev/neo-go/pkg/interop
go 1.15 go 1.16

View file

@ -209,7 +209,7 @@ func TestLoad(t *testing.T) {
require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm)) require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm))
filenameErr = "'" + filenameErr + "'" filenameErr = "'" + filenameErr + "'"
goMod := []byte(`module test.example/vmcli 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)) require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
e := newTestVMCLI(t) e := newTestVMCLI(t)
@ -242,7 +242,7 @@ require (
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0
) )
replace github.com/nspcc-dev/neo-go/pkg/interop => ` + filepath.Join(wd, "../../interop") + ` 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)) require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
e := newTestVMCLI(t) e := newTestVMCLI(t)