From: Austin Clements Date: Sat, 6 May 2023 19:27:02 +0000 (-0400) Subject: cmd/go: fix swigOne action with -n X-Git-Tag: go1.21rc1~562 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=711609d55f7d1254e0400fd870c97d5c5a259a99;p=gostls13.git cmd/go: fix swigOne action with -n Currently, if cmd/go builds a swig file with the -n (dry run) flag, it will print the swig command invocation without executing it, but then attempt to actually rename one of swig's output files, which will fail. Make this rename conditional on -n. While we're here, we fix the missing logging of the rename command with -x, too. Change-Id: I1f6e6efc53dfe4ac5a42d26096679b97bc322827 Reviewed-on: https://go-review.googlesource.com/c/go/+/493255 Run-TryBot: Austin Clements Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 66c1bfc41a..e52de3b6af 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -3779,8 +3779,13 @@ func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFL // going to compile. goFile = objdir + goFile newGoFile := objdir + "_" + base + "_swig.go" - if err := os.Rename(goFile, newGoFile); err != nil { - return "", "", err + if cfg.BuildX || cfg.BuildN { + b.Showcmd("", "mv %s %s", goFile, newGoFile) + } + if !cfg.BuildN { + if err := os.Rename(goFile, newGoFile); err != nil { + return "", "", err + } } return newGoFile, objdir + gccBase + gccExt, nil }