aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2024-06-03 13:31:56 -0400
committerGopher Robot <gobot@golang.org>2024-06-03 18:50:37 +0000
commitbc501ffff774407d086ca672d2b03a44ca3f310c (patch)
tree151892d0b70daecfe938f721d67ff8d33a4d38da /cmd
parentabb9f5be80baa843731b1afd18734bf4f857e77f (diff)
downloadgo-x-website-bc501ffff774407d086ca672d2b03a44ca3f310c.tar.xz
cmd/golangorg: fall back to embedded content when _content is not nearby
If golangbuild is run from a directory other than x/website root or its cmd/golangbuild directory, it's more useful to use the embedded content than a directory that does not exist. This was previously possible by explicitly setting the -content flag to the empty string. This change makes it possible to leave the flag unset, which can be handy for go run golang.org/x/website/cmd/golangorg@latest. Change-Id: Id0e33515b15934fdfcd1cbe594ad4c7b969a1d21 Reviewed-on: https://go-review.googlesource.com/c/website/+/589936 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/golangorg/server.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go
index 6c42ade3..d0191b65 100644
--- a/cmd/golangorg/server.go
+++ b/cmd/golangorg/server.go
@@ -74,16 +74,18 @@ func usage() {
}
func main() {
- // Running locally, find the local _content directory,
+ // Running locally, find the local _content directory when it's available nearby,
// so that updates to those files appear on the local dev instance without restarting.
// On App Engine, leave contentDir empty, so we use the embedded copy,
// which is much faster to access than the simulated file system.
if *contentDir == "" && !runningOnAppEngine {
- repoRoot := "../.."
- if _, err := os.Stat("_content"); err == nil {
- repoRoot = "."
+ if fi, err := os.Stat(filepath.Join("..", "..", "_content")); err == nil && fi.IsDir() {
+ *contentDir = fi.Name()
+ } else if fi, err := os.Stat("_content"); err == nil && fi.IsDir() {
+ *contentDir = fi.Name()
+ } else {
+ *contentDir = "" // Fall back to using embedded content.
}
- *contentDir = filepath.Join(repoRoot, "_content")
}
if runningOnAppEngine {
@@ -119,6 +121,7 @@ func main() {
log.Printf("\tversion = %s", runtime.Version())
log.Printf("\taddress = %s", *httpAddr)
log.Printf("\tgoroot = %s", *goroot)
+ log.Printf("\tcontent = %s", contentSource())
handler = loggingHandler(handler)
}
@@ -129,6 +132,18 @@ func main() {
}
}
+// contentSource returns a human-readable description
+// of where the x/website _content dir is coming from.
+func contentSource() string {
+ if *contentDir == "" {
+ return "embedded content"
+ } else if abs, err := filepath.Abs(*contentDir); err == nil {
+ return abs
+ } else {
+ return *contentDir
+ }
+}
+
//go:embed testdata
var testdataFS embed.FS