Skip to content

GopherJS created some strange directory paths for compiled files. #60

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

Closed
dmitshur opened this issue Jun 26, 2014 · 4 comments
Closed

GopherJS created some strange directory paths for compiled files. #60

dmitshur opened this issue Jun 26, 2014 · 4 comments

Comments

@dmitshur
Copy link
Member

I've just discovered a really puzzling directory, which seems to have been produced by gopherjs incorrectly. My GOPATH contains two workspaces /Users/Dmitri/Dropbox/Work/2013/GoLand and /Users/Dmitri/Dropbox/Work/2013/GoLanding. But there's folder is named /Users/Dmitri/Dropbox/Work/2013/GoLanding:/, and inside it, there is /Users/Dmitri/Dropbox/Work/2013/GoLanding:/Users/Dmitri/...

$ tree /Users/Dmitri/Dropbox/Work/2013/GoLanding:/
/Users/Dmitri/Dropbox/Work/2013/GoLanding:/
└── Users
    └── Dmitri
        ├── Dropbox
        │   └── Work
        │       └── 2013
        │           └── GoLand
        │               └── pkg
        │                   ├── darwin_amd64_js
        │                   │   ├── runtime.a
        │                   │   └── syscall.a
        │                   ├── darwin_amd64_js-min
        │                   │   ├── runtime.a
        │                   │   └── syscall.a
        │                   ├── darwin_js
        │                   │   ├── bufio.a
        │                   │   ├── bytes.a
        │                   │   ├── errors.a
        │                   │   ├── flag.a
        │                   │   ├── fmt.a
        │                   │   ├── go
        │                   │   │   ├── scanner.a
        │                   │   │   └── token.a
        │                   │   ├── io
        │                   │   │   └── ioutil.a
        │                   │   ├── io.a
        │                   │   ├── math.a
        │                   │   ├── os
        │                   │   │   └── exec.a
        │                   │   ├── os.a
        │                   │   ├── path
        │                   │   │   └── filepath.a
        │                   │   ├── reflect.a
        │                   │   ├── regexp
        │                   │   │   └── syntax.a
        │                   │   ├── regexp.a
        │                   │   ├── runtime
        │                   │   │   └── pprof.a
        │                   │   ├── sort.a
        │                   │   ├── strconv.a
        │                   │   ├── strings.a
        │                   │   ├── sync
        │                   │   │   └── atomic.a
        │                   │   ├── sync.a
        │                   │   ├── testing.a
        │                   │   ├── text
        │                   │   │   └── tabwriter.a
        │                   │   ├── time.a
        │                   │   ├── unicode
        │                   │   │   └── utf8.a
        │                   │   └── unicode.a
        │                   └── darwin_js-min
        │                       ├── bufio.a
        │                       ├── bytes.a
        │                       ├── errors.a
        │                       ├── flag.a
        │                       ├── fmt.a
        │                       ├── io
        │                       │   └── ioutil.a
        │                       ├── io.a
        │                       ├── math.a
        │                       ├── os
        │                       │   └── exec.a
        │                       ├── os.a
        │                       ├── path
        │                       │   └── filepath.a
        │                       ├── reflect.a
        │                       ├── regexp
        │                       │   └── syntax.a
        │                       ├── regexp.a
        │                       ├── runtime
        │                       │   └── pprof.a
        │                       ├── sort.a
        │                       ├── strconv.a
        │                       ├── strings.a
        │                       ├── sync
        │                       │   └── atomic.a
        │                       ├── sync.a
        │                       ├── testing.a
        │                       ├── text
        │                       │   └── tabwriter.a
        │                       ├── time.a
        │                       ├── unicode
        │                       │   └── utf8.a
        │                       └── unicode.a
        └── Local
            └── GoTrLand:
                └── Users
                    └── Dmitri
                        └── Dropbox
                            └── Work
                                └── 2013
                                    └── GoLand
                                        └── pkg
                                            ├── darwin_amd64_js
                                            │   ├── runtime.a
                                            │   └── syscall.a
                                            ├── darwin_amd64_js-min
                                            │   ├── runtime.a
                                            │   └── syscall.a
                                            ├── darwin_js
                                            │   ├── bufio.a
                                            │   ├── bytes.a
                                            │   ├── errors.a
                                            │   ├── fmt.a
                                            │   ├── io
                                            │   │   └── ioutil.a
                                            │   ├── io.a
                                            │   ├── math.a
                                            │   ├── os
                                            │   │   └── exec.a
                                            │   ├── os.a
                                            │   ├── path
                                            │   │   └── filepath.a
                                            │   ├── reflect.a
                                            │   ├── regexp
                                            │   │   └── syntax.a
                                            │   ├── regexp.a
                                            │   ├── sort.a
                                            │   ├── strconv.a
                                            │   ├── strings.a
                                            │   ├── sync
                                            │   │   └── atomic.a
                                            │   ├── sync.a
                                            │   ├── time.a
                                            │   ├── unicode
                                            │   │   └── utf8.a
                                            │   └── unicode.a
                                            └── darwin_js-min
                                                ├── bufio.a
                                                ├── bytes.a
                                                ├── errors.a
                                                ├── fmt.a
                                                ├── io
                                                │   └── ioutil.a
                                                ├── io.a
                                                ├── math.a
                                                ├── os
                                                │   └── exec.a
                                                ├── os.a
                                                ├── path
                                                │   └── filepath.a
                                                ├── reflect.a
                                                ├── regexp
                                                │   └── syntax.a
                                                ├── regexp.a
                                                ├── sort.a
                                                ├── strconv.a
                                                ├── strings.a
                                                ├── sync
                                                │   └── atomic.a
                                                ├── sync.a
                                                ├── time.a
                                                ├── unicode
                                                │   └── utf8.a
                                                └── unicode.a

