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

X . (non-local imports finish)

parent da44885f
......@@ -26,7 +26,7 @@ import (
"testing"
"time"
"../xcommon/xsync"
"lab.nexedi.com/kirr/neo/go/xcommon/xsync"
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/xerr"
......
......@@ -7,7 +7,7 @@ import (
"reflect"
"sort"
"../zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
)
// messages marshalling
......
......@@ -13,7 +13,7 @@ package neo
// XXX move imports out of here
import (
"../zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
"encoding/binary"
"errors"
......
......@@ -28,7 +28,7 @@ import (
"testing"
"unsafe"
"../zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
)
// decode string as hex; panic on error
......
......@@ -77,7 +77,7 @@ import (
// parsed & typechecked input
var fset = token.NewFileSet()
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{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
......@@ -88,10 +88,30 @@ func pos(x interface { Pos() token.Pos }) token.Position {
return fset.Position(x.Pos())
}
// get type name relative to neo package
var neoQualifier types.Qualifier
// get type name in context of neo package
var (
zodbPkg *types.Package
neoPkg *types.Package
)
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
......@@ -110,8 +130,9 @@ type localImporter struct {
}
func (li *localImporter) Import(path string) (*types.Package, error) {
xpath := strings.TrimPrefix(path, "../") // ../zodb -> zodb
pkg := pkgMap[xpath]
// xpath := strings.TrimPrefix(path, "../") // ../zodb -> zodb
// pkg := pkgMap[xpath]
pkg := pkgMap[path]
if pkg != nil {
return pkg, nil
}
......@@ -119,7 +140,7 @@ func (li *localImporter) Import(path string) (*types.Package, error) {
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
// parse
......@@ -137,11 +158,11 @@ func loadPkg(pkgName string, sources ...string) *types.Package {
// typecheck
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 {
log.Fatalf("typecheck: %v", err)
}
pkgMap[pkgName] = pkg
pkgMap[pkgPath] = pkg
return pkg
}
......@@ -151,9 +172,8 @@ func main() {
log.SetFlags(0)
// go through proto.go and AST'ify & typecheck it
loadPkg("zodb", "../zodb/zodb.go")
loadPkg("neo", "proto.go", "neo.go")
neoQualifier = types.RelativeTo(pkgMap["neo"])
zodbPkg = loadPkg("lab.nexedi.com/kirr/neo/go/zodb", "../zodb/zodb.go")
neoPkg = loadPkg("lab.nexedi.com/kirr/neo/go/neo", "proto.go", "neo.go")
// prologue
f := fileMap["proto.go"]
......
......@@ -25,17 +25,17 @@ import (
//"reflect"
"testing"
"../../neo"
//"../../neo/client"
"lab.nexedi.com/kirr/neo/go/neo"
//"lab.nexedi.com/kirr/neo/go/neo/client"
//"../../zodb"
"../../zodb/storage/fs1"
//"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/storage/fs1"
"../../xcommon/tracing"
"../../xcommon/xnet"
"../../xcommon/xnet/pipenet"
"../../xcommon/xsync"
"../../xcommon/xtesting"
"lab.nexedi.com/kirr/neo/go/xcommon/tracing"
"lab.nexedi.com/kirr/neo/go/xcommon/xnet"
"lab.nexedi.com/kirr/neo/go/xcommon/xnet/pipenet"
"lab.nexedi.com/kirr/neo/go/xcommon/xsync"
"lab.nexedi.com/kirr/neo/go/xcommon/xtesting"
"lab.nexedi.com/kirr/go123/exc"
......
......@@ -4,7 +4,7 @@ package neo
import (
"fmt"
"../zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/go123/xerr"
)
......
......@@ -25,7 +25,7 @@ import (
"reflect"
"testing"
"../../../xcommon/xsync"
"lab.nexedi.com/kirr/neo/go/xcommon/xsync"
"lab.nexedi.com/kirr/go123/exc"
)
......
......@@ -24,7 +24,7 @@ import (
"reflect"
"testing"
"../../../zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/go123/exc"
)
......
......@@ -29,8 +29,8 @@ import (
"strings"
"testing"
"../../../zodb"
"./fsb"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/storage/fs1/fsb"
)
type indexEntry struct {
......
......@@ -182,7 +182,7 @@ def main():
print >>f, v
emit("// DO NOT EDIT - AUTOGENERATED (by py/gen-testdata)")
emit("package fs1\n")
emit("import \"../../../zodb\"\n")
emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n")
# index
emit("const _1fs_indexTopPos = %i" % stor._pos)
......
// DO NOT EDIT - AUTOGENERATED (by py/gen-testdata)
package fs1
import "../../../zodb"
import "lab.nexedi.com/kirr/neo/go/zodb"
const _1fs_indexTopPos = 12226
var _1fs_indexEntryv = [...]indexEntry{
......
......@@ -26,8 +26,8 @@ import (
"regexp"
"testing"
"../../zodb/storage/fs1"
"../../zodb"
"lab.nexedi.com/kirr/neo/go/zodb/storage/fs1"
"lab.nexedi.com/kirr/neo/go/zodb"
"github.com/sergi/go-diff/diffmatchpatch"
"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