Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test updateWorkfile #69

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading