Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac3e23c

Browse files
committed
cmd/go: improve handling of tmpdir being noexec
1 parent 5f2fdbe commit ac3e23c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

‎src/cmd/go/internal/base/base.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,14 @@ func GetExitStatus() int {
150150

151151
// Run runs the command, with stdout and stderr
152152
// connected to the go command's own stdout and stderr.
153-
// If the command fails, Run reports the error using Errorf.
154-
func Run(cmdargs ...any) {
153+
// If the command fails, Run reports the error using Errorf,
154+
// and it also returns the error so that the caller can use it.
155+
func Run(cmdargs ...any) error {
155156
cmdline := str.StringList(cmdargs...)
156157
if cfg.BuildN || cfg.BuildX {
157158
fmt.Printf("%s\n", strings.Join(cmdline, " "))
158159
if cfg.BuildN {
159-
return
160+
returnnil
160161
}
161162
}
162163

@@ -165,11 +166,13 @@ func Run(cmdargs ...any) {
165166
cmd.Stderr = os.Stderr
166167
if err := cmd.Run(); err != nil {
167168
Errorf("%v", err)
169+
return err
168170
}
171+
return nil
169172
}
170173

171174
// RunStdin is like run but connects Stdin.
172-
func RunStdin(cmdline []string) {
175+
func RunStdin(cmdline []string) error{
173176
cmd := exec.Command(cmdline[0], cmdline[1:]...)
174177
cmd.Stdin = os.Stdin
175178
cmd.Stdout = os.Stdout
@@ -178,7 +181,9 @@ func RunStdin(cmdline []string) {
178181
StartSigHandlers()
179182
if err := cmd.Run(); err != nil {
180183
Errorf("%v", err)
184+
return err
181185
}
186+
return nil
182187
}
183188

184189
// Usage is the usage-reporting function, filled in by package main

‎src/cmd/go/internal/run/run.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package run
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"go/build"
1213
"os"
@@ -203,6 +204,10 @@ func buildRunProgram(b *work.Builder, ctx context.Context, a *work.Action) error
203204
}
204205
}
205206

206-
base.RunStdin(cmdline)
207+
err := base.RunStdin(cmdline)
208+
if err != nil && errors.Is(err, os.ErrPermission) {
209+
printStderr("\tRun 'go env -w GOTMPDIR=...' to specify another temporary directory.\n" +
210+
"\tFor more about GOTMPDIR, see 'go help environment'.\n")
211+
}
207212
return nil
208213
}

‎src/cmd/go/internal/test/test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,11 @@ func (c *runCache) builderRunTest(b *work.Builder, ctx context.Context, a *work.
14461446
// If there was no test output, print the exit status so that the reason
14471447
// for failure is clear.
14481448
fmt.Fprintf(cmd.Stdout, "%s\n", err)
1449+
if errors.Is(err, os.ErrPermission) {
1450+
fmt.Fprint(cmd.Stdout,
1451+
"\tRun 'go env -w GOTMPDIR=...' to specify another temporary directory.\n"+
1452+
"\tFor more about GOTMPDIR, see 'go help environment'.\n")
1453+
}
14491454
} else if !bytes.HasSuffix(out, []byte("\n")) {
14501455
// Otherwise, ensure that the output ends with a newline before the FAIL
14511456
// line we're about to print (https://golang.org/issue/49317).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /