build/analysis: copy cockroachdb code to third_party

We are currently fetching the full cockroach repository just for a hand
full of nogo passes. As the version we use is licensed under Apache 2.0,
we can copy them to third_party, allowing us to modify them and keep them
stable.

Change-Id: Ia28b181296138eef922485b6517d1e0066766715
Reviewed-on: https://review.monogon.dev/c/monogon/+/4486
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Tested-by: Jenkins CI
diff --git a/third_party/com_github_cockroachdb_cockroach/fmtsafe/functions.go b/third_party/com_github_cockroachdb_cockroach/fmtsafe/functions.go
new file mode 100644
index 0000000..717fa35
--- /dev/null
+++ b/third_party/com_github_cockroachdb_cockroach/fmtsafe/functions.go
@@ -0,0 +1,45 @@
+// Copyright 2020 The Cockroach Authors.
+// SPDX-License-Identifier: Apache-2.0
+
+package fmtsafe
+
+import (
+	"source.monogon.dev/third_party/com_github_cockroachdb_cockroach/errwrap"
+)
+
+// requireConstMsg records functions for which the last string
+// argument must be a constant string.
+var requireConstMsg = map[string]bool{}
+
+// requireConstFmt records functions for which the string arg
+// before the final ellipsis must be a constant string.
+var requireConstFmt = map[string]bool{
+	// Logging things.
+	"log.Printf":           true,
+	"log.Fatalf":           true,
+	"log.Panicf":           true,
+	"(*log.Logger).Fatalf": true,
+	"(*log.Logger).Panicf": true,
+	"(*log.Logger).Printf": true,
+
+	"(go.etcd.io/etcd/raft/v3.Logger).Debugf":   true,
+	"(go.etcd.io/etcd/raft/v3.Logger).Infof":    true,
+	"(go.etcd.io/etcd/raft/v3.Logger).Warningf": true,
+	"(go.etcd.io/etcd/raft/v3.Logger).Errorf":   true,
+	"(go.etcd.io/etcd/raft/v3.Logger).Fatalf":   true,
+	"(go.etcd.io/etcd/raft/v3.Logger).Panicf":   true,
+
+	"(google.golang.org/grpc/grpclog.Logger).Infof":    true,
+	"(google.golang.org/grpc/grpclog.Logger).Warningf": true,
+	"(google.golang.org/grpc/grpclog.Logger).Errorf":   true,
+}
+
+func init() {
+	for errorFn, formatStringIndex := range errwrap.ErrorFnFormatStringIndex {
+		if formatStringIndex < 0 {
+			requireConstMsg[errorFn] = true
+		} else {
+			requireConstFmt[errorFn] = true
+		}
+	}
+}