Skip to content

Commit

Permalink
Merge pull request #69 from xushiwei/req
Browse files Browse the repository at this point in the history
test updateWorkfile
  • Loading branch information
xushiwei committed Feb 12, 2024
2 parents 7a437d7 + 27d860a commit b8c336c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions modload/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,20 @@ const (
// SaveWithGopMod adds `require github.com/goplus/gop` and saves all
// changes of this module.
func (p Module) SaveWithGopMod(gop *env.Gop, flags int) (err error) {
gopVer := getGopVer(gop)
if old := p.checkGopDeps(); old != flags {
if p.Path() == gopMod { // don't change Go+ itself
return
}
p.requireGop(gop, gopVer, old, flags)
if err = p.Save(); err != nil {
return
}
if p.Path() == gopMod { // don't change Go+ itself
return
}
if (flags & FlagDepModGop) == 0 {
old := p.checkGopDeps()
if (flags &^ old) == 0 { // nothing to do
return
}

gopVer := getGopVer(gop)
p.requireGop(gop, gopVer, old, flags)
return p.Save()
}

func (p Module) updateWorkfile(gop *env.Gop, gopVer string) (err error) {
var work *gomodfile.WorkFile
var workFile = p.workFile()
b, err := os.ReadFile(workFile)
Expand Down Expand Up @@ -386,6 +386,7 @@ func (p Module) SaveWithGopMod(gop *env.Gop, flags int) (err error) {
func (p Module) requireGop(gop *env.Gop, gopVer string, old, flags int) {
if (flags&FlagDepModGop) != 0 && (old&FlagDepModGop) == 0 {
p.File.AddRequire(gopMod, gopVer)
p.updateWorkfile(gop, gopVer)
}
if (flags&FlagDepModX) != 0 && (old&FlagDepModX) == 0 { // depends module github.com/qiniu/x
if x, xsum, ok := getXVer(gop); ok {
Expand Down
4 changes: 2 additions & 2 deletions modload/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ require (
log.Fatal("mod.SaveWithGopMod 3:", err)
}

if err = mod.SaveWithGopMod(&env.Gop{Version: "v1.2.0 devel", Root: ".gop"}, FlagDepModX); err != nil {
log.Fatal("mod.SaveWithGopMod 4:", err)
if err = mod.updateWorkfile(&env.Gop{Version: "v1.2.0 devel", Root: ".gop"}, ""); err != nil {
log.Fatal("updateWorkfile:", err)
}

mod.Opt.Projects = append(mod.Opt.Projects, spxProject)
Expand Down

0 comments on commit b8c336c

Please sign in to comment.