diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 0b51a22d4f9..24c2a05d226 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -383,6 +383,7 @@ func goFilesPackage(gofiles []string) *Package { bp, err := ctxt.ImportDir(dir, 0) pkg := new(Package) + pkg.local = true pkg.load(&stk, bp, err) pkg.localPrefix = dirToImportPath(dir) pkg.ImportPath = "command-line-arguments" @@ -1202,7 +1203,7 @@ func (gcToolchain) pack(b *builder, p *Package, objDir, afile string, ofiles []s func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action, mainpkg string, ofiles []string) error { importArgs := b.includeArgs("-L", allactions) - return b.run(p.Dir, p.ImportPath, tool(archChar+"l"), "-o", out, importArgs, buildLdflags, mainpkg) + return b.run(".", p.ImportPath, tool(archChar+"l"), "-o", out, importArgs, buildLdflags, mainpkg) } func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error { @@ -1284,7 +1285,7 @@ func (tools gccgcToolchain) ld(b *builder, p *Package, out string, allactions [] ldflags = append(ldflags, afile) } ldflags = append(ldflags, cgoldflags...) - return b.run(p.Dir, p.ImportPath, "gccgo", "-o", out, buildGccgoflags, ofiles, "-Wl,-(", ldflags, "-Wl,-)") + return b.run(".", p.ImportPath, "gccgo", "-o", out, buildGccgoflags, ofiles, "-Wl,-(", ldflags, "-Wl,-)") } func (gccgcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error { @@ -1308,6 +1309,9 @@ func (b *builder) gccld(p *Package, out string, flags []string, obj []string) er // gccCmd returns a gcc command line prefix func (b *builder) gccCmd(objdir string) []string { + // NOTE: env.go's mkEnv knows that the first three + // strings returned are "gcc", "-I", objdir (and cuts them off). + // TODO: HOST_CC? a := []string{"gcc", "-I", objdir, "-g", "-O2"} diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index 9bdd56240b7..1b6a8c5124c 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -279,9 +279,8 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package p.copyBuild(bp) // The localPrefix is the path we interpret ./ imports relative to. - // Now that we've fixed the import path, it's just the import path. // Synthesized main packages sometimes override this. - p.localPrefix = p.ImportPath + p.localPrefix = dirToImportPath(p.Dir) if err != nil { p.Incomplete = true @@ -343,6 +342,16 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package } p1 := loadImport(path, p.Dir, stk, p.build.ImportPos[path]) if p1.local { + if !p.local && p.Error == nil { + p.Error = &PackageError{ + ImportStack: stk.copy(), + Err: fmt.Sprintf("local import %q in non-local package", path), + } + pos := p.build.ImportPos[path] + if len(pos) > 0 { + p.Error.Pos = pos[0].String() + } + } path = p1.ImportPath importPaths[i] = path }