package reboot_test
import (
+ "fmt"
+ "io"
"os"
"os/exec"
"path/filepath"
"runtime"
+ "strings"
"testing"
"time"
)
makeScript = "make.bash"
}
+ var stdout strings.Builder
cmd := exec.Command(filepath.Join(goroot, "src", makeScript))
cmd.Dir = gorootSrc
- cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+realGoroot)
+ cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_FINAL=", "GOROOT_BOOTSTRAP="+realGoroot)
cmd.Stderr = os.Stderr
- cmd.Stdout = os.Stdout
+ cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
+
+ // Test that go.dev/issue/42563 hasn't regressed.
+ t.Run("PATH reminder", func(t *testing.T) {
+ var want string
+ switch gorootBin := filepath.Join(goroot, "bin"); runtime.GOOS {
+ default:
+ want = fmt.Sprintf("*** You need to add %s to your PATH.", gorootBin)
+ case "plan9":
+ want = fmt.Sprintf("*** You need to bind %s before /bin.", gorootBin)
+ }
+ if got := stdout.String(); !strings.Contains(got, want) {
+ t.Errorf("reminder %q is missing from %s stdout:\n%s", want, makeScript, got)
+ }
+ })
}
echo 'all.bash must be run from $GOROOT/src' 1>&2
exit 1
fi
-OLDPATH="$PATH"
. ./make.bash "$@" --no-banner
bash run.bash --no-rebuild
-PATH="$OLDPATH"
$GOTOOLDIR/dist banner # print build info
goto end\r
:ok\r
\r
-set OLDPATH=%PATH%\r
call .\make.bat --no-banner --no-local\r
if %GOBUILDFAIL%==1 goto end\r
call .\run.bat --no-rebuild --no-local\r
if %GOBUILDFAIL%==1 goto end\r
-:: we must restore %PATH% before running "dist banner" so that the latter\r
-:: can get the original %PATH% and give suggestion to add %GOROOT%/bin\r
-:: to %PATH% if necessary.\r
-set PATH=%OLDPATH%\r
"%GOTOOLDIR%/dist" banner\r
\r
:end\r
windows := flag.Bool("w", gohostos == "windows", "emit windows syntax")
xflagparse(0)
- format := "%s=\"%s\"\n"
+ format := "%s=\"%s\";\n" // Include ; to separate variables when 'dist env' output is used with eval.
switch {
case *plan9:
format = "%s='%s'\n"
sep = ";"
}
xprintf(format, "PATH", fmt.Sprintf("%s%s%s", gorootBin, sep, os.Getenv("PATH")))
+
+ // Also include $DIST_UNMODIFIED_PATH with the original $PATH
+ // for the internal needs of "dist banner", along with export
+ // so that it reaches the dist process. See its comment below.
+ var exportFormat string
+ if !*windows && !*plan9 {
+ exportFormat = "export " + format
+ } else {
+ exportFormat = format
+ }
+ xprintf(exportFormat, "DIST_UNMODIFIED_PATH", os.Getenv("PATH"))
}
}
if gohostos == "windows" {
pathsep = ";"
}
- if !strings.Contains(pathsep+os.Getenv("PATH")+pathsep, pathsep+gorootBin+pathsep) {
+ path := os.Getenv("PATH")
+ if p, ok := os.LookupEnv("DIST_UNMODIFIED_PATH"); ok {
+ // Scripts that modify $PATH and then run dist should also provide
+ // dist with an unmodified copy of $PATH via $DIST_UNMODIFIED_PATH.
+ // Use it here when determining if the user still needs to update
+ // their $PATH. See go.dev/issue/42563.
+ path = p
+ }
+ if !strings.Contains(pathsep+path+pathsep, pathsep+gorootBin+pathsep) {
xprintf("*** You need to add %s to your PATH.\n", gorootBin)
}
}