1
0
mirror of https://github.com/golang/go synced 2024-11-25 13:57:57 -07:00
go/src
Russ Cox 604f375110 cmd/go: fix relative imports again
I tried before to make relative imports work by simply
invoking the compiler in the right directory, so that
an import of ./foo could be resolved by ./foo.a.
This required creating a separate tree of package binaries
that included the full path to the source directory, so that
/home/gopher/bar.go would be compiled in
tmpdir/work/local/home/gopher and perhaps find
a ./foo.a in that directory.

This model breaks on Windows because : appears in path
names but cannot be used in subdirectory names, and I
missed one or two places where it needed to be removed.

The model breaks more fundamentally when compiling
a test of a package that lives outside the Go path, because
we effectively use a ./ import in the generated testmain,
but there we want to be able to resolve the ./ import
of the test package to one directory and all the other ./
imports to a different directory.  Piggybacking on the compiler's
current working directory is then no longer possible.

Instead, introduce a new compiler option -D prefix that
makes the compiler turn a ./ import into prefix+that,
so that import "./foo" with -D a/b/c turns into import
"a/b/c/foo".  Then we can invent a package hierarchy
"_/" with subdirectories named for file system paths:
import "./foo" in the directory /home/gopher becomes
import "_/home/gopher/foo", and since that final path
is just an ordinary import now, all the ordinary processing
works, without special cases.

We will have to change the name of the hierarchy if we
ever decide to introduce a standard package with import
path "_", but that seems unlikely, and the detail is known
only in temporary packages that get thrown away at the
end of a build.

Fixes #3169.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5732045
2012-03-02 22:16:02 -05:00
..
cmd cmd/go: fix relative imports again 2012-03-02 22:16:02 -05:00
lib9 build: delete make paraphernalia 2012-02-06 13:34:25 -05:00
libbio build: delete make paraphernalia 2012-02-06 13:34:25 -05:00
libmach runtime/pprof: support OS X CPU profiling 2012-02-28 16:18:24 -05:00
pkg go/printer: simpler exprList code, more tests 2012-03-02 11:16:05 -08:00
all.bash cmd/dist: cross-compiling fixes 2012-02-13 22:31:51 -05:00
all.bat build: use setlocal in run.bat 2012-02-16 10:44:55 +11:00
clean.bash build: fix clean.bash 2012-02-15 23:52:07 +09:00
clean.bat build: implement clean.bat 2012-02-20 12:17:27 +11:00
make.bash build: add GO_ prefix to LDFLAGS and GCFLAGS 2012-03-02 02:45:01 -03:00
make.bat make.bat, run.bat: echo newlines 2012-02-16 20:49:50 +00:00
Make.dist cmd/dist: make 'make' quieter for developers 2012-02-08 15:26:47 -05:00
run.bash cmd/dist: cross-compiling fixes 2012-02-13 22:31:51 -05:00
run.bat make.bat, run.bat: echo newlines 2012-02-16 20:49:50 +00:00
sudo.bash build: fix sudo.bash. 2012-02-15 08:42:16 +11:00