mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-18 20:51:45 +00:00
util/codegen: permit running in directories without copyright headers
It broke in our corp repo that lacks copyright headers. Change-Id: Iafc433e6b6affe83b45477899455527658dc4f12 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
91e64ca74f
commit
b2b8e62476
@ -58,11 +58,13 @@ func HasNoClone(structTag string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = `// Copyright (c) %d Tailscale Inc & AUTHORS All rights reserved.
|
const copyrightHeader = `// Copyright (c) %d Tailscale Inc & AUTHORS All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Code generated by %v; DO NOT EDIT.
|
`
|
||||||
|
|
||||||
|
const genAndPackageHeader = `// Code generated by %v; DO NOT EDIT.
|
||||||
|
|
||||||
package %s
|
package %s
|
||||||
`
|
`
|
||||||
@ -109,7 +111,10 @@ func (it *ImportTracker) Write(w io.Writer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeHeader(w io.Writer, tool, pkg string, copyrightYear int) {
|
func writeHeader(w io.Writer, tool, pkg string, copyrightYear int) {
|
||||||
fmt.Fprintf(w, header, copyrightYear, tool, pkg)
|
if copyrightYear != 0 {
|
||||||
|
fmt.Fprintf(w, copyrightHeader, copyrightYear)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, genAndPackageHeader, tool, pkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WritePackageFile adds a file with the provided imports and contents to package.
|
// WritePackageFile adds a file with the provided imports and contents to package.
|
||||||
@ -287,7 +292,8 @@ func CopyrightYear(dir string) (year int) {
|
|||||||
Files:
|
Files:
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
if f.IsDir() ||
|
if !f.Type().IsRegular() ||
|
||||||
|
strings.HasPrefix(name, ".") || // includes emacs noise
|
||||||
!strings.HasSuffix(name, ".go") ||
|
!strings.HasSuffix(name, ".go") ||
|
||||||
strings.HasSuffix(name, "_clone.go") ||
|
strings.HasSuffix(name, "_clone.go") ||
|
||||||
strings.HasSuffix(name, "_view.go") ||
|
strings.HasSuffix(name, "_view.go") ||
|
||||||
@ -312,8 +318,5 @@ Files:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if year == 0 {
|
|
||||||
panic("no Copyright line found in any *.go file in " + dir)
|
|
||||||
}
|
|
||||||
return year
|
return year
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user