This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrates to using
go list -m -json all
for godep tactic (pass 1) (#443
- Loading branch information
Showing
9 changed files
with
131 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,29 +11,30 @@ Find all files named `go.mod` | |
|
||
Discovery: find go.mod files | ||
|
||
We run `go list -m all`, which produces, e.g.,: | ||
We run `go list -m -json all`, which produces, e.g.,: | ||
|
||
```json | ||
{ | ||
"Path": "example.com/foo/bar", | ||
"Main": true, | ||
"Dir": "/Users/example/Codes/golang/simple", | ||
"GoMod": "/Users/example/Codes/golang/simple/go.mod", | ||
"GoVersion": "1.16" | ||
} | ||
{ | ||
"Path": "github.com/kr/pretty", | ||
"Version": "v0.1.0", | ||
"Time": "2018-05-06T08:33:45Z", | ||
"Indirect": true, | ||
"Dir": "/Users/example/go/pkg/mod/github.com/kr/[email protected]", | ||
"GoMod": "/Users/example/go/pkg/mod/cache/download/github.com/kr/pretty/@v/v0.1.0.mod" | ||
} | ||
``` | ||
github.com/skyrocknroll/go-mod-example | ||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc | ||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf | ||
github.com/davecgh/go-spew v1.1.1 | ||
github.com/gorilla/mux v1.6.2 | ||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 | ||
github.com/pmezard/go-difflib v1.0.0 | ||
github.com/sirupsen/logrus v1.2.0 | ||
github.com/stretchr/objx v0.1.1 | ||
github.com/stretchr/testify v1.2.2 | ||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 | ||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
``` | ||
|
||
where the first line references the current module, and the remaining lines are | ||
package imports and pinned version separated by a space. For package | ||
dependencies that aren't using gomodules, a pseudo-version | ||
(`v0.0.0-TIMESTAMP-COMMITID`) is present instead. We use the commit ID as the | ||
version. | ||
- To infer direct dependencies, we filter out any module, which has `Main` field with value of true, and `Indirect` field with value of true. | ||
- To infer transitive dependencies, we execute `go list -json all`, and parse it's output for `Imports`, `ImportPath`, `Module`, `Standard` data, and fill in the transitive dependencies. | ||
|
||
For package dependencies that aren't using gomodules, a pseudo-version (`v0.0.0-TIMESTAMP-COMMITID`) is present instead. We use the commit ID as the version. | ||
|
||
## Analysis: gomod | ||
|
||
|
@@ -54,3 +55,12 @@ where: | |
|
||
- `replace` rewrites `require`s. In this example, our requires resolve to | ||
`[github.com/example/one v1.2.3, github.com/example/other v2.0.0]` | ||
|
||
|
||
## FAQ | ||
|
||
### Why `go list -m -json all` is used instead of `go list -json -deps` to infer dependencies? | ||
|
||
We use `go list -m -json all` in combination with the `go list -json all`, to infer direct and transitive dependencies. The reason, we do not use solely use `go list -json -deps` command at this moment, is because it does not include transitive dependencies imported with test imports. | ||
|
||
This go module functionality is actively being worked on, such that we can label dependencies environment (e.g. Test) correctly, for all types of golang project configurations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"Path": "example.com/foo/bar", | ||
"Main": true, | ||
"Dir": "/Users/megh/Codes/golang/simple", | ||
"GoMod": "/Users/megh/Codes/golang/simple/go.mod", | ||
"GoVersion": "1.16" | ||
} | ||
{ | ||
"Path": "gopkg.in/check.v1", | ||
"Version": "v1.0.0-20180628173108-788fd7840127", | ||
"Time": "2018-06-28T17:31:08Z", | ||
"Indirect": true, | ||
"Dir": "/Users/megh/go/pkg/mod/gopkg.in/[email protected]", | ||
"GoMod": "/Users/megh/go/pkg/mod/cache/download/gopkg.in/check.v1/@v/v1.0.0-20180628173108-788fd7840127.mod" | ||
} | ||
{ | ||
"Path": "gopkg.in/yaml.v3", | ||
"Version": "v3.0.0-20210107192922-496545a6307b", | ||
"Time": "2021-01-07T19:29:22Z", | ||
"Dir": "/Users/megh/go/pkg/mod/gopkg.in/[email protected]", | ||
"GoMod": "/Users/megh/go/pkg/mod/cache/download/gopkg.in/yaml.v3/@v/v3.0.0-20210107192922-496545a6307b.mod" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module example.com/foo/bar | ||
|
||
go 1.16 | ||
|
||
require ( | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b | ||
) |
This file was deleted.
Oops, something went wrong.