GetStream / vg

Virtualgo: Easy and powerful workspace based development for go
MIT License
1.32k stars 45 forks source link

With --full-isolation, package fails to import its own internal packages #26

Closed callpraths closed 6 years ago

callpraths commented 6 years ago

Here's a simplified example: (hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ tree

.
├── hello
├── hello.go
└── internal
    └── hello2
        └── hello2.go

(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ cat internal/hello2/hello2.go package hello2

    import (
            "fmt"
    )

    func Do() {
            fmt.Println("hello2")
    }

(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ vim hello.go (hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ cat hello.go

    package main
    import (
            "hello/internal/hello2"
    )

    func main() {
        hello2.Do()
    }

Without vg: callpraths@remote-workstation:/mnt/work/go/src/hello$ go run hello.go hello2

With vg (but fallback to GOPATH): callpraths@remote-workstation:/mnt/work/go/src/hello$ vg init Creating workspace "hello" with global fallback import mode Activating hello Linking /mnt/work/go/src/hello to workspace 'hello' (hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ go run hello.go hello2

With vg (full isolation): (hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ vg destroy Destroying workspace "hello" Deactivating hello callpraths@remote-workstation:/mnt/work/go/src/hello$ vg init --full-isolation Creating workspace "hello" with full isolation import mode Installing local sources at "/mnt/work/go/src/hello" in workspace as "hello" using bindfs Persisting the local install for "hello" Activating hello Uninstalling "hello" from workspace Unmounting bindfs mount at "/home/callpraths/.virtualgo/hello/src/hello" Removing sources at "/home/callpraths/.virtualgo/hello/src/hello" Installing local sources at "/mnt/work/go/src/hello" in workspace as "hello" using bindfs Persisting the local install for "hello" Linking /mnt/work/go/src/hello to workspace 'hello' (hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ go run hello.go hello.go:4:2: use of internal package not allowed

callpraths commented 6 years ago

There are two distinct problems here: First is minor: The README already talks about go tooling's problems with relative paths with --full-isolation. This is another instance of that.

$ go build hello 

works under some conditions.

The second problem is that to get to the good case above, I had to clear the env before 'vg init' I did:

vg destroy
rm .virtualgo
sudo -u callpraths bash
vg init
go build hello
# works

Looks like we're leaking some env variables from earlier vg invocations in a way that when we run vg init later, we do not call ws.InstallLocalPackagePersistently in initSettings.go because GOPATH is found to not be a prefix of cwd.

JelteF commented 6 years ago

Thanks for the bug report. I'll add the internal package problem to the README in the section with the problems that using absolute paths fixes.

For your second problem I'm a bit confused about how you got in the broken state, but it indeed sounds like a bug. Could you make a separate issue for that problem with full steps for reproducing it? Because it seems quite unrelated to the internal packages problem.

JelteF commented 6 years ago

Just updated the README with this issue.

JelteF commented 6 years ago

I'm gonna close this, since I updated the README. Please open a new issue for the second problem you ran into.