diff --git a/src/pkg/bb/bb.go b/src/pkg/bb/bb.go index 192f7e77..c4b6a32a 100644 --- a/src/pkg/bb/bb.go +++ b/src/pkg/bb/bb.go @@ -546,6 +546,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()