From 649f341e95626afa56ca67c5595c8f35780b29a8 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" <bcmills@google.com> Date: Tue, 5 Nov 2019 16:09:50 -0500 Subject: [PATCH] cmd: update x/mod to CL 205497 Also revert an incidental 'gofmt' of a vendored file from CL 205240. Updates #34822 Change-Id: I82a015d865db4d865b4776a8013312f25dbb9181 Reviewed-on: https://go-review.googlesource.com/c/go/+/205539 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> --- src/cmd/go.mod | 2 +- src/cmd/go.sum | 2 + .../vendor/golang.org/x/mod/modfile/read.go | 41 ++++++++++++++++++- .../vendor/golang.org/x/mod/modfile/rule.go | 6 ++- .../tools/go/analysis/internal/facts/facts.go | 1 + src/cmd/vendor/modules.txt | 2 +- 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/cmd/go.mod b/src/cmd/go.mod index de81b9ac76..896b863d4e 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -7,7 +7,7 @@ require ( github.com/ianlancetaylor/demangle v0.0.0-20180524225900-fc6590592b44 // indirect golang.org/x/arch v0.0.0-20190815191158-8a70ba74b3a1 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 - golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 + golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect golang.org/x/tools v0.0.0-20191104222624-6b7b8b79ae80 ) diff --git a/src/cmd/go.sum b/src/cmd/go.sum index e93b9a98eb..16336df272 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -9,6 +9,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 h1:QsMqsRXZFQT+jRZnwpEDIwGHWg0UY9ZrpWiplCOEK5I= golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/src/cmd/vendor/golang.org/x/mod/modfile/read.go b/src/cmd/vendor/golang.org/x/mod/modfile/read.go index bfa90a5a64..616d00efdb 100644 --- a/src/cmd/vendor/golang.org/x/mod/modfile/read.go +++ b/src/cmd/vendor/golang.org/x/mod/modfile/read.go @@ -90,6 +90,19 @@ func (x *FileSyntax) Span() (start, end Position) { return start, end } +// addLine adds a line containing the given tokens to the file. +// +// If the first token of the hint matches the first token of the +// line, the new line is added at the end of the block containing hint, +// extracting hint into a new block if it is not yet in one. +// +// If the hint is non-nil buts its first token does not match, +// the new line is added after the block containing hint +// (or hint itself, if not in a block). +// +// If no hint is provided, addLine appends the line to the end of +// the last block with a matching first token, +// or to the end of the file if no such block exists. func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { if hint == nil { // If no hint given, add to the last statement of the given type. @@ -111,11 +124,27 @@ func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { } } + newLineAfter := func(i int) *Line { + new := &Line{Token: tokens} + if i == len(x.Stmt) { + x.Stmt = append(x.Stmt, new) + } else { + x.Stmt = append(x.Stmt, nil) + copy(x.Stmt[i+2:], x.Stmt[i+1:]) + x.Stmt[i+1] = new + } + return new + } + if hint != nil { for i, stmt := range x.Stmt { switch stmt := stmt.(type) { case *Line: if stmt == hint { + if stmt.Token == nil || stmt.Token[0] != tokens[0] { + return newLineAfter(i) + } + // Convert line to line block. stmt.InBlock = true block := &LineBlock{Token: stmt.Token[:1], Line: []*Line{stmt}} @@ -125,15 +154,25 @@ func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { block.Line = append(block.Line, new) return new } + case *LineBlock: if stmt == hint { + if stmt.Token[0] != tokens[0] { + return newLineAfter(i) + } + new := &Line{Token: tokens[1:], InBlock: true} stmt.Line = append(stmt.Line, new) return new } + for j, line := range stmt.Line { if line == hint { - // Add new line after hint. + if stmt.Token[0] != tokens[0] { + return newLineAfter(i) + } + + // Add new line after hint within the block. stmt.Line = append(stmt.Line, nil) copy(stmt.Line[j+2:], stmt.Line[j+1:]) new := &Line{Token: tokens[1:], InBlock: true} diff --git a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go index 66b08d9723..292d5b60b5 100644 --- a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go +++ b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go @@ -505,9 +505,13 @@ func (f *File) AddGoStmt(version string) error { return fmt.Errorf("invalid language version string %q", version) } if f.Go == nil { + var hint Expr + if f.Module != nil && f.Module.Syntax != nil { + hint = f.Module.Syntax + } f.Go = &Go{ Version: version, - Syntax: f.Syntax.addLine(nil, "go", version), + Syntax: f.Syntax.addLine(hint, "go", version), } } else { f.Go.Version = version diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go index fe8e8f3884..1fb69c6159 100644 --- a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go @@ -231,6 +231,7 @@ func Decode(pkg *types.Package, read func(packagePath string) ([]byte, error)) ( // It may fail if one of the Facts could not be gob-encoded, but this is // a sign of a bug in an Analyzer. func (s *Set) Encode() []byte { + // TODO(adonovan): opt: use a more efficient encoding // that avoids repeating PkgPath for each fact. diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index 10e142568f..9bb8bd5a44 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -29,7 +29,7 @@ golang.org/x/arch/x86/x86asm golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519/internal/edwards25519 golang.org/x/crypto/ssh/terminal -# golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 +# golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee ## explicit golang.org/x/mod/internal/lazyregexp golang.org/x/mod/modfile -- 2.30.9