Add vendorPath to correctly link the vendor directory in the nix build

This commit is contained in:
adisbladis 2020-07-22 12:09:08 +02:00
parent a5f0e022c6
commit e51f884b85
No known key found for this signature in database
GPG key ID: 110BFAD44C6249B7
3 changed files with 15 additions and 10 deletions

View file

@ -73,16 +73,10 @@ func FetchPackages(goModPath string, goSumPath string, goMod2NixPath string, dep
caches = append(caches, buildGoCache) caches = append(caches, buildGoCache)
} }
// // Parse require
// require := make(map[string]module.Version)
// for _, req := range mod.Require {
// require[req.Mod.Path] = req.Mod
// }
// Map repos -> replacement repo // Map repos -> replacement repo
replace := make(map[string]string) replace := make(map[string]string)
for _, repl := range mod.Replace { for _, repl := range mod.Replace {
replace[repl.Old.Path] = repl.New.Path replace[repl.New.Path] = repl.Old.Path
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -111,12 +105,12 @@ func FetchPackages(goModPath string, goSumPath string, goMod2NixPath string, dep
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"numJobs": numJobs, "numJobs": numJobs,
}).Info("Queuing jobs") }).Info("Queuing jobs")
for goPackagePath, sumVersion := range sumVersions { for importPath, sumVersion := range sumVersions {
// Check for replacement path (only original goPackagePath is recorded in go.sum) // Check for replacement path (only original goPackagePath is recorded in go.sum)
importPath := goPackagePath goPackagePath := importPath
v, ok := replace[goPackagePath] v, ok := replace[goPackagePath]
if ok { if ok {
importPath = v goPackagePath = v
} }
jobs <- &packageJob{ jobs <- &packageJob{
@ -251,6 +245,12 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
return nil, err return nil, err
} }
vendorPath := ""
if importPath != goPackagePath {
importPathPrefix, _, _ := module.SplitPathVersion(importPath)
vendorPath = importPathPrefix
}
return &types.Package{ return &types.Package{
GoPackagePath: goPackagePath, GoPackagePath: goPackagePath,
URL: repoRoot.Repo, URL: repoRoot.Repo,
@ -260,6 +260,7 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
// It's also used to construct the vendor directory in the Nix build // It's also used to construct the vendor directory in the Nix build
SumVersion: sumVersion, SumVersion: sumVersion,
RelPath: relPath, RelPath: relPath,
VendorPath: vendorPath,
}, nil }, nil
} }

View file

@ -18,6 +18,7 @@ type fetchInfo struct {
type packageT struct { type packageT struct {
SumVersion string `toml:"sumVersion"` SumVersion string `toml:"sumVersion"`
RelPath string `toml:"relPath"` RelPath string `toml:"relPath"`
VendorPath string `toml:"vendorPath"`
Fetch *fetchInfo `toml:"fetch"` Fetch *fetchInfo `toml:"fetch"`
} }
@ -26,6 +27,7 @@ func Marshal(pkgs []*types.Package) ([]byte, error) {
for _, pkg := range pkgs { for _, pkg := range pkgs {
result[pkg.GoPackagePath] = &packageT{ result[pkg.GoPackagePath] = &packageT{
VendorPath: pkg.VendorPath,
SumVersion: pkg.SumVersion, SumVersion: pkg.SumVersion,
RelPath: pkg.RelPath, RelPath: pkg.RelPath,
Fetch: &fetchInfo{ Fetch: &fetchInfo{
@ -75,6 +77,7 @@ func LoadGomod2Nix(filePath string) map[string]*types.Package {
Sha256: v.Fetch.Sha256, Sha256: v.Fetch.Sha256,
SumVersion: v.SumVersion, SumVersion: v.SumVersion,
RelPath: v.RelPath, RelPath: v.RelPath,
VendorPath: v.VendorPath,
} }
} }

View file

@ -7,4 +7,5 @@ type Package struct {
Sha256 string Sha256 string
SumVersion string SumVersion string
RelPath string RelPath string
VendorPath string
} }