mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-28 20:45:34 +00:00
all: update tools that manage copyright headers
Update all code generation tools, and those that check for license headers to use the new standard header. Also update copyright statement in LICENSE file. Fixes #6865 Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
parent
71029cea2d
commit
947c14793a
3
LICENSE
3
LICENSE
@ -1,7 +1,6 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2020 Tailscale & AUTHORS.
|
||||
All rights reserved.
|
||||
Copyright (c) 2020 Tailscale Inc & AUTHORS.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
@ -14,26 +14,24 @@
|
||||
)
|
||||
|
||||
var (
|
||||
year = flag.Int("year", 0, "copyright year")
|
||||
file = flag.String("file", "", "file to modify")
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, `
|
||||
usage: addlicense -year YEAR -file FILE <subcommand args...>
|
||||
usage: addlicense -file FILE <subcommand args...>
|
||||
`[1:])
|
||||
|
||||
flag.PrintDefaults()
|
||||
fmt.Fprintf(os.Stderr, `
|
||||
addlicense adds a Tailscale license to the beginning of file,
|
||||
using year as the copyright year.
|
||||
addlicense adds a Tailscale license to the beginning of file.
|
||||
|
||||
It is intended for use with 'go generate', so it also runs a subcommand,
|
||||
which presumably creates the file.
|
||||
|
||||
Sample usage:
|
||||
|
||||
addlicense -year 2021 -file pull_strings.go stringer -type=pull
|
||||
addlicense -file pull_strings.go stringer -type=pull
|
||||
`[1:])
|
||||
os.Exit(2)
|
||||
}
|
||||
@ -53,7 +51,7 @@ func main() {
|
||||
check(err)
|
||||
f, err := os.OpenFile(*file, os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
check(err)
|
||||
_, err = fmt.Fprintf(f, license, *year)
|
||||
_, err = fmt.Fprint(f, license)
|
||||
check(err)
|
||||
_, err = f.Write(b)
|
||||
check(err)
|
||||
@ -69,8 +67,7 @@ func check(err error) {
|
||||
}
|
||||
|
||||
var license = `
|
||||
// Copyright (c) %d Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
`[1:]
|
||||
|
@ -79,7 +79,7 @@ func main() {
|
||||
w("}")
|
||||
}
|
||||
cloneOutput := pkg.Name + "_clone.go"
|
||||
if err := codegen.WritePackageFile("tailscale.com/cmd/cloner", pkg, cloneOutput, codegen.CopyrightYear("."), it, buf); err != nil {
|
||||
if err := codegen.WritePackageFile("tailscale.com/cmd/cloner", pkg, cloneOutput, it, buf); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ func main() {
|
||||
genView(buf, it, typ, pkg.Types)
|
||||
}
|
||||
out := pkg.Name + "_view.go"
|
||||
if err := codegen.WritePackageFile("tailscale/cmd/viewer", pkg, out, codegen.CopyrightYear("."), it, buf); err != nil {
|
||||
if err := codegen.WritePackageFile("tailscale/cmd/viewer", pkg, out, it, buf); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if runCloner {
|
||||
|
@ -955,7 +955,7 @@ func (c *sclient) handleFrameSendPacket(ft frameType, fl uint32) error {
|
||||
// dropReason is why we dropped a DERP frame.
|
||||
type dropReason int
|
||||
|
||||
//go:generate go run tailscale.com/cmd/addlicense -year 2021 -file dropreason_string.go go run golang.org/x/tools/cmd/stringer -type=dropReason -trimprefix=dropReason
|
||||
//go:generate go run tailscale.com/cmd/addlicense -file dropreason_string.go go run golang.org/x/tools/cmd/stringer -type=dropReason -trimprefix=dropReason
|
||||
|
||||
const (
|
||||
dropReasonUnknownDest dropReason = iota // unknown destination pubkey
|
||||
|
@ -17,7 +17,7 @@
|
||||
// https://www.rfc-editor.org/rfc/pdfrfc/rfc6887.txt.pdf
|
||||
// https://tools.ietf.org/html/rfc6887
|
||||
|
||||
//go:generate go run tailscale.com/cmd/addlicense -year 2021 -file pcpresultcode_string.go go run golang.org/x/tools/cmd/stringer -type=pcpResultCode -trimprefix=pcpCode
|
||||
//go:generate go run tailscale.com/cmd/addlicense -file pcpresultcode_string.go go run golang.org/x/tools/cmd/stringer -type=pcpResultCode -trimprefix=pcpCode
|
||||
|
||||
type pcpResultCode uint8
|
||||
|
||||
|
@ -586,7 +586,7 @@ func (c *Client) createOrGetMapping(ctx context.Context) (external netip.AddrPor
|
||||
}
|
||||
}
|
||||
|
||||
//go:generate go run tailscale.com/cmd/addlicense -year 2021 -file pmpresultcode_string.go go run golang.org/x/tools/cmd/stringer -type=pmpResultCode -trimprefix=pmpCode
|
||||
//go:generate go run tailscale.com/cmd/addlicense -file pmpresultcode_string.go go run golang.org/x/tools/cmd/stringer -type=pmpResultCode -trimprefix=pmpCode
|
||||
|
||||
type pmpResultCode uint16
|
||||
|
||||
|
@ -9,17 +9,14 @@
|
||||
check_file() {
|
||||
got=$1
|
||||
|
||||
for year in `seq 2019 2023`; do
|
||||
want=$(cat <<EOF
|
||||
// Copyright (c) $year Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
want=$(cat <<EOF
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
EOF
|
||||
)
|
||||
if [ "$got" = "$want" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
)
|
||||
if [ "$got" = "$want" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -50,7 +47,7 @@ for file in $(find $1 -name '*.go' -not -path '*/.git/*'); do
|
||||
# Generated syscall wrappers
|
||||
;;
|
||||
*)
|
||||
header="$(head -3 $file)"
|
||||
header="$(head -2 $file)"
|
||||
if ! check_file "$header"; then
|
||||
fail=1
|
||||
echo "${file#$1/} doesn't have the right copyright header:"
|
||||
|
@ -35,9 +35,8 @@ func generate(goos string) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var out bytes.Buffer
|
||||
out.WriteString(`// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
out.WriteString(`// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Code generated by gen_deps.go; DO NOT EDIT.
|
||||
|
||||
|
@ -7,10 +7,8 @@
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/dave/jennifer/jen"
|
||||
"github.com/iancoleman/strcase"
|
||||
@ -41,9 +39,8 @@ func main() {
|
||||
}
|
||||
defer fout.Close()
|
||||
|
||||
fmt.Fprintf(fout, "// Copyright (c) %d Tailscale Inc & AUTHORS All rights reserved.\n", time.Now().Year())
|
||||
fout.WriteString("// Use of this source code is governed by a BSD-style\n")
|
||||
fout.WriteString("// license that can be found in the LICENSE file.\n")
|
||||
fout.WriteString("// Copyright (c) Tailscale Inc & AUTHORS\n")
|
||||
fout.WriteString("// SPDX-License-Identifier: BSD-3-Clause\n")
|
||||
fout.WriteString("\n")
|
||||
fout.WriteString("// +build linux\n\n")
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
@ -13,16 +12,12 @@
|
||||
"go/types"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/packages"
|
||||
"golang.org/x/tools/imports"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/must"
|
||||
)
|
||||
|
||||
// LoadTypes returns all named types in pkgName, keyed by their type name.
|
||||
@ -57,9 +52,8 @@ func HasNoClone(structTag string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
const copyrightHeader = `// Copyright (c) %d Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
const copyrightHeader = `// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
`
|
||||
|
||||
@ -109,18 +103,16 @@ func (it *ImportTracker) Write(w io.Writer) {
|
||||
fmt.Fprintf(w, ")\n\n")
|
||||
}
|
||||
|
||||
func writeHeader(w io.Writer, tool, pkg string, copyrightYear int) {
|
||||
if copyrightYear != 0 {
|
||||
fmt.Fprintf(w, copyrightHeader, copyrightYear)
|
||||
}
|
||||
func writeHeader(w io.Writer, tool, pkg string) {
|
||||
fmt.Fprint(w, copyrightHeader)
|
||||
fmt.Fprintf(w, genAndPackageHeader, tool, pkg)
|
||||
}
|
||||
|
||||
// WritePackageFile adds a file with the provided imports and contents to package.
|
||||
// The tool param is used to identify the tool that generated package file.
|
||||
func WritePackageFile(tool string, pkg *packages.Package, path string, copyrightYear int, it *ImportTracker, contents *bytes.Buffer) error {
|
||||
func WritePackageFile(tool string, pkg *packages.Package, path string, it *ImportTracker, contents *bytes.Buffer) error {
|
||||
buf := new(bytes.Buffer)
|
||||
writeHeader(buf, tool, pkg.Name, copyrightYear)
|
||||
writeHeader(buf, tool, pkg.Name)
|
||||
it.Write(buf)
|
||||
if _, err := buf.Write(contents.Bytes()); err != nil {
|
||||
return err
|
||||
@ -271,51 +263,3 @@ func IsViewType(typ types.Type) bool {
|
||||
}
|
||||
return t.Field(0).Name() == "ж"
|
||||
}
|
||||
|
||||
// CopyrightYear reports the greatest copyright year in non-generated *.go files
|
||||
// in the current directory, for use in the copyright line of generated code.
|
||||
//
|
||||
// It panics on I/O error, as it's assumed this is only being used by "go
|
||||
// generate" or GitHub actions.
|
||||
//
|
||||
// TODO(bradfitz,dgentry): determine what heuristic to use for all this: latest
|
||||
// year, earliest, none? don't list years at all? IANAL. Get advice of others.
|
||||
// For now we just want to unbreak the tree. See Issue 6865.
|
||||
func CopyrightYear(dir string) (year int) {
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
rxYear := regexp.MustCompile(`^// Copyright \(c\) (20\d{2}) `)
|
||||
rxGenerated := regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.$`)
|
||||
Files:
|
||||
for _, f := range files {
|
||||
name := f.Name()
|
||||
if !f.Type().IsRegular() ||
|
||||
strings.HasPrefix(name, ".") || // includes emacs noise
|
||||
!strings.HasSuffix(name, ".go") ||
|
||||
strings.HasSuffix(name, "_clone.go") ||
|
||||
strings.HasSuffix(name, "_view.go") ||
|
||||
strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
src, err := os.ReadFile(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bs := bufio.NewScanner(bytes.NewReader(src))
|
||||
for bs.Scan() {
|
||||
line := bs.Bytes()
|
||||
if m := rxYear.FindSubmatch(line); m != nil {
|
||||
if y := must.Get(strconv.Atoi(string(m[1]))); y > year {
|
||||
year = y
|
||||
}
|
||||
continue
|
||||
}
|
||||
if rxGenerated.Match(line) {
|
||||
continue Files
|
||||
}
|
||||
}
|
||||
}
|
||||
return year
|
||||
}
|
||||
|
@ -4061,7 +4061,7 @@ func (de *endpoint) sendDiscoPing(ep netip.AddrPort, discoKey key.DiscoPublic, t
|
||||
// discoPingPurpose is the reason why a discovery ping message was sent.
|
||||
type discoPingPurpose int
|
||||
|
||||
//go:generate go run tailscale.com/cmd/addlicense -year 2020 -file discopingpurpose_string.go go run golang.org/x/tools/cmd/stringer -type=discoPingPurpose -trimprefix=ping
|
||||
//go:generate go run tailscale.com/cmd/addlicense -file discopingpurpose_string.go go run golang.org/x/tools/cmd/stringer -type=discoPingPurpose -trimprefix=ping
|
||||
const (
|
||||
// pingDiscovery means that purpose of a ping was to see if a
|
||||
// path was valid.
|
||||
|
Loading…
Reference in New Issue
Block a user