all: fix deprecated

Change-Id: I2db557669ada6e031140a09b3a92bd901220f8f3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/580975
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
This commit is contained in:
Koichi Shiraishi 2024-04-23 07:15:31 +09:00 committed by Gopher Robot
parent e4ad8f9dfc
commit c2b76eee36
15 changed files with 52 additions and 55 deletions

View File

@ -6,7 +6,7 @@ package main
import (
"bytes"
"io/ioutil"
"os"
"testing"
"github.com/google/go-cmp/cmp"
@ -19,11 +19,11 @@ import (
)
func TestAnnotations(t *testing.T) {
sourceFile, err := ioutil.ReadFile("testdata/annotations/annotations.pb.go")
sourceFile, err := os.ReadFile("testdata/annotations/annotations.pb.go")
if err != nil {
t.Fatal(err)
}
metaFile, err := ioutil.ReadFile("testdata/annotations/annotations.pb.go.meta")
metaFile, err := os.ReadFile("testdata/annotations/annotations.pb.go.meta")
if err != nil {
t.Fatal(err)
}

View File

@ -231,7 +231,7 @@ func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp
func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) {
// Enum type declaration.
g.Annotate(e.GoIdent.GoName, e.Location)
g.AnnotateSymbol(e.GoIdent.GoName, protogen.Annotation{Location: e.Location})
leadingComments := appendDeprecationSuffix(e.Comments.Leading,
e.Desc.ParentFile(),
e.Desc.Options().(*descriptorpb.EnumOptions).GetDeprecated())
@ -241,7 +241,7 @@ func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) {
// Enum value constants.
g.P("const (")
for _, value := range e.Values {
g.Annotate(value.GoIdent.GoName, value.Location)
g.AnnotateSymbol(value.GoIdent.GoName, protogen.Annotation{Location: value.Location})
leadingComments := appendDeprecationSuffix(value.Comments.Leading,
value.Desc.ParentFile(),
value.Desc.Options().(*descriptorpb.EnumValueOptions).GetDeprecated())
@ -331,7 +331,7 @@ func genMessage(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) {
}
// Message type declaration.
g.Annotate(m.GoIdent.GoName, m.Location)
g.AnnotateSymbol(m.GoIdent.GoName, protogen.Annotation{Location: m.Location})
leadingComments := appendDeprecationSuffix(m.Comments.Leading,
m.Desc.ParentFile(),
m.Desc.Options().(*descriptorpb.MessageOptions).GetDeprecated())
@ -392,7 +392,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie
tags = append(tags, gotrackTags...)
}
g.Annotate(m.GoIdent.GoName+"."+oneof.GoName, oneof.Location)
g.AnnotateSymbol(m.GoIdent.GoName+"."+oneof.GoName, protogen.Annotation{Location: oneof.Location})
leadingComments := oneof.Comments.Leading
if leadingComments != "" {
leadingComments += "\n"
@ -431,7 +431,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie
if field.Desc.IsWeak() {
name = genid.WeakFieldPrefix_goname + name
}
g.Annotate(m.GoIdent.GoName+"."+name, field.Location)
g.AnnotateSymbol(m.GoIdent.GoName+"."+name, protogen.Annotation{Location: field.Location})
leadingComments := appendDeprecationSuffix(field.Comments.Leading,
field.Desc.ParentFile(),
field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated())
@ -559,7 +559,7 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI
// Getter for parent oneof.
if oneof := field.Oneof; oneof != nil && oneof.Fields[0] == field && !oneof.Desc.IsSynthetic() {
g.Annotate(m.GoIdent.GoName+".Get"+oneof.GoName, oneof.Location)
g.AnnotateSymbol(m.GoIdent.GoName+".Get"+oneof.GoName, protogen.Annotation{Location: oneof.Location})
g.P("func (m *", m.GoIdent.GoName, ") Get", oneof.GoName, "() ", oneofInterfaceName(oneof), " {")
g.P("if m != nil {")
g.P("return m.", oneof.GoName)
@ -572,7 +572,7 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI
// Getter for message field.
goType, pointer := fieldGoType(g, f, field)
defaultValue := fieldDefaultValue(g, f, m, field)
g.Annotate(m.GoIdent.GoName+".Get"+field.GoName, field.Location)
g.AnnotateSymbol(m.GoIdent.GoName+".Get"+field.GoName, protogen.Annotation{Location: field.Location})
leadingComments := appendDeprecationSuffix("",
field.Desc.ParentFile(),
field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated())
@ -815,8 +815,8 @@ func genMessageOneofWrapperTypes(g *protogen.GeneratedFile, f *fileInfo, m *mess
g.P("}")
g.P()
for _, field := range oneof.Fields {
g.Annotate(field.GoIdent.GoName, field.Location)
g.Annotate(field.GoIdent.GoName+"."+field.GoName, field.Location)
g.AnnotateSymbol(field.GoIdent.GoName, protogen.Annotation{Location: field.Location})
g.AnnotateSymbol(field.GoIdent.GoName+"."+field.GoName, protogen.Annotation{Location: field.Location})
g.P("type ", field.GoIdent, " struct {")
goType, _ := fieldGoType(g, f, field)
tags := structTags{

View File

@ -19,7 +19,7 @@ import (
"go/printer"
"go/token"
"go/types"
"io/ioutil"
"io"
"os"
"path"
"path/filepath"
@ -60,7 +60,7 @@ func run(opts Options, f func(*Plugin) error) error {
if len(os.Args) > 1 {
return fmt.Errorf("unknown argument %q (this program should be run by protoc, not directly)", os.Args[1])
}
in, err := ioutil.ReadAll(os.Stdin)
in, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}

View File

@ -14,7 +14,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
"os/exec"
@ -229,14 +228,16 @@ func mustInitDeps(t *testing.T) {
// Delete other sub-directories that are no longer relevant.
defer func() {
now := time.Now()
fis, _ := ioutil.ReadDir(testDir)
fis, _ := os.ReadDir(testDir)
for _, fi := range fis {
dir := filepath.Join(testDir, fi.Name())
if finishedDirs[dir] {
os.Chtimes(dir, now, now) // best-effort
continue
}
if now.Sub(fi.ModTime()) < purgeTimeout {
fii, err := fi.Info()
check(err)
if now.Sub(fii.ModTime()) < purgeTimeout {
continue
}
fmt.Printf("delete %v\n", fi.Name())
@ -373,7 +374,7 @@ func downloadArchive(check func(error), dstPath, srcURL, skipPrefix, wantSHA256
var r io.Reader = resp.Body
if wantSHA256 != "" {
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
check(err)
r = bytes.NewReader(b)
@ -408,9 +409,9 @@ func downloadArchive(check func(error), dstPath, srcURL, skipPrefix, wantSHA256
mode := os.FileMode(h.Mode & 0777)
switch h.Typeflag {
case tar.TypeReg:
b, err := ioutil.ReadAll(tr)
b, err := io.ReadAll(tr)
check(err)
check(ioutil.WriteFile(path, b, mode))
check(os.WriteFile(path, b, mode))
case tar.TypeDir:
check(os.Mkdir(path, mode))
}
@ -443,7 +444,7 @@ func mustHandleFlags(t *testing.T) {
cmd.mustRun(t, "go", "build", "-trimpath", "-ldflags", "-s -w -buildid=", "-o", binPath, "./cmd/protoc-gen-go")
// Archive and compress the binary.
in, err := ioutil.ReadFile(binPath)
in, err := os.ReadFile(binPath)
if err != nil {
t.Fatal(err)
}
@ -472,7 +473,7 @@ func mustHandleFlags(t *testing.T) {
tw.Close()
gz.Close()
}
if err := ioutil.WriteFile(binPath+suffix, out.Bytes(), 0664); err != nil {
if err := os.WriteFile(binPath+suffix, out.Bytes(), 0664); err != nil {
t.Fatal(err)
}
}
@ -499,7 +500,7 @@ func mustHaveCopyrightHeader(t *testing.T, files []string) {
var bad []string
File:
for _, file := range files {
b, err := ioutil.ReadFile(file)
b, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}

View File

@ -7,7 +7,6 @@ package bench_test
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -175,7 +174,7 @@ func TestMain(m *testing.M) {
if filepath.Ext(path) != ".pb" {
return nil
}
raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
panic(err)
}

View File

@ -12,8 +12,8 @@ package main
import (
"crypto/sha1"
"fmt"
"io/ioutil"
"log"
"os"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/encoding/prototext"
@ -114,7 +114,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(fmt.Sprintf("internal/fuzz/wirefuzz/corpus/%x", sha1.Sum(wire)), wire, 0777); err != nil {
if err := os.WriteFile(fmt.Sprintf("internal/fuzz/wirefuzz/corpus/%x", sha1.Sum(wire)), wire, 0777); err != nil {
log.Fatal(err)
}
@ -122,7 +122,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(fmt.Sprintf("internal/fuzz/textfuzz/corpus/%x", sha1.Sum(text)), text, 0777); err != nil {
if err := os.WriteFile(fmt.Sprintf("internal/fuzz/textfuzz/corpus/%x", sha1.Sum(text)), text, 0777); err != nil {
log.Fatal(err)
}
@ -130,7 +130,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(fmt.Sprintf("internal/fuzz/jsonfuzz/corpus/%x", sha1.Sum(json)), json, 0777); err != nil {
if err := os.WriteFile(fmt.Sprintf("internal/fuzz/jsonfuzz/corpus/%x", sha1.Sum(json)), json, 0777); err != nil {
log.Fatal(err)
}
}

View File

@ -11,7 +11,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"path"
@ -126,7 +125,7 @@ func generateEditionsDefaults() {
}
func generateLocalProtos() {
tmpDir, err := ioutil.TempDir(repoRoot, "tmp")
tmpDir, err := os.MkdirTemp(repoRoot, "tmp")
check(err)
defer os.RemoveAll(tmpDir)
@ -197,7 +196,7 @@ func generateLocalProtos() {
}...), "\n")
b, err := format.Source([]byte(s))
check(err)
check(ioutil.WriteFile(filepath.Join(tmpDir, filepath.FromSlash(d.path+"/gen_test.go")), b, 0664))
check(os.WriteFile(filepath.Join(tmpDir, filepath.FromSlash(d.path+"/gen_test.go")), b, 0664))
}
}
@ -205,7 +204,7 @@ func generateLocalProtos() {
}
func generateRemoteProtos() {
tmpDir, err := ioutil.TempDir(repoRoot, "tmp")
tmpDir, err := os.MkdirTemp(repoRoot, "tmp")
check(err)
defer os.RemoveAll(tmpDir)
@ -466,14 +465,14 @@ func syncOutput(dstDir, srcDir string) {
}
func copyFile(dstPath, srcPath string) (changed bool) {
src, err := ioutil.ReadFile(srcPath)
src, err := os.ReadFile(srcPath)
check(err)
check(os.MkdirAll(filepath.Dir(dstPath), 0775))
dst, _ := ioutil.ReadFile(dstPath)
dst, _ := os.ReadFile(dstPath)
if bytes.Equal(src, dst) {
return false
}
check(ioutil.WriteFile(dstPath, src, 0664))
check(os.WriteFile(dstPath, src, 0664))
return true
}

View File

@ -11,7 +11,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"path"
@ -248,13 +247,13 @@ func writeSource(file, src string) {
absFile := filepath.Join(repoRoot, file)
if run {
prev, _ := ioutil.ReadFile(absFile)
prev, _ := os.ReadFile(absFile)
if !bytes.Equal(b, prev) {
fmt.Println("#", file)
check(ioutil.WriteFile(absFile, b, 0664))
check(os.WriteFile(absFile, b, 0664))
}
} else {
check(ioutil.WriteFile(absFile+".tmp", b, 0664))
check(os.WriteFile(absFile+".tmp", b, 0664))
defer os.Remove(absFile + ".tmp")
cmd := exec.Command("diff", file, file+".tmp", "-N", "-u")

View File

@ -9,7 +9,7 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
@ -111,14 +111,14 @@ func main() {
// Read message input.
var buf []byte
if flag.NArg() == 0 {
b, err := ioutil.ReadAll(os.Stdin)
b, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("ReadAll error: %v", err)
}
buf = b
}
for _, f := range flag.Args() {
b, err := ioutil.ReadFile(f)
b, err := os.ReadFile(f)
if err != nil {
log.Fatalf("ReadFile error: %v", err)
}

View File

@ -7,7 +7,7 @@ package filedesc_test
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"testing"
"google.golang.org/protobuf/proto"
@ -33,7 +33,7 @@ func TestInit(t *testing.T) {
want := &descriptorpb.FileDescriptorProto{}
zb, _ := (&testpb.TestAllTypes{}).Descriptor()
r, _ := gzip.NewReader(bytes.NewBuffer(zb))
b, _ := ioutil.ReadAll(r)
b, _ := io.ReadAll(r)
if err := proto.Unmarshal(b, want); err != nil {
t.Fatal(err)
}

View File

@ -7,7 +7,6 @@ package fuzztest
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -34,7 +33,7 @@ func Test(t *testing.T, fuzz func(b []byte) int) {
sort.Strings(names)
for _, name := range names {
t.Run(name, func(t *testing.T) {
b, err := ioutil.ReadFile(filepath.Join(*corpus, name))
b, err := os.ReadFile(filepath.Join(*corpus, name))
if err != nil {
t.Fatal(err)
}

View File

@ -7,7 +7,7 @@ package impl
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"math"
"strings"
"testing"
@ -30,7 +30,7 @@ func TestCompressGZIP(t *testing.T) {
if err != nil {
t.Errorf("unexpected gzip.NewReader error: %v", err)
}
b, err := ioutil.ReadAll(zr)
b, err := io.ReadAll(zr)
if err != nil {
t.Errorf("unexpected ioutil.ReadAll error: %v", err)
}

View File

@ -7,7 +7,7 @@ package impl
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"sync"
"google.golang.org/protobuf/internal/filedesc"
@ -51,7 +51,7 @@ func legacyLoadFileDesc(b []byte) protoreflect.FileDescriptor {
if err != nil {
panic(err)
}
b2, err := ioutil.ReadAll(zr)
b2, err := io.ReadAll(zr)
if err != nil {
panic(err)
}

View File

@ -7,7 +7,7 @@ package impl_test
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"reflect"
"testing"
@ -39,7 +39,7 @@ func mustLoadFileDesc(b []byte, _ []int) protoreflect.FileDescriptor {
if err != nil {
panic(err)
}
b, err = ioutil.ReadAll(zr)
b, err = io.ReadAll(zr)
if err != nil {
panic(err)
}

View File

@ -11,7 +11,7 @@ import (
"compress/gzip"
"errors"
"fmt"
"io/ioutil"
"io"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
@ -48,7 +48,7 @@ func RegisterFile(s string, d []byte) {
if err != nil {
panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err))
}
b, err := ioutil.ReadAll(zr)
b, err := io.ReadAll(zr)
if err != nil {
panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err))
}