func moduleUnits (modulePath , version string ,
pkgs []*goPackage ,
readmes []*internal .Readme ,
d *licenses .Detector ) []*internal .Unit {
pkgLookup := map [string ]*goPackage {}
for _ , pkg := range pkgs {
pkgLookup [pkg .path ] = pkg
}
dirPaths := unitPaths (modulePath , pkgs )
readmeLookup := map [string ]*internal .Readme {}
for _ , readme := range readmes {
if path .Dir (readme .Filepath ) == "." {
readmeLookup [modulePath ] = readme
} else if modulePath == stdlib .ModulePath {
readmeLookup [path .Dir (readme .Filepath )] = readme
} else {
readmeLookup [path .Join (modulePath , path .Dir (readme .Filepath ))] = readme
}
}
var units []*internal .Unit
for _ , dirPath := range dirPaths {
suffix := internal .Suffix (dirPath , modulePath )
if modulePath == stdlib .ModulePath {
suffix = dirPath
}
isRedist , lics := d .PackageInfo (suffix )
var meta []*licenses .Metadata
for _ , l := range lics {
meta = append (meta , l .Metadata )
}
dir := &internal .Unit {
UnitMeta : internal .UnitMeta {
ModuleInfo : internal .ModuleInfo {
ModulePath : modulePath ,
Version : version ,
IsRedistributable : d .ModuleIsRedistributable (),
},
Path : dirPath ,
IsRedistributable : isRedist ,
Licenses : meta ,
},
}
if r , ok := readmeLookup [dirPath ]; ok {
dir .Readme = r
}
if pkg , ok := pkgLookup [dirPath ]; ok {
dir .Name = pkg .name
dir .Imports = pkg .imports
dir .Documentation = pkg .docs
}
units = append (units , dir )
}
return units
}