go/build: Import seems to require absolute srcDir

Created on 10 Feb 2016  路  12Comments  路  Source: golang/go

While investigating go/types issue https://github.com/golang/go/issues/14215, I noticed that (after fixing the obvious go/types bug), build.Import didn't find the desired package if srcDir was relative. Computing its absolute path (relative to cwd) fixed the problem.

Reminder to investigate behavior. Fix and/or document.

FrozenDueToAge

Most helpful comment

@rsc are there any written down plans on the package management changes, changes to go/build and so on that you have planned for future releases? This is probably something that tool authors want to know about way ahead of time.

All 12 comments

cc: @rsc

If build.Import is changed/fixed such that it accepts a relative srcDir we can undo the changes to FindPkg (computing of absolute srcDir) in the following CLs:

http://golang.org/cl/19393
http://golang.org/cl/19394

Another CL to update if this gets addressed: http://golang.org/cl/37405/

@rsc I'm going to assign this one to you (go/build issue); to decide and/or fix or document since you're most familiar with go/build.

I can take care of my CLs that contain the work-arounds.

If the solution turns out to be that build.Import creates an absolute path from a relative srcDir, build.Context may need to also export a new function field AbsPath func(path string) (string, error) (to match the other virtual file system support). By default (function is nil), filepath.Abs would be used instead. As is, libraries using a build.Context cannot handle the case correctly where srcDir is relative and build.Context provides customized file system functions because the libraries can't know how they should implement AbsPath. (see go/internal/srcimporter)

I think we should fix it, for Go 1.10. Will send a CL.

CL https://golang.org/cl/45831 mentions this issue.

Decided to hold off. go/build is basically going to be deprecated for this kind of use in another release or two.

@rsc are there any written down plans on the package management changes, changes to go/build and so on that you have planned for future releases? This is probably something that tool authors want to know about way ahead of time.

Things are in flux with vgo coming down the pike. Pushing this to next release, and perhaps at some point we can just close it as not relevant anymore.

Moving to 1.13 where we may decide this doesn't matter anymore per https://github.com/golang/go/issues/14282#issuecomment-346233120.

This has been "working" as is for > 3 years. With modules this code won't be executed anymore. It's unlikely that there is a need to fix this.

Was this page helpful?
0 / 5 - 0 ratings