Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
gosrc: add minimal support for vgo-aware modules
Browse files Browse the repository at this point in the history
Currently, gddo assumes that there will be just one go-import HTML meta
tag when resolving a custom import's VCS repository. vgo introduces a
special new go-import meta tag to identify the location of published Go
modules; it has the VCS identifier 'mod'.

https://golang.org/issue/25140 and https://golang.org/issue/25139 added
minimal awareness to the Go 1.9 and 1.10 branches for the vgo transition
that will start in Go 1.11. Part of this backported support is to ignore
the module special go-import meta tag which has a 'mod' vcvs type:

https://go-review.googlesource.com/c/go/+/115298/4/src/cmd/go/internal/get/discovery.go

Per https://golang.org/issue/25069, the 'mod' vcs type is used by 'new'
Go code to identify where published modules can be fetched.

As a first minimal step we can make gddo "aware" in the same way that Go
1.9 and 1.10 are "aware" of these published modules by simply ignoring
that go-import meta tag.

Later gddo CLs will likely need to enhance support for vgo, but this is
a sufficient first step.

Fixes #558

Change-Id: Ibddfcc8e0a663792da206a244e5cffb8c68fe894
Reviewed-on: https://go-review.googlesource.com/120817
Reviewed-by: Tuo Shan <shantuo@google.com>
  • Loading branch information
myitcv authored and shantuo committed Jun 27, 2018
1 parent 574849d commit 9ab275b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gosrc/gosrc.go
Expand Up @@ -302,6 +302,10 @@ metaScan:
errorMessage = "go-import meta tag content attribute does not have three fields"
continue metaScan
}
if fields[1] == "mod" {
// vgo adds a special mod vcs type; we can skip this
continue
}
if im != nil {
im = nil
errorMessage = "more than one go-import meta tag found"
Expand Down
19 changes: 19 additions & 0 deletions gosrc/gosrc_test.go
Expand Up @@ -86,6 +86,14 @@ var testWeb = map[string]string{
`<meta name="go-source" content="azul3d.org/examples https://github.com/azul3d/examples https://gotools.org/azul3d.org/examples{/dir} https://gotools.org/azul3d.org/examples{/dir}#{file}-L{line}">` +
`<meta http-equiv="refresh" content="0; url=https://godoc.org/azul3d.org/examples/abs">` +
`</head>`,

// Multiple go-import meta tags; one of which is a vgo-special mod vcs type
"http://myitcv.io/blah2": `<!DOCTYPE html><html><head>` +
`<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>` +
`<meta name="go-import" content="myitcv.io/blah2 git https://github.com/myitcv/x">` +
`<meta name="go-import" content="myitcv.io/blah2 mod https://raw.githubusercontent.com/myitcv/pubx/master">` +
`<meta name="go-source" content="myitcv.io https://github.com/myitcv/x/wiki https://github.com/myitcv/x/tree/master{/dir} https://github.com/myitcv/x/blob/master{/dir}/{file}#L{line}">` +
`</head>`,
}

var getDynamicTests = []struct {
Expand Down Expand Up @@ -202,6 +210,17 @@ var getDynamicTests = []struct {
VCS: "git",
Files: []*File{{Name: "main.go", BrowseURL: "https://gotools.org/azul3d.org/examples/abs#main.go"}},
}},
{"myitcv.io/blah2", &Directory{
BrowseURL: "https://github.com/myitcv/x",
ImportPath: "myitcv.io/blah2",
LineFmt: "%s#L%d",
ProjectName: "blah2",
ProjectRoot: "myitcv.io/blah2",
ProjectURL: "http://myitcv.io/blah2",
ResolvedPath: "github.com/myitcv/x",
VCS: "git",
Files: []*File{{Name: "main.go", BrowseURL: "https://github.com/myitcv/x/blob/master/main.go"}},
}},
}

type testTransport map[string]string
Expand Down

0 comments on commit 9ab275b

Please sign in to comment.