Skip to content

Commit

Permalink
all: fix deprecated
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zchee authored and gopherbot committed Apr 23, 2024
1 parent e4ad8f9 commit c2b76ee
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 55 deletions.
6 changes: 3 additions & 3 deletions cmd/protoc-gen-go/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -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)
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/protoc-gen-go/internal_gengo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions compiler/protogen/protogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go/printer"
"go/token"
"go/types"
"io/ioutil"
"io"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 10 additions & 9 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package bench_test
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/generate-corpus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -114,23 +114,23 @@ 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)
}

text, err := prototext.Marshal(m)
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)
}

json, err := protojson.Marshal(m)
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)
}
}
Expand Down
13 changes: 6 additions & 7 deletions internal/cmd/generate-protos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -197,15 +196,15 @@ 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))
}
}

syncOutput(repoRoot, tmpDir)
}

func generateRemoteProtos() {
tmpDir, err := ioutil.TempDir(repoRoot, "tmp")
tmpDir, err := os.MkdirTemp(repoRoot, "tmp")
check(err)
defer os.RemoveAll(tmpDir)

Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 3 additions & 4 deletions internal/cmd/generate-types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/pbdump/pbdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/filedesc/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package filedesc_test
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"testing"

"google.golang.org/protobuf/proto"
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/fuzztest/fuzztest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package fuzztest

import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand All @@ -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)
}
Expand Down
Loading

0 comments on commit c2b76ee

Please sign in to comment.