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>
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))
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.
}
targets := []string{"std", "cmd"}
goInstall(goBootstrap, targets...)
+ checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
checkNotStale(goBootstrap, targets...)
checkNotStale(cmdGo, targets...)
if debug {
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 {
// 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
// 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:
//
// 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'.
//
// 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.
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
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")
}
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)
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.
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.
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
"context"
"errors"
"fmt"
- "go/build"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
"regexp"
- "sort"
"strconv"
"strings"
"sync"
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.
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.)
}
}()
- 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
- }
-
- // 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 {
import (
"cmd/go/internal/base"
- "cmd/go/internal/cfg"
"cmd/go/internal/cmdflag"
"cmd/go/internal/work"
"errors"
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", "")
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()
}
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:
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 {
}
depMode := ModeBuild
- if cfg.BuildI {
- depMode = ModeInstall
- fmt.Fprint(os.Stderr, "go: -i flag is deprecated\n")
- }
pkgs = omitTestOnly(pkgsFilter(pkgs))
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'.
}
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
}
}
}
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)
}()
depMode := ModeBuild
- if cfg.BuildI {
- depMode = ModeInstall
- }
a := &Action{Mode: "go install"}
var tools []*Action
for _, p := range pkgs {
+++ /dev/null
-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() }
+++ /dev/null
-# 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
mkdir $WORK/gocache
env GOCACHE=$WORK/gocache
-go build -i -pkgdir=. runtime
+go build -pkgdir=. runtime
+++ /dev/null
-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() {}
# 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$'
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
+++ /dev/null
-# 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())
- }
-}
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
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'