feature: set default GOPATH for command line and allow self interpreting (#240)

This commit is contained in:
Marc Vertes
2019-07-09 16:57:29 +02:00
committed by Ludovic Fernandez
parent 8ee5cbd7aa
commit 3528b4539d
4 changed files with 22 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"go/build"
"io/ioutil"
"log"
"os"
@@ -24,13 +25,15 @@ func main() {
args := flag.Args()
log.SetFlags(log.Lshortfile)
i := interp.New(interp.Options{})
i := interp.New(interp.Options{GoPath: build.Default.GOPATH})
i.Use(stdlib.Symbols)
i.Use(interp.Symbols)
if len(args) > 0 {
// Skip first os arg to set command line as expected by interpreted main
os.Args = os.Args[1:]
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
b, err := ioutil.ReadFile(args[0])
if err != nil {
log.Fatal("Could not read file: ", args[0])

View File

@@ -5,6 +5,12 @@ import "reflect"
// Symbols variable stores the map of stdlib symbols per package
var Symbols = map[string]map[string]reflect.Value{}
func init() {
Symbols["github.com/containous/yaegi/stdlib"] = map[string]reflect.Value{
"Symbols": reflect.ValueOf(Symbols),
}
}
// Provide access to go standard library (http://golang.org/pkg/)
//go:generate ../cmd/goexports/goexports archive/tar archive/zip

View File

@@ -5,4 +5,10 @@ import "reflect"
// Symbols stores the map of syscall package symbols
var Symbols = map[string]map[string]reflect.Value{}
func init() {
Symbols["github.com/containous/yaegi/stdlib/syscall"] = map[string]reflect.Value{
"Symbols": reflect.ValueOf(Symbols),
}
}
//go:generate ../../cmd/goexports/goexports syscall

View File

@@ -5,4 +5,10 @@ import "reflect"
// Symbols stores the map of unsafe package symbols
var Symbols = map[string]map[string]reflect.Value{}
func init() {
Symbols["github.com/containous/yaegi/stdlib/unsafe"] = map[string]reflect.Value{
"Symbols": reflect.ValueOf(Symbols),
}
}
//go:generate ../../cmd/goexports/goexports unsafe