gopherjs / gopherjs.github.io

GopherJS Playground
https://gopherjs.github.io/playground/
23 stars 12 forks source link

playground: go generate fails when GOROOT is user-writeable. #69

Closed myitcv closed 4 years ago

myitcv commented 6 years ago

Following https://github.com/gopherjs/gopherjs/pull/787 I'm seeing the playground fail to regenerate:

cd `mktemp -d`
export GOPATH=$PWD
go get github.com/gopherjs/gopherjs
go get github.com/gopherjs/gopherjs.github.io/playground
export PATH=$PWD/bin:$PATH
cd src/github.com/gopherjs/gopherjs.github.io/playground
gopherjs --version
go generate

with:

cp: cannot stat '/tmp/gopherjs_playground.QXOsmkSXHw/gopath/pkg/*_js_min/github.com/gopherjs/gopherjs/js.a': No such file or directory

This is, I believe, because js and nosync are fully vendored.

@shurcooL - what do you think is going on here?

dmitshur commented 6 years ago

This is, I believe, because js and nosync are fully vendored.

I don't believe that is the case. Only the source code of those packages is embedded, not their built archives. Please see commit message of https://github.com/gopherjs/gopherjs.github.io/commit/cbdec896dfc8a335278926fc7d6a7e2c43ccdb05.

@shurcooL - what do you think is going on here?

I have a hunch. Is your GOROOT directory writeable by user (i.e., can you modify GOROOT contents without having to use sudo)?

myitcv commented 6 years ago

I have a hunch. Is your GOROOT directory writeable by user (i.e., can you modify GOROOT contents without having to use sudo)?

Yes, it is.

dmitshur commented 6 years ago

That must be why then. The current update.sh assumes it's not. If it is, GopherJS compiler installs the js.a and nosync.a into your GOROOT instead of GOPATH, so lines 33 and 34 won't be able to copy the archives:

https://github.com/gopherjs/gopherjs.github.io/blob/cbdec896dfc8a335278926fc7d6a7e2c43ccdb05/playground/update.sh#L25-L34

I noticed the comment on line 26 is wrong, it should say "GOPATH/pkg" there.

To fix this, we need to find a way of making it work regardless of whether GOROOT is user-writeable or not.

myitcv commented 6 years ago

If it is, GopherJS compiler installs the js.a and nosync.a into your GOROOT instead of GOPATH

Out of interest, why does it do that?

dmitshur commented 6 years ago

That was the behavior Richard implemented about 5 years ago. His GOROOT was user writeable, and he wanted GopherJS to install its archives of the standard library into GOROOT/pkg.

Back then, it would fail to work if GOROOT was not user-writeable.

I prefer my GOROOT not to be user-writeable and not contain any extraneous files, so I reported it as https://github.com/gopherjs/gopherjs/issues/4. Richard worked on a fix that would make GopherJS fall back to writing the standard library archives to GOPATH/pkg if it failed to write to GOROOT/pkg.

That has been the behavior since.

(Later on, I worked on a fix to make it support GOPATH that consisted of more than workspace, see https://github.com/gopherjs/gopherjs/issues/60.)

dmitshur commented 6 years ago

Also note that this behavior is documented, see last paragraph of https://github.com/gopherjs/gopherjs#installation-and-usage.