From 230c8eb5a3c8f2ed81eb0a1beacd3e728bf25d27 Mon Sep 17 00:00:00 2001 From: Ronald Minnich Date: Thu, 2 Sep 2021 14:43:15 +0000 Subject: [PATCH] Fix up replace directives 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 --- src/pkg/bb/bb.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pkg/bb/bb.go b/src/pkg/bb/bb.go index ebbcb252..427abdc6 100644 --- a/src/pkg/bb/bb.go +++ b/src/pkg/bb/bb.go @@ -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()