all: add a test for copyright headers
Fix a few files with no or unusual copyright headers.
Manually add copyright headers to the legacy testprotos, which will
(probably) never be regenerated.
Change-Id: Ifb52fa0eb59bf9d2de40b8df7e581a3c9731c883
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/220498
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
index 6d1b602..65bf3b5 100644
--- a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
+++ b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.proto
diff --git a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.proto b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.proto
index 4f93027..e96d472 100644
--- a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.proto
+++ b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.proto
@@ -1,3 +1,7 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
syntax = "proto2";
package oneoftest;
diff --git a/integration_test.go b/integration_test.go
index 1afd13b..757d410 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -18,6 +18,7 @@
"os"
"os/exec"
"path/filepath"
+ "regexp"
"runtime"
"strings"
"sync"
@@ -95,6 +96,10 @@
t.Fatalf("unformatted source files:\n%v", diff)
}
})
+ t.Run("CopyrightHeaders", func(t *testing.T) {
+ files := strings.Split(strings.TrimSpace(mustRunCommand(t, "git", "ls-files", "*.go", "*.proto")), "\n")
+ mustHaveCopyrightHeader(t, files)
+ })
t.Run("CommittedGitChanges", func(t *testing.T) {
diff := mustRunCommand(t, "git", "diff", "--no-prefix", "HEAD")
if strings.TrimSpace(diff) != "" {
@@ -362,6 +367,47 @@
}
}
+var copyrightRegex = []*regexp.Regexp{
+ regexp.MustCompile(`^// Copyright \d\d\d\d The Go Authors\. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file\.
+`),
+ // Generated .pb.go files from main protobuf repo.
+ regexp.MustCompile(`^// Protocol Buffers - Google's data interchange format
+// Copyright \d\d\d\d Google Inc\. All rights reserved\.
+`),
+}
+
+var noCopyrightHeader = []string{
+ // Missing copyright header upstream.
+ "internal/testprotos/benchmarks/datasets/",
+}
+
+func mustHaveCopyrightHeader(t *testing.T, files []string) {
+ var bad []string
+File:
+ for _, file := range files {
+ for _, prefix := range noCopyrightHeader {
+ if strings.HasPrefix(file, prefix) {
+ continue File
+ }
+ }
+ b, err := ioutil.ReadFile(file)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, re := range copyrightRegex {
+ if loc := re.FindIndex(b); loc != nil && loc[0] == 0 {
+ continue File
+ }
+ }
+ bad = append(bad, file)
+ }
+ if len(bad) > 0 {
+ t.Fatalf("files with missing/bad copyright headers:\n %v", strings.Join(bad, "\n "))
+ }
+}
+
type command struct {
Dir string
Env []string
diff --git a/internal/flags/proto_legacy_disable.go b/internal/flags/proto_legacy_disable.go
index de110ca..a72995f 100644
--- a/internal/flags/proto_legacy_disable.go
+++ b/internal/flags/proto_legacy_disable.go
@@ -1,6 +1,6 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
+// license that can be found in the LICENSE file.
// +build !protolegacy
diff --git a/internal/flags/proto_legacy_enable.go b/internal/flags/proto_legacy_enable.go
index dbd2cd5..772e2f0 100644
--- a/internal/flags/proto_legacy_enable.go
+++ b/internal/flags/proto_legacy_enable.go
@@ -1,6 +1,6 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
+// license that can be found in the LICENSE file.
// +build protolegacy
diff --git a/internal/pragma/pragma.go b/internal/pragma/pragma.go
index 9101531..49dc4fc 100644
--- a/internal/pragma/pragma.go
+++ b/internal/pragma/pragma.go
@@ -1,6 +1,6 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
+// license that can be found in the LICENSE file.
// Package pragma provides types that can be embedded into a struct to
// statically enforce or prevent certain language properties.
diff --git a/internal/protolegacy/proto.go b/internal/protolegacy/proto.go
index b9f023a..96b44d9 100644
--- a/internal/protolegacy/proto.go
+++ b/internal/protolegacy/proto.go
@@ -1,6 +1,6 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
+// license that can be found in the LICENSE file.
// Package protolegacy is a stub version of the v1 proto package
// to satisfy internal/testprotos/legacy dependencies.
diff --git a/internal/testprotos/legacy/proto2_20160225_2fc053c5/test.pb.go b/internal/testprotos/legacy/proto2_20160225_2fc053c5/test.pb.go
index 7472cd9..8e0835e 100644
--- a/internal/testprotos/legacy/proto2_20160225_2fc053c5/test.pb.go
+++ b/internal/testprotos/legacy/proto2_20160225_2fc053c5/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go.
// source: proto2_20160225_2fc053c5/test.proto
// DO NOT EDIT!
diff --git a/internal/testprotos/legacy/proto2_20160519_a4ab9ec5/test.pb.go b/internal/testprotos/legacy/proto2_20160519_a4ab9ec5/test.pb.go
index 2a3b0f3..19bfe41 100644
--- a/internal/testprotos/legacy/proto2_20160519_a4ab9ec5/test.pb.go
+++ b/internal/testprotos/legacy/proto2_20160519_a4ab9ec5/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go.
// source: proto2_20160519_a4ab9ec5/test.proto
// DO NOT EDIT!
diff --git a/internal/testprotos/legacy/proto2_20180125_92554152/test.pb.go b/internal/testprotos/legacy/proto2_20180125_92554152/test.pb.go
index e05f830..782dd07 100644
--- a/internal/testprotos/legacy/proto2_20180125_92554152/test.pb.go
+++ b/internal/testprotos/legacy/proto2_20180125_92554152/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto2_20180125_92554152/test.proto
diff --git a/internal/testprotos/legacy/proto2_20180430_b4deda09/test.pb.go b/internal/testprotos/legacy/proto2_20180430_b4deda09/test.pb.go
index f256f02..b6e4899 100644
--- a/internal/testprotos/legacy/proto2_20180430_b4deda09/test.pb.go
+++ b/internal/testprotos/legacy/proto2_20180430_b4deda09/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto2_20180430_b4deda09/test.proto
diff --git a/internal/testprotos/legacy/proto2_20180814_aa810b61/test.pb.go b/internal/testprotos/legacy/proto2_20180814_aa810b61/test.pb.go
index 7b25f5c..47e825a 100644
--- a/internal/testprotos/legacy/proto2_20180814_aa810b61/test.pb.go
+++ b/internal/testprotos/legacy/proto2_20180814_aa810b61/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto2_20180814_aa810b61/test.proto
diff --git a/internal/testprotos/legacy/proto2_20190205_c823c79e/test.pb.go b/internal/testprotos/legacy/proto2_20190205_c823c79e/test.pb.go
index dba75b5..38a43bc 100644
--- a/internal/testprotos/legacy/proto2_20190205_c823c79e/test.pb.go
+++ b/internal/testprotos/legacy/proto2_20190205_c823c79e/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto2_20190205_c823c79e/test.proto
@@ -5,8 +9,9 @@
import (
fmt "fmt"
- proto "google.golang.org/protobuf/internal/protolegacy"
math "math"
+
+ proto "google.golang.org/protobuf/internal/protolegacy"
)
// Reference imports to suppress errors if they are not otherwise used.
diff --git a/internal/testprotos/legacy/proto3_20160225_2fc053c5/test.pb.go b/internal/testprotos/legacy/proto3_20160225_2fc053c5/test.pb.go
index 6236810..abae7ff 100644
--- a/internal/testprotos/legacy/proto3_20160225_2fc053c5/test.pb.go
+++ b/internal/testprotos/legacy/proto3_20160225_2fc053c5/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go.
// source: proto3_20160225_2fc053c5/test.proto
// DO NOT EDIT!
diff --git a/internal/testprotos/legacy/proto3_20160519_a4ab9ec5/test.pb.go b/internal/testprotos/legacy/proto3_20160519_a4ab9ec5/test.pb.go
index 06e1035..ac339fa 100644
--- a/internal/testprotos/legacy/proto3_20160519_a4ab9ec5/test.pb.go
+++ b/internal/testprotos/legacy/proto3_20160519_a4ab9ec5/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go.
// source: proto3_20160519_a4ab9ec5/test.proto
// DO NOT EDIT!
diff --git a/internal/testprotos/legacy/proto3_20180125_92554152/test.pb.go b/internal/testprotos/legacy/proto3_20180125_92554152/test.pb.go
index 9377d39..35ac0a0 100644
--- a/internal/testprotos/legacy/proto3_20180125_92554152/test.pb.go
+++ b/internal/testprotos/legacy/proto3_20180125_92554152/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto3_20180125_92554152/test.proto
diff --git a/internal/testprotos/legacy/proto3_20180430_b4deda09/test.pb.go b/internal/testprotos/legacy/proto3_20180430_b4deda09/test.pb.go
index f9c51a1..cd2631a 100644
--- a/internal/testprotos/legacy/proto3_20180430_b4deda09/test.pb.go
+++ b/internal/testprotos/legacy/proto3_20180430_b4deda09/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto3_20180430_b4deda09/test.proto
diff --git a/internal/testprotos/legacy/proto3_20180814_aa810b61/test.pb.go b/internal/testprotos/legacy/proto3_20180814_aa810b61/test.pb.go
index 68ef699..97e4089 100644
--- a/internal/testprotos/legacy/proto3_20180814_aa810b61/test.pb.go
+++ b/internal/testprotos/legacy/proto3_20180814_aa810b61/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto3_20180814_aa810b61/test.proto
diff --git a/internal/testprotos/legacy/proto3_20190205_c823c79e/test.pb.go b/internal/testprotos/legacy/proto3_20190205_c823c79e/test.pb.go
index 18449f5..250836c 100644
--- a/internal/testprotos/legacy/proto3_20190205_c823c79e/test.pb.go
+++ b/internal/testprotos/legacy/proto3_20190205_c823c79e/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto3_20190205_c823c79e/test.proto
@@ -5,8 +9,9 @@
import (
fmt "fmt"
- proto "google.golang.org/protobuf/internal/protolegacy"
math "math"
+
+ proto "google.golang.org/protobuf/internal/protolegacy"
)
// Reference imports to suppress errors if they are not otherwise used.