Skip to content
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

x/pkgsite/cmd/pkgsite: templates aren't embedded, causing an error if run from another directory #48410

Closed
dmitshur opened this issue Sep 15, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dmitshur
Copy link
Contributor

This issue is likely a subset of #40371.

Environment Details

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

$ go version
go version go1.17.1 darwin/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gopher/Library/Caches/go-build"
GOENV="/Users/gopher/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/gopher/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/gopher/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zb/5p8cwfhj29gf_m8vdy8ylmlr00jwcj/T/go-build316419869=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I tried to use pkgsite as part of reviewing CL 349051. CC @jba.

$ go install golang.org/x/pkgsite/cmd/pkgsite@latest
$ cd $(mktemp -d) && git clone https://go.googlesource.com/tools && cd tools
$ pkgsite

What did you expect to see?

A documentation web server running on localhost:8080.

What did you see instead?

$ pkgsite
2021/09/15 18:36:25 Critical: frontend.NewServer: NewServer(...): error parsing templates: ParseFiles: open static/frontend/frontend.tmpl: no such file or directory

Perhaps //go:embed can be helpful for resolving this issue.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 15, 2021
@gopherbot gopherbot added this to the Unreleased milestone Sep 15, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/359394 mentions this issue: go.mod: update to latest safehtml

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/359395 mentions this issue: many: cmd/pkgsite embeds static assets

gopherbot pushed a commit to golang/pkgsite that referenced this issue Oct 28, 2021
Update github.com/google/safehtml to a version where it supports
embedding.

For golang/go#48410

Change-Id: I4efd6d270b38b0cc00647b3c1e87e46e5e0aab21
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/359394
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
gopherbot pushed a commit to golang/pkgsite that referenced this issue Oct 28, 2021
The `pkgsite` command now embeds all the static assets it needs, so it
need not be told the location of the static/ directory with a
flag. The binary is self-contained and can be placed and invoked from
anywhere.

This required embedding the static/ and third_party/
directories. Since //go:embed cannot reference files outside the
containing package's tree, we had to add trivial Go packages in
static/ and third_party/ to construct `embed.FS`s for those
directories.

Also, the frontend needed to accept `fs.FS` values where it
previously took paths, and `template.TrustedFS` values where it
previously used `template.TrustedSources`. We ended up clumsily
requiring four separate config values:

- A TrustedFS to load templates.

- Two fs.FSs, one for static and one for third_party, to load other
  assets.

- The path to the static directory as a string, solely to support
  dynamic loading in dev mode.

For golang/go#48410

Change-Id: I9eeb351b1c6f23444b9e65b60f2a1d3905d59ef9
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/359395
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
@jba
Copy link
Contributor

jba commented Oct 28, 2021

This is fixed: cmd/pkgsite now embeds everything it needs.

@jba jba closed this as completed Oct 28, 2021
@golang golang locked and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants