Commit 5c660da3 authored by Kirill Smelkov's avatar Kirill Smelkov

X . (non-local imports finish)

parent da44885f
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
"testing" "testing"
"time" "time"
"../xcommon/xsync" "lab.nexedi.com/kirr/neo/go/xcommon/xsync"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"reflect" "reflect"
"sort" "sort"
"../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
) )
// messages marshalling // messages marshalling
......
...@@ -13,7 +13,7 @@ package neo ...@@ -13,7 +13,7 @@ package neo
// XXX move imports out of here // XXX move imports out of here
import ( import (
"../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"encoding/binary" "encoding/binary"
"errors" "errors"
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
"testing" "testing"
"unsafe" "unsafe"
"../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
) )
// decode string as hex; panic on error // decode string as hex; panic on error
......
...@@ -77,7 +77,7 @@ import ( ...@@ -77,7 +77,7 @@ import (
// parsed & typechecked input // parsed & typechecked input
var fset = token.NewFileSet() var fset = token.NewFileSet()
var fileMap = map[string]*ast.File{} // fileName -> AST var fileMap = map[string]*ast.File{} // fileName -> AST
var pkgMap = map[string]*types.Package{} // pkgName -> Package var pkgMap = map[string]*types.Package{} // pkgPath -> Package
var typeInfo = &types.Info{ var typeInfo = &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue), Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object), Defs: make(map[*ast.Ident]types.Object),
...@@ -88,10 +88,30 @@ func pos(x interface { Pos() token.Pos }) token.Position { ...@@ -88,10 +88,30 @@ func pos(x interface { Pos() token.Pos }) token.Position {
return fset.Position(x.Pos()) return fset.Position(x.Pos())
} }
// get type name relative to neo package // get type name in context of neo package
var neoQualifier types.Qualifier var (
zodbPkg *types.Package
neoPkg *types.Package
)
func typeName(typ types.Type) string { func typeName(typ types.Type) string {
return types.TypeString(typ, neoQualifier) qf := func(pkg *types.Package) string {
switch pkg {
case neoPkg:
// same package - unqualified
return ""
case zodbPkg:
// zodb is imported - only name
return pkg.Name()
default:
// fully qualified otherwise
return pkg.Path()
}
}
return types.TypeString(typ, qf)
} }
// bytes.Buffer + bell & whistles // bytes.Buffer + bell & whistles
...@@ -110,8 +130,9 @@ type localImporter struct { ...@@ -110,8 +130,9 @@ type localImporter struct {
} }
func (li *localImporter) Import(path string) (*types.Package, error) { func (li *localImporter) Import(path string) (*types.Package, error) {
xpath := strings.TrimPrefix(path, "../") // ../zodb -> zodb // xpath := strings.TrimPrefix(path, "../") // ../zodb -> zodb
pkg := pkgMap[xpath] // pkg := pkgMap[xpath]
pkg := pkgMap[path]
if pkg != nil { if pkg != nil {
return pkg, nil return pkg, nil
} }
...@@ -119,7 +140,7 @@ func (li *localImporter) Import(path string) (*types.Package, error) { ...@@ -119,7 +140,7 @@ func (li *localImporter) Import(path string) (*types.Package, error) {
return li.Importer.Import(path) return li.Importer.Import(path)
} }
func loadPkg(pkgName string, sources ...string) *types.Package { func loadPkg(pkgPath string, sources ...string) *types.Package {
var filev []*ast.File var filev []*ast.File
// parse // parse
...@@ -137,11 +158,11 @@ func loadPkg(pkgName string, sources ...string) *types.Package { ...@@ -137,11 +158,11 @@ func loadPkg(pkgName string, sources ...string) *types.Package {
// typecheck // typecheck
conf := types.Config{Importer: &localImporter{importer.Default()}} conf := types.Config{Importer: &localImporter{importer.Default()}}
pkg, err := conf.Check(pkgName, fset, filev, typeInfo) pkg, err := conf.Check(pkgPath, fset, filev, typeInfo)
if err != nil { if err != nil {
log.Fatalf("typecheck: %v", err) log.Fatalf("typecheck: %v", err)
} }
pkgMap[pkgName] = pkg pkgMap[pkgPath] = pkg
return pkg return pkg
} }
...@@ -151,9 +172,8 @@ func main() { ...@@ -151,9 +172,8 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
// go through proto.go and AST'ify & typecheck it // go through proto.go and AST'ify & typecheck it
loadPkg("zodb", "../zodb/zodb.go") zodbPkg = loadPkg("lab.nexedi.com/kirr/neo/go/zodb", "../zodb/zodb.go")
loadPkg("neo", "proto.go", "neo.go") neoPkg = loadPkg("lab.nexedi.com/kirr/neo/go/neo", "proto.go", "neo.go")
neoQualifier = types.RelativeTo(pkgMap["neo"])
// prologue // prologue
f := fileMap["proto.go"] f := fileMap["proto.go"]
......
...@@ -25,17 +25,17 @@ import ( ...@@ -25,17 +25,17 @@ import (
//"reflect" //"reflect"
"testing" "testing"
"../../neo" "lab.nexedi.com/kirr/neo/go/neo"
//"../../neo/client" //"lab.nexedi.com/kirr/neo/go/neo/client"
//"../../zodb" //"lab.nexedi.com/kirr/neo/go/zodb"
"../../zodb/storage/fs1" "lab.nexedi.com/kirr/neo/go/zodb/storage/fs1"
"../../xcommon/tracing" "lab.nexedi.com/kirr/neo/go/xcommon/tracing"
"../../xcommon/xnet" "lab.nexedi.com/kirr/neo/go/xcommon/xnet"
"../../xcommon/xnet/pipenet" "lab.nexedi.com/kirr/neo/go/xcommon/xnet/pipenet"
"../../xcommon/xsync" "lab.nexedi.com/kirr/neo/go/xcommon/xsync"
"../../xcommon/xtesting" "lab.nexedi.com/kirr/neo/go/xcommon/xtesting"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
......
...@@ -4,7 +4,7 @@ package neo ...@@ -4,7 +4,7 @@ package neo
import ( import (
"fmt" "fmt"
"../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
) )
......
...@@ -25,7 +25,7 @@ import ( ...@@ -25,7 +25,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"../../../xcommon/xsync" "lab.nexedi.com/kirr/neo/go/xcommon/xsync"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
) )
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"../../../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
) )
......
...@@ -29,8 +29,8 @@ import ( ...@@ -29,8 +29,8 @@ import (
"strings" "strings"
"testing" "testing"
"../../../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"./fsb" "lab.nexedi.com/kirr/neo/go/zodb/storage/fs1/fsb"
) )
type indexEntry struct { type indexEntry struct {
......
...@@ -182,7 +182,7 @@ def main(): ...@@ -182,7 +182,7 @@ def main():
print >>f, v print >>f, v
emit("// DO NOT EDIT - AUTOGENERATED (by py/gen-testdata)") emit("// DO NOT EDIT - AUTOGENERATED (by py/gen-testdata)")
emit("package fs1\n") emit("package fs1\n")
emit("import \"../../../zodb\"\n") emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n")
# index # index
emit("const _1fs_indexTopPos = %i" % stor._pos) emit("const _1fs_indexTopPos = %i" % stor._pos)
......
// DO NOT EDIT - AUTOGENERATED (by py/gen-testdata) // DO NOT EDIT - AUTOGENERATED (by py/gen-testdata)
package fs1 package fs1
import "../../../zodb" import "lab.nexedi.com/kirr/neo/go/zodb"
const _1fs_indexTopPos = 12226 const _1fs_indexTopPos = 12226
var _1fs_indexEntryv = [...]indexEntry{ var _1fs_indexEntryv = [...]indexEntry{
......
...@@ -26,8 +26,8 @@ import ( ...@@ -26,8 +26,8 @@ import (
"regexp" "regexp"
"testing" "testing"
"../../zodb/storage/fs1" "lab.nexedi.com/kirr/neo/go/zodb/storage/fs1"
"../../zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"github.com/sergi/go-diff/diffmatchpatch" "github.com/sergi/go-diff/diffmatchpatch"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment