Skip to content

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

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
myitcv opened this issue Apr 24, 2018 · 6 comments · Fixed by #72
Closed

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

myitcv opened this issue Apr 24, 2018 · 6 comments · Fixed by #72
Assignees
Labels

Comments

@myitcv
Copy link
Member

myitcv commented Apr 24, 2018

Following gopherjs/gopherjs#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
Copy link
Member

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 cbdec89.

@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
Copy link
Member Author

myitcv commented Apr 24, 2018

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
Copy link
Member

dmitshur commented Apr 24, 2018

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:

# Use an empty GOPATH workspace with just gopherjs,
# so that all the standard library packages get written to GOROOT/pkg.
export GOPATH="$tmp/gopath"
mkdir -p "$GOPATH"/src/github.com/gopherjs/gopherjs
cp -a "$gopherjsgopath"/src/github.com/gopherjs/gopherjs/* "$GOPATH"/src/github.com/gopherjs/gopherjs
gopherjs install -m github.com/gopherjs/gopherjs/js github.com/gopherjs/gopherjs/nosync
mkdir -p pkg/github.com/gopherjs/gopherjs
cp "$GOPATH"/pkg/*_js_min/github.com/gopherjs/gopherjs/js.a pkg/github.com/gopherjs/gopherjs/js.a
cp "$GOPATH"/pkg/*_js_min/github.com/gopherjs/gopherjs/nosync.a pkg/github.com/gopherjs/gopherjs/nosync.a

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.

@dmitshur dmitshur changed the title go generate fails with gopherjs 1.10-3 go generate fails when GOROOT is user-writeable. Apr 24, 2018
@myitcv
Copy link
Member Author

myitcv commented Apr 24, 2018

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
Copy link
Member

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 gopherjs/gopherjs#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 gopherjs/gopherjs#60.)

@dmitshur
Copy link
Member

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

@dmitshur dmitshur added the bug label Apr 24, 2018
@dmitshur dmitshur changed the title go generate fails when GOROOT is user-writeable. playground: go generate fails when GOROOT is user-writeable. Apr 24, 2018
@dmitshur dmitshur self-assigned this Dec 1, 2019
dmitshur added a commit that referenced this issue Dec 1, 2019
Also modify the default "hello world" snippet to use it,
since it's a more general API.

Modernize update.sh slightly to handle variability in
environments better.

Updates #69
dmitshur added a commit that referenced this issue Dec 1, 2019
Previously, the script relied on GOROOT not being user-writable and
failed when that wasn't the case. This change makes it succeed in
both cases.

Fixes #69
dmitshur added a commit that referenced this issue Dec 2, 2019
Also modify the default "hello world" snippet to use it,
since it's a more general API.

Modernize update.sh slightly to handle variability in
environments better.

Updates #69
dmitshur added a commit that referenced this issue Dec 2, 2019
Previously, the script relied on GOROOT not being user-writable and
failed when that wasn't the case. This change makes it succeed in
both cases.

Fixes #69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants