Commit 227c1260 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: Fix protogen to work without prior `go install`

When trying to regenerate zproto-marshal.go on a fresh go workspace I
got:

    (neo) (z-dev) (g.env) kirr@deco:~/src/neo/src/lab.nexedi.com/kirr/neo/go/neo/proto$ go generate
    typecheck: ../../zodb/zodb.go:174:2: could not import lab.nexedi.com/kirr/go123/mem (can't find import: "lab.nexedi.com/kirr/go123/mem")
    exit status 1
    proto.go:57: running "sh": exit status 1

Digging around a bit this turned out to be due to that
importer.Default() is using packages in only binary installed form:

    https://github.com/golang/go/issues/19334#issuecomment-283430322
    https://github.com/golang/go/issues/11415

Fix it by using "source" importer which always looks at sources.

(zproto-marshal.go stays unchanged after `go generate` rerun)
parent cb94be39
// Copyright (C) 2016-2018 Nexedi SA and Contributors.
// Copyright (C) 2016-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -145,7 +145,11 @@ func (li *localImporter) Import(path string) (*types.Package, error) {
// importer instance - only 1 so that for 2 top-level packages same dependent
// packages are not reimported several times.
var localImporterObj = &localImporter{importer.Default()}
//
// don't use importer.Default - this importer uses only binaries for installed
// packages, which might a) get stale wrt sources, or b) be completely missing.
// https://github.com/golang/go/issues/11415
var localImporterObj = &localImporter{importer.For("source", nil)}
func loadPkg(pkgPath string, sources ...string) *types.Package {
var filev []*ast.File
......
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