Skip to content

Commit

Permalink
*: Modified to conform to Module aware 'go list'
Browse files Browse the repository at this point in the history
Go 1.13 is module aware, so the output of 'go list' results in paths pointing to moule cache (GOPATH/pkg/mod).
Non module aware go versions, the `Root` field in the `go list` output contained `GOPATH`. IN module aware Go versions, it points to the root of module in module cache.
Earlier versions, the LICENSEs could be read by concatenating the concatenating `GOPATH` and `ImportPath`. Now the LICENSES need to be read using `Root` and `Dir` fields which point to the root of the module and imported folder within the module.

This change fixes bill-of-materials test fails in CI with Go 1.13.
etcd-io/etcd#11132
  • Loading branch information
vimalk78 committed Sep 9, 2019
1 parent 6e6186f commit ae365cb
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions license-bill-of-materials.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ func scoreLicenseName(name string) int8 {
// returns a slice of paths all viable files, or a slice containing one empty
// string if none were found.
func findLicenses(info *PkgInfo) ([]string, error) {
path := info.ImportPath
for ; path != "."; path = filepath.Dir(path) {
fis, err := ioutil.ReadDir(filepath.Join(info.Root, "src", path))
path := info.Dir
for ; path != filepath.Dir(info.Root); path = filepath.Dir(path) {
fis, err := ioutil.ReadDir(path)
if err != nil {
return []string{""}, err
}
Expand Down Expand Up @@ -418,15 +418,14 @@ func listPackagesWithLicenses(gopath string, pkgs []string) ([]GoPackage, error)
for _, path := range paths {
rl := RawLicense{Path: path}
if path != "" {
fpath := filepath.Join(info.Root, "src", path)
m, ok := matched[fpath]
m, ok := matched[path]
if !ok {
data, err := ioutil.ReadFile(fpath)
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
m = matchTemplates(data, templates)
matched[fpath] = m
matched[path] = m
}
rl.Score = m.Score
rl.Template = m.Template
Expand Down

0 comments on commit ae365cb

Please sign in to comment.