Skip to content

Commit

Permalink
add docs/PKG/index.html redirects and import comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adonovan committed Nov 1, 2018
1 parent b9737eb commit 551f300
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/starlark/starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// The starlark command interprets a Starlark file.
// With no arguments, it starts a read-eval-print loop (REPL).
package main
package main // import "go.starlark.net/cmd/starlark"

import (
"flag"
Expand All @@ -15,9 +15,9 @@ import (
"sort"
"strings"

"go.starlark.net/starlark"
"go.starlark.net/repl"
"go.starlark.net/resolve"
"go.starlark.net/starlark"
)

// flags
Expand Down
9 changes: 9 additions & 0 deletions docs/cmd/starlark/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/cmd/starlark'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/cmd/starlark...
</body>
</html>
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<meta http-equiv="refresh" content="0;URL='http://github.com/google/starlark-go'" />
</head>
<body>
Redirecting to github.com/google/starlark-go...
Redirecting to GitHub project github.com/google/starlark-go...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/internal/chunkedfile/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/internal/chunkedfile'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/internal/chunkedfile...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/internal/compile/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/internal/compile'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/internal/compile...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/repl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/repl'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/repl...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/resolve/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/resolve'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/resolve...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/starlark/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/starlark'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/starlark...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/starlarkstruct/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/starlarkstruct'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/starlarkstruct...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/starlarktest/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/starlarktest'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/starlarktest...
</body>
</html>
9 changes: 9 additions & 0 deletions docs/syntax/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/go.starlark.net/syntax'" /></meta>
</head>
<body>
Redirecting to godoc.org page for go.starlark.net/syntax...
</body>
</html>
71 changes: 71 additions & 0 deletions docs/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//+build ignore

// The update command creates/updates the <html><head> elements of
// each subpackage beneath docs so that "go get" requests redirect
// to GitHub and other HTTP requests redirect to godoc.corp.
//
// Usage:
//
// $ cd $GOPATH/src/go.starlark.net
// $ go run docs/update.go
//
package main

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)

func main() {
log.SetFlags(0)
log.SetPrefix("update: ")

cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
if filepath.Base(cwd) != "go.starlark.net" {
log.Fatalf("must run from the go.starlark.net directory")
}

cmd := exec.Command("go", "list", "./...")
cmd.Stdout = new(bytes.Buffer)
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
for _, pkg := range strings.Split(strings.TrimSpace(fmt.Sprint(cmd.Stdout)), "\n") {
rel := strings.TrimPrefix(pkg, "go.starlark.net/") // e.g. "cmd/starlark"
subdir := filepath.Join("docs", rel)
if err := os.MkdirAll(subdir, 0777); err != nil {
log.Fatal(err)
}

// Create missing docs/$rel/index.html files.
html := filepath.Join(subdir, "index.html")
if _, err := os.Stat(html); os.IsNotExist(err) {
data := strings.Replace(defaultHTML, "$PKG", pkg, -1)
if err := ioutil.WriteFile(html, []byte(data), 0666); err != nil {
log.Fatal(err)
}
log.Printf("created %s", html)
}
}
}

const defaultHTML = `<html>
<head>
<meta name="go-import" content="go.starlark.net git https://github.com/google/starlark-go"></meta>
<meta http-equiv="refresh" content="0;URL='http://godoc.org/$PKG'" /></meta>
</head>
<body>
Redirecting to godoc.org page for $PKG...
</body>
</html>
`
2 changes: 1 addition & 1 deletion internal/chunkedfile/chunkedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// then calls chunk.GotError for each error that actually occurred. Any
// discrepancy between the actual and expected errors is reported using
// the client's reporter, which is typically a testing.T.
package chunkedfile
package chunkedfile // import "go.starlark.net/internal/chunkedfile"

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion internal/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Operands, logically uint32s, are encoded using little-endian 7-bit
// varints, the top bit indicating that more bytes follow.
//
package compile
package compile // import "go.starlark.net/internal/compile"

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// expression. If the input still cannot be parsed as an expression,
// the REPL parses and executes it as a file (a list of statements),
// for side effects.
package repl
package repl // import "go.starlark.net/repl"

// TODO(adonovan):
//
Expand Down
2 changes: 1 addition & 1 deletion resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// free variable. It also sets the Locals array of a File for locals
// bound by comprehensions outside any function. Identifiers for global
// variables do not get an index.
package resolve
package resolve // import "go.starlark.net/resolve"

// All references to names are statically resolved. Names may be
// predeclared, global, or local to a function or module-level comprehension.
Expand Down
4 changes: 2 additions & 2 deletions starlarkstruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Package starlarkstruct defines the Starlark 'struct' type,
// an optional language extension.
package starlarkstruct
package starlarkstruct // import "go.starlark.net/starlarkstruct"

// It is tempting to introduce a variant of Struct that is a wrapper
// around a Go struct value, for stronger typing guarantees and more
Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *Struct) String() string {
// Constructor returns the constructor used to create this struct.
func (s *Struct) Constructor() starlark.Value { return s.constructor }

func (s *Struct) Type() string { return "struct" }
func (s *Struct) Type() string { return "struct" }
func (s *Struct) Truth() starlark.Bool { return true } // even when empty
func (s *Struct) Hash() (uint32, error) {
// Same algorithm as Tuple.hash, but with different primes.
Expand Down
2 changes: 1 addition & 1 deletion starlarktest/starlarktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
// The assert.error function, which reports errors to the current Go
// testing.T, requires that clients call SetTest(thread, t) before use.
package starlarktest
package starlarktest // import "go.starlark.net/starlarktest"

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

// Package syntax provides a Starlark parser and abstract syntax tree.
package syntax
package syntax // import "go.starlark.net/syntax"

// A Node is a node in a Starlark syntax tree.
type Node interface {
Expand Down

0 comments on commit 551f300

Please sign in to comment.