Daniel Martí has uploaded this change for review.
cmd/go: remove -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
---
M src/cmd/dist/build.go
M src/cmd/dist/test.go
M src/cmd/go/alldocs.go
M src/cmd/go/go_test.go
M src/cmd/go/internal/cfg/cfg.go
M src/cmd/go/internal/test/test.go
M src/cmd/go/internal/test/testflag.go
M src/cmd/go/internal/work/build.go
D src/cmd/go/testdata/script/build_i.txt
D src/cmd/go/testdata/script/build_i_deprecate.txt
M src/cmd/go/testdata/script/build_relative_pkgdir.txt
D src/cmd/go/testdata/script/install_rebuild_gopath.txt
M src/cmd/go/testdata/script/test_flag.txt
M src/cmd/go/testdata/script/test_race_install.txt
D src/cmd/go/testdata/script/test_relative_import_dash_i.txt
M src/cmd/go/testdata/script/vendor_test_issue11864.txt
M src/cmd/go/testdata/script/vendor_test_issue14613.txt
17 files changed, 51 insertions(+), 311 deletions(-)
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
index 7c44c4a..1775909 100644
--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -1357,7 +1357,7 @@
os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
// Now that cmd/go is in charge of the build process, enable GOEXPERIMENT.
os.Setenv("GOEXPERIMENT", goexperiment)
- goInstall(goBootstrap, append([]string{"-i"}, toolchain...)...)
+ goInstall(goBootstrap, toolchain...)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
@@ -1385,13 +1385,12 @@
xprintf("\n")
}
xprintf("Building Go toolchain3 using go_bootstrap and Go toolchain2.\n")
- goInstall(goBootstrap, append([]string{"-a", "-i"}, toolchain...)...)
+ goInstall(goBootstrap, append([]string{"-a"}, toolchain...)...)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec)
}
- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
if goos == oldgoos && goarch == oldgoarch {
// Common case - not setting up for cross-compilation.
@@ -1430,6 +1429,7 @@
targets = targets[:1]
}
goInstall(goBootstrap, targets...)
+ checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
checkNotStale(goBootstrap, targets...)
checkNotStale(cmdGo, targets...)
if debug {
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
index 846d0c0..48cb489 100644
--- a/src/cmd/dist/test.go
+++ b/src/cmd/dist/test.go
@@ -136,7 +136,7 @@
if t.rebuild {
t.out("Building packages and commands.")
// Force rebuild the whole toolchain.
- goInstall("go", append([]string{"-a", "-i"}, toolchain...)...)
+ goInstall("go", append([]string{"-a"}, toolchain...)...)
}
if !t.listMode {
@@ -153,8 +153,8 @@
// to break if we don't automatically refresh things here.
// Rebuilding is a shortened bootstrap.
// See cmdbootstrap for a description of the overall process.
- goInstall("go", append([]string{"-i"}, toolchain...)...)
- goInstall("go", append([]string{"-i"}, toolchain...)...)
+ goInstall("go", toolchain...)
+ goInstall("go", toolchain...)
goInstall("go", "std", "cmd")
} else {
// The Go builder infrastructure should always begin running tests from a
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index db63726..65212ca 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -97,9 +97,6 @@
// 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:
//
@@ -728,9 +725,6 @@
// 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'.
//
@@ -1728,11 +1722,6 @@
// Run the test binary using xprog. The behavior is the same as
// in 'go run'. See 'go help run' for details.
//
-// -i
-// Install packages that are dependencies of the test.
-// Do not run the test.
-// The -i flag is deprecated. Compiled packages are cached automatically.
-//
// -json
// Convert test output to JSON suitable for automated processing.
// See 'go doc test2json' for the encoding details.
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index b39a62f..e2992b8 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -942,7 +942,7 @@
tg.tempFile("d1/src/p1/p1.go", `package main; func main(){}`)
tg.setenv("GOPATH", tg.path("d1"))
// Pass -i flag to rebuild everything outdated.
- tg.run("install", "-i", "p1")
+ tg.run("install", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, before any changes")
// Changing mtime of runtime/internal/sys/sys.go
@@ -964,13 +964,13 @@
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after changing back to old release")
addVar(sys, 2)
tg.wantStale("p1", "stale dependency: runtime", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again")
- tg.run("install", "-i", "p1")
+ tg.run("install", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release")
// Restore to "old" release.
restore()
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after restoring sys.go")
- tg.run("install", "-i", "p1")
+ tg.run("install", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with old release")
}
@@ -1483,22 +1483,6 @@
tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
}
-func TestGoTestDashIDashOWritesBinary(t *testing.T) {
- skipIfGccgo(t, "gccgo has no standard packages")
- tooSlow(t)
- tg := testgo(t)
- defer tg.cleanup()
- tg.parallel()
- tg.makeTempdir()
-
- // don't let test -i overwrite runtime
- tg.wantNotStale("runtime", "", "must be non-stale before test -i")
-
- tg.run("test", "-v", "-i", "-o", tg.path("myerrors.test"+exeSuffix), "errors")
- tg.grepBothNot("PASS|FAIL", "test should not have run")
- tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
-}
-
// Issue 4515.
func TestInstallWithTags(t *testing.T) {
tooSlow(t)
@@ -1835,9 +1819,6 @@
tg.run("install", "-pkgdir", pkg, "sync")
tg.mustExist(filepath.Join(pkg, "sync.a"))
tg.mustNotExist(filepath.Join(pkg, "sync/atomic.a"))
- tg.run("install", "-i", "-pkgdir", pkg, "sync")
- tg.mustExist(filepath.Join(pkg, "sync.a"))
- tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
}
// For issue 14337.
@@ -2644,16 +2625,6 @@
tg.run("install", "p2")
tg.mustExist(p2)
tg.mustNotExist(p1)
-
- // don't let install -i overwrite runtime
- tg.wantNotStale("runtime", "", "must be non-stale before install -i")
-
- tg.run("install", "-i", "main1")
- tg.mustExist(p1)
- tg.must(os.Remove(p1))
-
- tg.run("install", "-i", "p2")
- tg.mustExist(p1)
}
// Issue 22986.
diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index c6ddfe5..53f538a 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -51,7 +51,6 @@
BuildMod string // -mod flag
BuildModExplicit bool // whether -mod was set explicitly
BuildModReason string // reason -mod was set, if set by default
- BuildI bool // -i flag
BuildLinkshared bool // -linkshared flag
BuildMSan bool // -msan flag
BuildASan bool // -asan flag
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index 058906d..e593b3e 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -10,7 +10,6 @@
"crypto/sha256"
"errors"
"fmt"
- "go/build"
"io"
"io/fs"
"os"
@@ -18,7 +17,6 @@
"path"
"path/filepath"
"regexp"
- "sort"
"strconv"
"strings"
"sync"
@@ -152,11 +150,6 @@
Run the test binary using xprog. The behavior is the same as
in 'go run'. See 'go help run' for details.
- -i
- Install packages that are dependencies of the test.
- Do not run the test.
- The -i flag is deprecated. Compiled packages are cached automatically.
-
-json
Convert test output to JSON suitable for automated processing.
See 'go doc test2json' for the encoding details.
@@ -728,11 +721,6 @@
testKillTimeout = testTimeout + 1*time.Minute
}
- // For 'go test -i -o x.test', we want to build x.test. Imply -c to make the logic easier.
- if cfg.BuildI && testO != "" {
- testC = true
- }
-
// Read testcache expiration time, if present.
// (We implement go clean -testcache by writing an expiration date
// instead of searching out and deleting test result cache entries.)
@@ -747,62 +735,6 @@
var b work.Builder
b.Init()
- if cfg.BuildI {
- fmt.Fprint(os.Stderr, "go: -i flag is deprecated\n")
- cfg.BuildV = testV
-
- deps := make(map[string]bool)
- for _, dep := range load.TestMainDeps {
- deps[dep] = true
- }
-
- for _, p := range pkgs {
- // Dependencies for each test.
- for _, path := range p.Imports {
- deps[path] = true
- }
- for _, path := range p.Resolve(p.TestImports) {
- deps[path] = true
- }
- for _, path := range p.Resolve(p.XTestImports) {
- deps[path] = true
- }
- }
-
- // translate C to runtime/cgo
- if deps["C"] {
- delete(deps, "C")
- deps["runtime/cgo"] = true
- }
- // Ignore pseudo-packages.
- delete(deps, "unsafe")
-
- all := []string{}
- for path := range deps {
- if !build.IsLocalImport(path) {
- all = append(all, path)
- }
- }
- sort.Strings(all)
-
- a := &work.Action{Mode: "go test -i"}
- pkgs := load.PackagesAndErrors(ctx, pkgOpts, all)
- load.CheckPackageErrors(pkgs)
- for _, p := range pkgs {
- if cfg.BuildToolchainName == "gccgo" && p.Standard {
- // gccgo's standard library packages
- // can not be reinstalled.
- continue
- }
- a.Deps = append(a.Deps, b.CompileAction(work.ModeInstall, work.ModeInstall, p))
- }
- b.Do(ctx, a)
- if !testC || a.Failed {
- return
- }
- b.Init()
- }
-
var builds, runs, prints []*work.Action
if testCoverPaths != nil {
diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go
index f3cd0b1..78a9c25 100644
--- a/src/cmd/go/internal/test/testflag.go
+++ b/src/cmd/go/internal/test/testflag.go
@@ -31,7 +31,6 @@
cf := CmdTest.Flag
cf.BoolVar(&testC, "c", false, "")
- cf.BoolVar(&cfg.BuildI, "i", false, "")
cf.StringVar(&testO, "o", "", "")
cf.BoolVar(&testCover, "cover", false, "")
@@ -390,12 +389,8 @@
args = remainingArgs
}
- if firstUnknownFlag != "" && (testC || cfg.BuildI) {
- buildFlag := "-c"
- if !testC {
- buildFlag = "-i"
- }
- fmt.Fprintf(os.Stderr, "go: unknown flag %s cannot be used with %s\n", firstUnknownFlag, buildFlag)
+ if firstUnknownFlag != "" && testC {
+ fmt.Fprintf(os.Stderr, "go: unknown flag %s cannot be used with -c\n", firstUnknownFlag)
exitWithUsage()
}
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 42745d9..4150842 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -53,9 +53,6 @@
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:
@@ -206,11 +203,8 @@
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)
}
@@ -432,10 +426,6 @@
}
depMode := ModeBuild
- if cfg.BuildI {
- depMode = ModeInstall
- fmt.Fprint(os.Stderr, "go: -i flag is deprecated\n")
- }
pkgs = omitTestOnly(pkgsFilter(pkgs))
@@ -546,9 +536,6 @@
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'.
@@ -619,16 +606,8 @@
}
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
}
@@ -660,18 +639,6 @@
}
}
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")
- }
- }
InstallPackages(ctx, args, pkgs)
}
@@ -731,9 +698,6 @@
var b Builder
b.Init()
depMode := ModeBuild
- if cfg.BuildI {
- depMode = ModeInstall
- }
a := &Action{Mode: "go install"}
var tools []*Action
for _, p := range pkgs {
diff --git a/src/cmd/go/testdata/script/build_i.txt b/src/cmd/go/testdata/script/build_i.txt
deleted file mode 100644
index 0e7ebed..0000000
--- a/src/cmd/go/testdata/script/build_i.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-env GO111MODULE=off
-
-# Test that 'go build -i' installs dependencies of the requested package.
-
-[short] skip
-
-# Since we are checking installation of dependencies, use a clean cache
-# to ensure that multiple runs of the test do not interfere.
-env GOCACHE=$WORK/cache
-
-# The initial 'go build -i' for bar should install its dependency foo.
-
-go build -v -i x/y/bar
-stderr 'x/y/foo' # should be rebuilt
-go build -v -i x/y/bar
-! stderr 'x/y/foo' # should already be installed
-
-# After modifying the source files, both packages should be rebuild.
-
-cp x/y/foo/foo.go.next x/y/foo/foo.go
-cp x/y/bar/bar.go.next x/y/bar/bar.go
-
-go build -v -i x/y/bar
-stderr 'x/y/foo' # should be rebuilt
-go build -v -i x/y/bar
-! stderr 'x/y/foo' # should already be installed
-
--- x/y/foo/foo.go --
-package foo
-func F() {}
--- x/y/bar/bar.go --
-package bar
-import "x/y/foo"
-func F() { foo.F() }
--- x/y/foo/foo.go.next --
-package foo
-func F() { F() }
--- x/y/bar/bar.go.next --
-package main
-import "x/y/foo"
-func main() { foo.F() }
diff --git a/src/cmd/go/testdata/script/build_i_deprecate.txt b/src/cmd/go/testdata/script/build_i_deprecate.txt
deleted file mode 100644
index 5c17995..0000000
--- a/src/cmd/go/testdata/script/build_i_deprecate.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-# Check that deprecation warnings are printed when the -i flag is used.
-# TODO(golang.org/issue/41696): remove the -i flag after Go 1.16, and this test.
-
-go build -n -i
-stderr '^go: -i flag is deprecated$'
-
-go install -n -i
-stderr '^go: -i flag is deprecated$'
-
-go test -n -i
-stderr '^go: -i flag is deprecated$'
-
-
-# 'go clean -i' should not print a deprecation warning.
-# It will continue working.
-go clean -i .
-! stderr .
-
--- go.mod --
-module m
-
-go 1.16
--- m.go --
-package m
diff --git a/src/cmd/go/testdata/script/build_relative_pkgdir.txt b/src/cmd/go/testdata/script/build_relative_pkgdir.txt
index 0716bcd..57f18ee 100644
--- a/src/cmd/go/testdata/script/build_relative_pkgdir.txt
+++ b/src/cmd/go/testdata/script/build_relative_pkgdir.txt
@@ -6,4 +6,4 @@
mkdir $WORK/gocache
env GOCACHE=$WORK/gocache
-go build -i -pkgdir=. runtime
+go build -pkgdir=. runtime
diff --git a/src/cmd/go/testdata/script/install_rebuild_gopath.txt b/src/cmd/go/testdata/script/install_rebuild_gopath.txt
deleted file mode 100644
index 14a6c86..0000000
--- a/src/cmd/go/testdata/script/install_rebuild_gopath.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-env GO111MODULE=off
-
-# GOPATH with p1 in d1, p2 in d2
-env GOPATH=$WORK/d1${:}$WORK/d2
-
-# build & install p1
-go install -i p1
-! stale p1 p2
-
-# modify p2 - p1 should appear stale
-cp $WORK/p2x.go $WORK/d2/src/p2/p2.go
-stale p1 p2
-
-# build & install p1 again
-go install -i p1
-! stale p1 p2
-
--- $WORK/d1/src/p1/p1.go --
-package p1
-import "p2"
-func F() { p2.F() }
-
--- $WORK/d2/src/p2/p2.go --
-package p2
-func F() {}
-
--- $WORK/p2x.go --
-package p2
-func F() {}
-func G() {}
diff --git a/src/cmd/go/testdata/script/test_flag.txt b/src/cmd/go/testdata/script/test_flag.txt
index d168cfe..6ef4529 100644
--- a/src/cmd/go/testdata/script/test_flag.txt
+++ b/src/cmd/go/testdata/script/test_flag.txt
@@ -6,14 +6,12 @@
# Using a custom flag mixed with regular 'go test' flags should be OK.
go test -count=1 -custom -args -v=7
-# However, it should be an error to use custom flags when -i or -c are used,
+# However, it should be an error to use custom flags when -c is used,
# since we know for sure that no test binary will run at all.
-! go test -i -custom
-stderr '^go: unknown flag -custom cannot be used with -i$'
! go test -c -custom
stderr '^go: unknown flag -custom cannot be used with -c$'
-# The same should apply even if -c or -i come after a custom flag.
+# The same should apply even if -c comes after a custom flag.
! go test -custom -c
stderr '^go: unknown flag -custom cannot be used with -c$'
diff --git a/src/cmd/go/testdata/script/test_race_install.txt b/src/cmd/go/testdata/script/test_race_install.txt
index a1d47a7..918d7e9 100644
--- a/src/cmd/go/testdata/script/test_race_install.txt
+++ b/src/cmd/go/testdata/script/test_race_install.txt
@@ -4,15 +4,9 @@
mkdir $WORKDIR/tmp/pkg
go install -race -pkgdir=$WORKDIR/tmp/pkg std
-# Make sure go test -i -race doesn't rebuild cached packages
-go test -race -pkgdir=$WORKDIR/tmp/pkg -i -v empty/pkg
-cmp stderr stderr.txt
-
-- go.mod --
module empty
go 1.16
-- pkg/pkg.go --
package p
--- stderr.txt --
-go: -i flag is deprecated
diff --git a/src/cmd/go/testdata/script/test_relative_import_dash_i.txt b/src/cmd/go/testdata/script/test_relative_import_dash_i.txt
deleted file mode 100644
index b2716d8..0000000
--- a/src/cmd/go/testdata/script/test_relative_import_dash_i.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-# Relative imports in go test -i
-env GO111MODULE=off # relative import not supported in module mode
-
-# Run tests outside GOPATH.
-env GOPATH=$WORK/tmp
-
-# Check that it's safe to pass -i (which installs dependencies in $GOPATH/pkg) to go test.
-! stale runtime # don't let test -i overwrite runtime
-go test -i ./testimport
-
--- testimport/p.go --
-package p
-
-func F() int { return 1 }
--- testimport/p1/p1.go --
-package p1
-
-func F() int { return 1 }
--- testimport/p_test.go --
-package p
-
-import (
- "./p1"
-
- "testing"
-)
-
-func TestF(t *testing.T) {
- if F() != p1.F() {
- t.Fatal(F())
- }
-}
diff --git a/src/cmd/go/testdata/script/vendor_test_issue11864.txt b/src/cmd/go/testdata/script/vendor_test_issue11864.txt
index cfb43bf..b9ee434 100644
--- a/src/cmd/go/testdata/script/vendor_test_issue11864.txt
+++ b/src/cmd/go/testdata/script/vendor_test_issue11864.txt
@@ -4,14 +4,6 @@
go get github.com/rsc/go-get-issue-11864
-# build -i should work
-go build -i github.com/rsc/go-get-issue-11864
-go build -i github.com/rsc/go-get-issue-11864/t
-
-# test -i should work like build -i (golang.org/issue/11988)
-go test -i github.com/rsc/go-get-issue-11864
-go test -i github.com/rsc/go-get-issue-11864/t
-
# test should work too
go test github.com/rsc/go-get-issue-11864
go test github.com/rsc/go-get-issue-11864/t
diff --git a/src/cmd/go/testdata/script/vendor_test_issue14613.txt b/src/cmd/go/testdata/script/vendor_test_issue14613.txt
index cfd7e58..8759445 100644
--- a/src/cmd/go/testdata/script/vendor_test_issue14613.txt
+++ b/src/cmd/go/testdata/script/vendor_test_issue14613.txt
@@ -5,18 +5,14 @@
cd $GOPATH
go get github.com/clsung/go-vendor-issue-14613
-go build -o $WORK/a.out -i github.com/clsung/go-vendor-issue-14613
# test folder should work
-go test -i github.com/clsung/go-vendor-issue-14613
go test github.com/clsung/go-vendor-issue-14613
# test with specified _test.go should work too
cd $GOPATH/src
-go test -i github.com/clsung/go-vendor-issue-14613/vendor_test.go
go test github.com/clsung/go-vendor-issue-14613/vendor_test.go
# test with imported and not used
-go test -i github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go
! go test github.com/clsung/go-vendor-issue-14613/vendor/mylibtesttest/myapp/myapp_test.go
stderr 'imported and not used'
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills.
1 comment:
Patchset:
I took a stab at this as I stumbled upon the flag still being around :)
For 1.20, likely early in cycle in case I got anything wrong. I verified that make.bash and go test cmd/go both succeed.
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Daniel Martí.
Daniel Martí uploaded patch set #2 to this change.
The following approvals got outdated and were removed: Run-TryBot+1 by Daniel Martí
cmd/go: remove the -i build flag
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills.
Patch set 2:Run-TryBot +1
Attention is currently required from: Bryan Mills.
1 comment:
Patchset:
1 of 30 TryBots failed. […]
I imagine we can fix js/wasm by skipping the staleness checks on cmd/... object files. That target avoids running `go install cmd` per https://github.com/golang/go/issues/25911, so it seems to be on purpose.
I'll wait to get a review on the overall approach of the changes, though, to not spend extra time on this in case it's misguided :)
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Daniel Martí.
Daniel Martí uploaded patch set #3 to this change.
The following approvals got outdated and were removed: Run-TryBot+1 by Daniel Martí, TryBot-Result-1 by Gopher Robot
17 files changed, 51 insertions(+), 323 deletions(-)
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Patchset:
Rebased to fix a minor conflict.
I'll wait to get a review on the overall approach of the changes, though, to not spend extra time on this in case it's misguided :)
Bryan, do you have any spare cycles to review this CL this cycle? No worries if not - it's not urgent so it could be pushed back to 1.21. I am happy to do the legwork otherwise, and hopefully it's going to be easy enough to get it into 1.20 and remove the flag for good.
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Daniel Martí.
1 comment:
Patchset:
We talked with Russ about this this afternoon and we're set to review for Go 1.20. I'm planning to give it a proper review probably tomorrow.
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Daniel Martí.
Patch set 3:Run-TryBot +1Code-Review +2
2 comments:
Patchset:
I imagine we can fix js/wasm by skipping the staleness checks on cmd/... object files. […]
The `js-wasm` failure may have been incidentally fixed by the change to `cmd/dist/build.go` in CL 435237. I suggest that you try rebasing and see if it resolves. 🙂
Patchset:
TRY=longtest,windows-amd64-longtest,darwin
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Daniel Martí.
1 comment:
Patchset:
(Also, this CL is refreshingly red. We don't get many of those. Thanks for pushing this forward!)
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills.
Patch set 4:Run-TryBot +1
1 comment:
Patchset:
TRY=longtest,windows-amd64-longtest,darwin
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Daniel Martí.
Daniel Martí uploaded patch set #5 to this change.
The following approvals got outdated and were removed: Run-TryBot+1 by Daniel Martí
cmd/go: remove the -i build flag
17 files changed, 51 insertions(+), 324 deletions(-)
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills.
Patch set 5:Run-TryBot +1
1 comment:
Patchset:
Rebasing per your comment, though I didn't spot the unused import due to it. Trying again.
TRY=longtest,windows-amd64-longtest,darwin
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Daniel Martí.
Patch set 5:Code-Review +1
Daniel Martí submitted this change.
3 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: src/cmd/go/internal/test/testflag.go
Insertions: 0, Deletions: 1.
The diff is too large to show. Please review the diff.
```
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 <bcm...@google.com>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Run-TryBot: Daniel Martí <mv...@mvdan.cc>
TryBot-Result: Gopher Robot <go...@golang.org>
---
M src/cmd/dist/build.go
M src/cmd/dist/test.go
M src/cmd/go/alldocs.go
M src/cmd/go/go_test.go
M src/cmd/go/internal/cfg/cfg.go
M src/cmd/go/internal/test/test.go
M src/cmd/go/internal/test/testflag.go
M src/cmd/go/internal/work/build.go
D src/cmd/go/testdata/script/build_i.txt
D src/cmd/go/testdata/script/build_i_deprecate.txt
M src/cmd/go/testdata/script/build_relative_pkgdir.txt
D src/cmd/go/testdata/script/install_rebuild_gopath.txt
M src/cmd/go/testdata/script/test_flag.txt
M src/cmd/go/testdata/script/test_race_install.txt
D src/cmd/go/testdata/script/test_relative_import_dash_i.txt
M src/cmd/go/testdata/script/vendor_test_issue11864.txt
M src/cmd/go/testdata/script/vendor_test_issue14613.txt
17 files changed, 56 insertions(+), 324 deletions(-)
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
index dae8531..b51f56d 100644
--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -1359,7 +1359,7 @@
os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
// Now that cmd/go is in charge of the build process, enable GOEXPERIMENT.
os.Setenv("GOEXPERIMENT", goexperiment)
- goInstall(goBootstrap, append([]string{"-i"}, toolchain...)...)
+ goInstall(goBootstrap, toolchain...)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
@@ -1387,13 +1387,12 @@
xprintf("\n")
}
xprintf("Building Go toolchain3 using go_bootstrap and Go toolchain2.\n")
- goInstall(goBootstrap, append([]string{"-a", "-i"}, toolchain...)...)
+ goInstall(goBootstrap, append([]string{"-a"}, toolchain...)...)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec)
}
- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
if goos == oldgoos && goarch == oldgoarch {
// Common case - not setting up for cross-compilation.
@@ -1428,6 +1427,7 @@
}
targets := []string{"std", "cmd"}
goInstall(goBootstrap, targets...)
+ checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
checkNotStale(goBootstrap, targets...)
checkNotStale(cmdGo, targets...)
if debug {
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
index d27afb9..7f85fc1 100644
--- a/src/cmd/dist/test.go
+++ b/src/cmd/dist/test.go
@@ -136,7 +136,7 @@
if t.rebuild {
t.out("Building packages and commands.")
// Force rebuild the whole toolchain.
- goInstall("go", append([]string{"-a", "-i"}, toolchain...)...)
+ goInstall("go", append([]string{"-a"}, toolchain...)...)
}
if !t.listMode {
@@ -153,8 +153,8 @@
// to break if we don't automatically refresh things here.
// Rebuilding is a shortened bootstrap.
// See cmdbootstrap for a description of the overall process.
- goInstall("go", append([]string{"-i"}, toolchain...)...)
- goInstall("go", append([]string{"-i"}, toolchain...)...)
+ goInstall("go", toolchain...)
+ goInstall("go", toolchain...)
goInstall("go", "std", "cmd")
} else {
// The Go builder infrastructure should always begin running tests from a
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 79410f0..f83a7e2 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -97,9 +97,6 @@
// 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:
//
@@ -744,9 +741,6 @@
// 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'.
//
@@ -1744,11 +1738,6 @@
// Run the test binary using xprog. The behavior is the same as
// in 'go run'. See 'go help run' for details.
//
-// -i
-// Install packages that are dependencies of the test.
-// Do not run the test.
-// The -i flag is deprecated. Compiled packages are cached automatically.
-//
// -json
// Convert test output to JSON suitable for automated processing.
// See 'go doc test2json' for the encoding details.
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index ee1cbc1..acc4d66 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -947,7 +947,7 @@
tg.tempFile("d1/src/p1/p1.go", `package main; func main(){}`)
tg.setenv("GOPATH", tg.path("d1"))
// Pass -i flag to rebuild everything outdated.
- tg.run("install", "-i", "p1")
+ tg.run("install", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, before any changes")
// Changing mtime of runtime/internal/sys/sys.go
@@ -969,13 +969,13 @@
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after changing back to old release")
addVar(sys, 2)
tg.wantStale("p1", "stale dependency: runtime", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again")
- tg.run("install", "-i", "p1")
+ tg.run("install", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release")
// Restore to "old" release.
restore()
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after restoring sys.go")
- tg.run("install", "-i", "p1")
+ tg.run("install", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with old release")
}
@@ -1459,22 +1459,6 @@
tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
}
-func TestGoTestDashIDashOWritesBinary(t *testing.T) {
- skipIfGccgo(t, "gccgo has no standard packages")
- tooSlow(t)
- tg := testgo(t)
- defer tg.cleanup()
- tg.parallel()
- tg.makeTempdir()
-
- // don't let test -i overwrite runtime
- tg.wantNotStale("runtime", "", "must be non-stale before test -i")
-
- tg.run("test", "-v", "-i", "-o", tg.path("myerrors.test"+exeSuffix), "errors")
- tg.grepBothNot("PASS|FAIL", "test should not have run")
- tg.wantExecutable(tg.path("myerrors.test"+exeSuffix), "go test -o myerrors.test did not create myerrors.test")
-}
-
// Issue 4515.
func TestInstallWithTags(t *testing.T) {
tooSlow(t)
@@ -1811,9 +1795,6 @@
tg.run("install", "-pkgdir", pkg, "sync")
tg.mustExist(filepath.Join(pkg, "sync.a"))
tg.mustNotExist(filepath.Join(pkg, "sync/atomic.a"))
- tg.run("install", "-i", "-pkgdir", pkg, "sync")
- tg.mustExist(filepath.Join(pkg, "sync.a"))
- tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
}
// For issue 14337.
@@ -2626,16 +2607,6 @@
tg.run("install", "p2")
tg.mustExist(p2)
tg.mustNotExist(p1)
-
- // don't let install -i overwrite runtime
- tg.wantNotStale("runtime", "", "must be non-stale before install -i")
-
- tg.run("install", "-i", "main1")
- tg.mustExist(p1)
- tg.must(os.Remove(p1))
-
- tg.run("install", "-i", "p2")
- tg.mustExist(p1)
}
// Issue 22986.
diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index fbf91be..ba02944 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -70,7 +70,6 @@
BuildMod string // -mod flag
BuildModExplicit bool // whether -mod was set explicitly
BuildModReason string // reason -mod was set, if set by default
- BuildI bool // -i flag
BuildLinkshared bool // -linkshared flag
BuildMSan bool // -msan flag
BuildASan bool // -asan flag
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index d6cec78..9a59bba 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -9,14 +9,12 @@
"context"
"errors"
"fmt"
- "go/build"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
"regexp"
- "sort"
"strconv"
"strings"
"sync"
@@ -150,11 +148,6 @@
Run the test binary using xprog. The behavior is the same as
in 'go run'. See 'go help run' for details.
- -i
- Install packages that are dependencies of the test.
- Do not run the test.
- The -i flag is deprecated. Compiled packages are cached automatically.
-
-json
Convert test output to JSON suitable for automated processing.
See 'go doc test2json' for the encoding details.
@@ -732,11 +725,6 @@
testKillTimeout = testTimeout + 1*time.Minute
}
- // For 'go test -i -o x.test', we want to build x.test. Imply -c to make the logic easier.
- if cfg.BuildI && testO != "" {
- testC = true
- }
-
// Read testcache expiration time, if present.
// (We implement go clean -testcache by writing an expiration date
// instead of searching out and deleting test result cache entries.)
@@ -755,74 +743,6 @@- // TODO(bcmills): I have no idea why the Builder must be reset here, but
- // without this reset dance, TestGoTestDashIDashOWritesBinary fails with
- // lots of "vet config not found" errors. This was added in CL 5699088,
- // which had almost no public discussion, a very short commit description,
- // and left no comment in the code to explain what is going on here. 🤯
- //
- // Maybe this has the effect of removing actions that were registered by the
- // call to CompileAction above?
- if err := b.Close(); err != nil {
- base.Fatalf("go: %v", err)
- }
- b = work.NewBuilder("")
- }
-
var builds, runs, prints []*work.Action
if cfg.BuildCoverPkg != nil {
diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go
index 2b2bd87..55f6ebf 100644
--- a/src/cmd/go/internal/test/testflag.go
+++ b/src/cmd/go/internal/test/testflag.go
@@ -6,7 +6,6 @@
import (
"cmd/go/internal/base"
- "cmd/go/internal/cfg"
"cmd/go/internal/cmdflag"
"cmd/go/internal/work"
"errors"
@@ -31,7 +30,6 @@
cf := CmdTest.Flag
cf.BoolVar(&testC, "c", false, "")
- cf.BoolVar(&cfg.BuildI, "i", false, "")
cf.StringVar(&testO, "o", "", "")
work.AddCoverFlags(CmdTest, &testCoverProfile)
cf.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
@@ -337,12 +335,8 @@
args = remainingArgs
}
- if firstUnknownFlag != "" && (testC || cfg.BuildI) {
- buildFlag := "-c"
- if !testC {
- buildFlag = "-i"
- }
- fmt.Fprintf(os.Stderr, "go: unknown flag %s cannot be used with %s\n", firstUnknownFlag, buildFlag)
+ if firstUnknownFlag != "" && testC {
+ fmt.Fprintf(os.Stderr, "go: unknown flag %s cannot be used with -c\n", firstUnknownFlag)
exitWithUsage()
}
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 2acc153..6a83ec6 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -54,9 +54,6 @@
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 @@
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 @@
}
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 @@
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 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 @@
}
}
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 @@
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
RELNOTE=yes
To view, visit change 416094. To unsubscribe, or for help writing mail filters, visit settings.