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

cmd/go: improve handling of tmpdir being noexec #52959

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

Open
ZekeLu wants to merge 1 commit into golang:master
base: master
Choose a base branch
Loading
from ZekeLu:tmpdir-noexec
Open
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
13 changes: 9 additions & 4 deletions src/cmd/go/internal/base/base.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ func GetExitStatus() int {

// Run runs the command, with stdout and stderr
// connected to the go command's own stdout and stderr.
// If the command fails, Run reports the error using Errorf.
func Run(cmdargs ...any) {
// If the command fails, Run reports the error using Errorf,
// and it also returns the error so that the caller can use it.
func Run(cmdargs ...any) error {
cmdline := str.StringList(cmdargs...)
if cfg.BuildN || cfg.BuildX {
fmt.Printf("%s\n", strings.Join(cmdline, " "))
if cfg.BuildN {
return
return nil
}
}

Expand All @@ -165,11 +166,13 @@ func Run(cmdargs ...any) {
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Errorf("%v", err)
return err
}
return nil
}

// RunStdin is like run but connects Stdin.
func RunStdin(cmdline []string) {
func RunStdin(cmdline []string) error {
cmd := exec.Command(cmdline[0], cmdline[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand All @@ -178,7 +181,9 @@ func RunStdin(cmdline []string) {
StartSigHandlers()
if err := cmd.Run(); err != nil {
Errorf("%v", err)
return err
}
return nil
}

// Usage is the usage-reporting function, filled in by package main
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/go/internal/run/run.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package run

import (
"context"
"errors"
"fmt"
"go/build"
"os"
Expand Down Expand Up @@ -203,6 +204,10 @@ func buildRunProgram(b *work.Builder, ctx context.Context, a *work.Action) error
}
}

base.RunStdin(cmdline)
err := base.RunStdin(cmdline)
if err != nil && errors.Is(err, os.ErrPermission) {
printStderr("\tRun 'go env -w GOTMPDIR=...' to specify another temporary directory.\n" +
"\tFor more about GOTMPDIR, see 'go help environment'.\n")
}
return nil
}
5 changes: 5 additions & 0 deletions src/cmd/go/internal/test/test.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@ func (c *runCache) builderRunTest(b *work.Builder, ctx context.Context, a *work.
// If there was no test output, print the exit status so that the reason
// for failure is clear.
fmt.Fprintf(cmd.Stdout, "%s\n", err)
if errors.Is(err, os.ErrPermission) {
fmt.Fprint(cmd.Stdout,
"\tRun 'go env -w GOTMPDIR=...' to specify another temporary directory.\n"+
"\tFor more about GOTMPDIR, see 'go help environment'.\n")
}
} else if !bytes.HasSuffix(out, []byte("\n")) {
// Otherwise, ensure that the output ends with a newline before the FAIL
// line we're about to print (https://golang.org/issue/49317).
Expand Down

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