Merge "Support multiple library names per target."
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -93,13 +94,14 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic
|
|||||||
}
|
}
|
||||||
hashes := make(map[hash]struct{})
|
hashes := make(map[hash]struct{})
|
||||||
for _, text := range tn.LicenseTexts() {
|
for _, text := range tn.LicenseTexts() {
|
||||||
if _, ok := ni.hash[text]; !ok {
|
fname := strings.SplitN(text, ":", 2)[0]
|
||||||
err := ni.addText(text)
|
if _, ok := ni.hash[fname]; !ok {
|
||||||
|
err := ni.addText(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hash := ni.hash[text]
|
hash := ni.hash[fname]
|
||||||
if _, ok := hashes[hash]; !ok {
|
if _, ok := hashes[hash]; !ok {
|
||||||
hashes[hash] = struct{}{}
|
hashes[hash] = struct{}{}
|
||||||
}
|
}
|
||||||
@@ -108,11 +110,12 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic
|
|||||||
return hashes, nil
|
return hashes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
link := func(libName string, hashes map[hash]struct{}, installPaths []string) {
|
link := func(tn *TargetNode, hashes map[hash]struct{}, installPaths []string) {
|
||||||
if _, ok := ni.libHash[libName]; !ok {
|
|
||||||
ni.libHash[libName] = make(map[hash]struct{})
|
|
||||||
}
|
|
||||||
for h := range hashes {
|
for h := range hashes {
|
||||||
|
libName := ni.getLibName(tn, h)
|
||||||
|
if _, ok := ni.libHash[libName]; !ok {
|
||||||
|
ni.libHash[libName] = make(map[hash]struct{})
|
||||||
|
}
|
||||||
if _, ok := ni.hashLibInstall[h]; !ok {
|
if _, ok := ni.hashLibInstall[h]; !ok {
|
||||||
ni.hashLibInstall[h] = make(map[string]map[string]struct{})
|
ni.hashLibInstall[h] = make(map[string]map[string]struct{})
|
||||||
}
|
}
|
||||||
@@ -160,7 +163,7 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
link(ni.getLibName(tn), hashes, installPaths)
|
link(tn, hashes, installPaths)
|
||||||
if tn.IsContainer() {
|
if tn.IsContainer() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -170,7 +173,7 @@ func IndexLicenseTexts(rootFS fs.FS, lg *LicenseGraph, rs ResolutionSet) (*Notic
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
link(ni.getLibName(r.actsOn), hashes, installPaths)
|
link(r.actsOn, hashes, installPaths)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
@@ -305,7 +308,24 @@ func (ni *NoticeIndex) HashText(h hash) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getLibName returns the name of the library associated with `noticeFor`.
|
// getLibName returns the name of the library associated with `noticeFor`.
|
||||||
func (ni *NoticeIndex) getLibName(noticeFor *TargetNode) string {
|
func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string {
|
||||||
|
for _, text := range noticeFor.LicenseTexts() {
|
||||||
|
if !strings.Contains(text, ":") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := strings.SplitN(text, ":", 2)
|
||||||
|
fname, pname := fields[0], fields[1]
|
||||||
|
if ni.hash[fname].key != h.key {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
ln, err := url.QueryUnescape(pname)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return ln
|
||||||
|
}
|
||||||
// use name from METADATA if available
|
// use name from METADATA if available
|
||||||
ln := ni.checkMetadata(noticeFor)
|
ln := ni.checkMetadata(noticeFor)
|
||||||
if len(ln) > 0 {
|
if len(ln) > 0 {
|
||||||
|
Reference in New Issue
Block a user