cmd/go: remove the -i build flag

The flag is now removed from `go build` and `go test`.
It has been deprecated since Go 1.16, printing a warning message.
The idea was to fully delete it in Go 1.17, but that didn't happen.

First, delete the BuildI variable and its flag declarations,
as well as all the bits of docs that mentioned the flag.

Second, delete or simplify the code paths that used BuildI.

Third, adapt the tests to the removed flag.
Some of them are removed, like test_relative_import_dash_i.txt and
TestGoTestDashIDashOWritesBinary, as they centered around the flag.
The rest are modified to not cover or use the flag.

Finally, change cmd/dist to no longer use `go install -i`.
The purpose of the flag was that, when bootstrapping the toolchain,
all of its dependencies would also be installed as object files.

When removing the use of the -i flags, the checkNotStale call right
after building toolchain3 would fail as expected,
because runtime/internal/sys is now only up to date in the build cache.

Luckily, that's not a problem: we run `go install std cmd` right after,
so all standard library packages will be installed as object files.
Move the checkNotStale call after that install command.

Fixes #41696.

Change-Id: I5d8139f18aaee07da886d483e663f3f2f00d5f3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/416094
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Daniel Martí 2022-07-05 15:57:37 +01:00
parent 738a2caf08
commit ef1c70fbde
17 changed files with 14 additions and 324 deletions

View file

@ -54,9 +54,6 @@ in the last two paragraphs. If the named output is an existing directory or
ends with a slash or backslash, then any resulting executables
will be written to that directory.
The -i flag installs the packages that are dependencies of the target.
The -i flag is deprecated. Compiled packages are cached automatically.
The build flags are shared by the build, clean, get, install, list, run,
and test commands:
@ -216,11 +213,8 @@ func init() {
CmdBuild.Run = runBuild
CmdInstall.Run = runInstall
CmdBuild.Flag.BoolVar(&cfg.BuildI, "i", false, "")
CmdBuild.Flag.StringVar(&cfg.BuildO, "o", "", "output file or directory")
CmdInstall.Flag.BoolVar(&cfg.BuildI, "i", false, "")
AddBuildFlags(CmdBuild, DefaultBuildFlags)
AddBuildFlags(CmdInstall, DefaultBuildFlags)
if cfg.Experiment != nil && cfg.Experiment.CoverageRedesign {
@ -475,10 +469,6 @@ func runBuild(ctx context.Context, cmd *base.Command, args []string) {
}
depMode := ModeBuild
if cfg.BuildI {
depMode = ModeInstall
fmt.Fprint(os.Stderr, "go: -i flag is deprecated\n")
}
pkgs = omitTestOnly(pkgsFilter(pkgs))
@ -593,9 +583,6 @@ When module-aware mode is disabled, other packages are installed in the
directory $GOPATH/pkg/$GOOS_$GOARCH. When module-aware mode is enabled,
other packages are built and cached but not installed.
The -i flag installs the dependencies of the named packages as well.
The -i flag is deprecated. Compiled packages are cached automatically.
For more about the build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
@ -666,16 +653,8 @@ func libname(args []string, pkgs []*load.Package) (string, error) {
}
func runInstall(ctx context.Context, cmd *base.Command, args []string) {
// TODO(golang.org/issue/41696): print a deprecation message for the -i flag
// whenever it's set (or just remove it). For now, we don't print a message
// if all named packages are in GOROOT. cmd/dist (run by make.bash) uses
// 'go install -i' when bootstrapping, and we don't want to show deprecation
// messages in that case.
for _, arg := range args {
if strings.Contains(arg, "@") && !build.IsLocalImport(arg) && !filepath.IsAbs(arg) {
if cfg.BuildI {
fmt.Fprint(os.Stderr, "go: -i flag is deprecated\n")
}
installOutsideModule(ctx, args)
return
}
@ -707,18 +686,6 @@ func runInstall(ctx context.Context, cmd *base.Command, args []string) {
}
}
load.CheckPackageErrors(pkgs)
if cfg.BuildI {
allGoroot := true
for _, pkg := range pkgs {
if !pkg.Goroot {
allGoroot = false
break
}
}
if !allGoroot {
fmt.Fprintf(os.Stderr, "go: -i flag is deprecated\n")
}
}
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
load.PrepareForCoverageBuild(pkgs)
@ -787,9 +754,6 @@ func InstallPackages(ctx context.Context, patterns []string, pkgs []*load.Packag
}()
depMode := ModeBuild
if cfg.BuildI {
depMode = ModeInstall
}
a := &Action{Mode: "go install"}
var tools []*Action
for _, p := range pkgs {