]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: respect internal directories during 'go run'
authorRuss Cox <rsc@golang.org>
Thu, 14 Jan 2016 03:35:17 +0000 (22:35 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 14 Jan 2016 04:01:47 +0000 (04:01 +0000)
Fixes #12217.

Change-Id: I5ee6cb18eaa66bdec1affe689aa531c05e719fc9
Reviewed-on: https://go-review.googlesource.com/18645
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/go/build.go
src/cmd/go/go_test.go
src/cmd/go/testdata/src/run/bad.go [new file with mode: 0644]
src/cmd/go/testdata/src/run/good.go [new file with mode: 0644]
src/cmd/go/testdata/src/run/internal/internal.go [new file with mode: 0644]
src/cmd/go/testdata/src/run/subdir/internal/private/private.go [new file with mode: 0644]

index ebeb11cf636f8d6d4c52d587f1722f585dd9e8d8..6a8edaf6d25f065559261a555c681a2a5954019b 100644 (file)
@@ -822,7 +822,9 @@ func goFilesPackage(gofiles []string) *Package {
        pkg := new(Package)
        pkg.local = true
        pkg.cmdline = true
+       stk.push("main")
        pkg.load(&stk, bp, err)
+       stk.pop()
        pkg.localPrefix = dirToImportPath(dir)
        pkg.ImportPath = "command-line-arguments"
        pkg.target = ""
index cc36b43de3beaf99528b98078fb9d1347f93cf7e..50c7521831e0703d34c17cc6aed1afbbd2c86817 100644 (file)
@@ -961,6 +961,16 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) {
        tg.grepBoth("use of internal package not allowed", "wrote error message for testdata/testinternal2")
 }
 
+func TestRunInternal(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       dir := filepath.Join(tg.pwd(), "testdata")
+       tg.setenv("GOPATH", dir)
+       tg.run("run", filepath.Join(dir, "src/run/good.go"))
+       tg.runFail("run", filepath.Join(dir, "src/run/bad.go"))
+       tg.grepStderr("use of internal package not allowed", "unexpected error for run/bad.go")
+}
+
 func testMove(t *testing.T, vcs, url, base, config string) {
        testenv.MustHaveExternalNetwork(t)
 
diff --git a/src/cmd/go/testdata/src/run/bad.go b/src/cmd/go/testdata/src/run/bad.go
new file mode 100644 (file)
index 0000000..c1cc3ac
--- /dev/null
@@ -0,0 +1,5 @@
+package main
+
+import _ "run/subdir/internal/private"
+
+func main() {}
diff --git a/src/cmd/go/testdata/src/run/good.go b/src/cmd/go/testdata/src/run/good.go
new file mode 100644 (file)
index 0000000..0b67dce
--- /dev/null
@@ -0,0 +1,5 @@
+package main
+
+import _ "run/internal"
+
+func main() {}
diff --git a/src/cmd/go/testdata/src/run/internal/internal.go b/src/cmd/go/testdata/src/run/internal/internal.go
new file mode 100644 (file)
index 0000000..5bf0569
--- /dev/null
@@ -0,0 +1 @@
+package internal
diff --git a/src/cmd/go/testdata/src/run/subdir/internal/private/private.go b/src/cmd/go/testdata/src/run/subdir/internal/private/private.go
new file mode 100644 (file)
index 0000000..735e4dc
--- /dev/null
@@ -0,0 +1 @@
+package private