golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.71k stars 17.5k forks source link

x/tools/cmd/present: doesn't work with go in git master (1.16) #43459

Open ayang64 opened 3 years ago

ayang64 commented 3 years ago

What version of Go are you using (go version)?

go 1.16

$ go version
go version devel +95ce805d14 Thu Dec 31 02:24:55 2020 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
go version devel +95ce805d14 Thu Dec 31 02:24:55 2020 +0000 linux/amd64
ayan@alia:/tmp/y$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ayan/.cache/go-build"
GOENV="/home/ayan/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ayan/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ayan"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ayan/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ayan/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +95ce805d14 Thu Dec 31 02:24:55 2020 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/y/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2261444876=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I installed the present tool using go get:

$ go get golang.org/x/tools/cmd/present
go: downloading golang.org/x/tools v0.0.0-20201230224404-63754364767c
go: downloading golang.org/x/net v0.0.0-20201021035429-f5854403a974
go: downloading github.com/yuin/goldmark v1.2.1

That error occurs because go didn't place the source for the present tool in my $GOPATH.

What did you expect to see?

$ present
2021/01/01 14:19:58 Open your web browser and visit http://127.0.0.1:3999

What did you see instead?

$  present
Couldn't find gopresent files: no required module provides package golang.org/x/tools/cmd/present: working directory is not part of a module

By default, gopresent locates the slide template files and associated
static content by looking for a "golang.org/x/tools/cmd/present" package
in your Go workspaces (GOPATH).

You may use the -base flag to specify an alternate location.

I believe the right thing to do is to embed the static assets and templates in the present tool. I submitted a PR that appears to work at:

https://github.com/golang/tools/pull/264

toothrot commented 3 years ago

/cc @rsc

mikijov commented 3 years ago

Workaround is to invoke it with -base, but that is obviously far from ideal. present -base ~/go/src/golang.org/x/tools/cmd/present

ayang64 commented 3 years ago

@mikijov -- thank you for that work-around! i think part of my issue is that go 1.16 doesn't place the source for package in an easy to find location. for example, when i use go get, the static files land in ${GOPATH}/pkg/mod/golang.org/x/tools@v0.0.0-20210115202250-e0d201561e39/cmd/present.

so this patch is meant to simplify things by embedding all of the static files.

zikaeroh commented 3 years ago

x/tools (and any other module wanting to support Go versions before 1.16) cannot make use of the embed package due to #40067; if you want to embed the assets, you'd need to do it by other means.

EDIT: The restriction is any package in x/tools (my mistake); if you don't import it you don't see the error, but it would make present not possible to use even with build tags.

ayang64 commented 3 years ago

x/tools (and any other module wanting to support Go versions before 1.16) cannot make use of the embed package due to #40067; if you want to embed the assets, you'd need to do it by other means.

I understand. So should I simply close this PR and the related issues?

zikaeroh commented 3 years ago

The PR/CL maybe, but I wouldn't personally be closing the issues as you're still getting them. This is certainly still an issue; it's just that the fix can't be the embed package unless #40067 is fixed and backported to old versions of Go (or, we wait a couple of years).

zikaeroh commented 3 years ago

FWIW, my original reasoning here was wrong (sorry 😦); embed could be used in a package like this as it's not importable (so the go tooling was happy before); just note that this would still have to wait for x/tools/cmd/present to no longer need to be supported for anything below 1.16.

Koshmaar commented 3 years ago

I updated from golang v1.14 to 1.16 and thought things will work the same (or better), but this is sad exception. Before it was working perfectly, now by default it fails miserably and one need to search internet and only on internal bugtracker it's possible to find explanation what's happening. How can this change/workaround not be explained in the present docs? Sorry for my tone, but such user unfriendliness is incredible.

What worked for me was present -base ~/go/pkg/mod/golang.org/x/tools@v0.1.0/cmd/present - maybe at least add this as a suggestion in cmdline output.

nerg4l commented 3 years ago

Instead of using -base flag you could turn off modules temporarily with GO111MODULE=off present. Starting this way it will run as espected as of now.

gopherbot commented 2 years ago

Change https://golang.org/cl/356290 mentions this issue: cmd/present: embed contents when available