Skip to content

Commit

Permalink
Fix up replace directives
Browse files Browse the repository at this point in the history
Courtesy floren. Fixes building u-root when external commands
like edwood are added. edwood has replace directives in go.mod
and they need to be handled correctly.

Signed-off-by: Ronald Minnich <rminnich@gmail.com>
  • Loading branch information
rminnich committed Sep 2, 2021
1 parent adc854e commit 230c8eb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/pkg/bb/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,25 @@ func dealWithDeps(env golang.Environ, bbDir, tmpDir, pkgDir string, mainPkgs []*
if err := mod.AddReplace(mpath, "", path.Join("..", "..", mpath), ""); err != nil {
return fmt.Errorf("could not add replace rule for %v to go.mod: %v", mpath, err)
}
// Also copy over every replace directive
if module.GoMod != "" {
gomodData, err := ioutil.ReadFile(module.GoMod)
if err != nil {
return err
}
gomod, err := modfile.Parse(module.GoMod, gomodData, nil)
if err != nil {
return err
}
for _, r := range gomod.Replace {
if strings.HasPrefix(r.New.Path, "./") || strings.HasPrefix(r.New.Path, "../") || strings.HasPrefix(r.New.Path, "/") {
continue
}
if err := mod.AddReplace(r.Old.Path, r.Old.Version, r.New.Path, r.New.Version); err != nil {
return err
}
}
}
}

gomod, err := mod.Format()
Expand Down

0 comments on commit 230c8eb

Please sign in to comment.