53 directories, 102 files

It looks like something went wrong in calculating paths. This is on OS X. I highly recommend using path/filepath and funcs like http://godoc.org/path/filepath#Join that are safe to use across different OSes (if you're not already), rather than joining strings by hand.

@dmitshur
Copy link
Member Author

I have a guess as to what ended up creating that nesting folder structure. Are you assuming the GOPATH env var contains a path to a single workspace? Because mine contains 2-3 workspaces, colon separated.

$ echo $GOPATH
/Users/Dmitri/Dropbox/Work/2013/GoLanding:/Users/Dmitri/Dropbox/Work/2013/GoLand

See the definition of GOPATH env var:

The GOPATH environment variable lists places to look for Go code. On Unix, the value is a colon-separated string. On Windows, the value is a semicolon-separated string. On Plan 9, the value is a list.

http://golang.org/cmd/go/#hdr-GOPATH_environment_variable

I recommend using http://godoc.org/path/filepath#SplitList to process GOPATH env var. See, e.g. here.

@dmitshur dmitshur changed the title GopherJS writes to GOPATH workspace when doing build. Possible problem because of incorrect GOPATH parsing... Jun 26, 2014
@dmitshur dmitshur changed the title Possible problem because of incorrect GOPATH parsing... GopherJS created some strange directory paths for compiled files. Jun 26, 2014
@dmitshur
Copy link
Member Author

Yep, my guess confirmed:

gopherjs/build/build.go

Lines 364 to 367 in 278c542

// fall back to GOPATH
if err := s.writeLibraryPackage(pkg, s.options.GOPATH+pkg.PkgObj[len(s.options.GOROOT):]); err != nil {
return err
}

It doesn't use http://godoc.org/path/filepath#Join to join the path, and doesn't use http://godoc.org/path/filepath#SplitList to split the GOPATH env var into 1 or more GOPATH workspaces.

Another instance in Import():

gopherjs/build/build.go

Lines 57 to 58 in 278c542

// fall back to GOPATH
gopathPkgObj := build.Default.GOPATH + pkg.PkgObj[len(build.Default.GOROOT):]

@neelance
Copy link
Member

Usually I use path/filepath, must have missed it there. May I ask you for a pull request?

@dmitshur
Copy link
Member Author

Sure, it will take me a few days to get enough free time though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants