Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/importer: importer doesn't handle relative path correctly #23092

Closed
hirochachacha opened this issue Dec 11, 2017 · 3 comments
Closed

go/importer: importer doesn't handle relative path correctly #23092

hirochachacha opened this issue Dec 11, 2017 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

Create "mypkg" under the current directory, the run following code

package main

import (
	"fmt"
	"go/importer"
	"go/types"
)

func main() {
	imp := importer.For("source", nil)
	pkg, err := imp.Import("./mypkg")
	if err != nil {
		panic(err)
	}
	fmt.Println("path:", pkg.Path())
	fmt.Println("name:", pkg.Name())
}

What did you expect to see?

path: ./mypkg
name: mypkg

What did you see instead?

path: .
name: mypkg

Does this issue reproduce with the latest release (go1.9.2)?

I think so.

System details

go version devel +1055dfce40 Mon Dec 11 22:39:08 2017 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hiro/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTMPDIR=""
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build815608946=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version devel +1055dfce40 Mon Dec 11 22:39:08 2017 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +1055dfce40 Mon Dec 11 22:39:08 2017 +0000
uname -v: Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.1
BuildVersion:	17B1003
lldb --version: lldb-900.0.64
  Swift-4.0
gdb --version: GNU gdb (GDB) 8.0.1

srcimporter use import paths as cache keys. This problem also cause cache confliction.

@ianlancetaylor ianlancetaylor changed the title go/internal/srcimporter: importer doesn't handle relative path correctly go/importer: importer doesn't handle relative path correctly Dec 11, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Dec 11, 2017
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 11, 2017
@ianlancetaylor
Copy link
Contributor

CC @griesemer

@gopherbot
Copy link

Change https://golang.org/cl/83415 mentions this issue: go/internal/srcimporter: fix relative import

@gopherbot
Copy link

Change https://golang.org/cl/102789 mentions this issue: [release-branch.go1.10] go/internal/srcimporter: simplify and fix package file lookup

gopherbot pushed a commit that referenced this issue Mar 29, 2018
…kage file lookup

The old code was a blend of (copied) code that existed before go/build,
and incorrect adjustments made when go/build was introduced. This change
leaves package path determination entirely to go/build and in the process
fixes issues with relative import paths.

Fixes #23092
Fixes #24392

Change-Id: I9e900538b365398751bace56964495c5440ac4ae
Reviewed-on: https://go-review.googlesource.com/83415
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-on: https://go-review.googlesource.com/102789
Run-TryBot: Andrew Bonventre <andybons@golang.org>
@golang golang locked and limited conversation to collaborators Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants