Skip to content

Commit 8a368c6

Browse files
author
Jay Conrod
committed
cmd/go: print deprecation messages for -i
build, install, and test will now print deprecation messages when the -i flag is used. clean will continue to support -i. For #41696 Change-Id: I956c235c487a872c5e6c1395388b4d6cd5ef817a Reviewed-on: https://go-review.googlesource.com/c/go/+/266368 Trust: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 6560768 commit 8a368c6

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

doc/go1.16.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ <h4 id="toolexec">The <code>-toolexec</code> build flag</h4>
151151
being built.
152152
</p>
153153

154+
<h4 id="i-flag">The <code>-i</code> build flag</h4>
155+
156+
<p><!-- golang.org/issue/41696 -->
157+
The <code>-i</code> flag accepted by <code>go</code> <code>build</code>,
158+
<code>go</code> <code>install</code>, and <code>go</code> <code>test</code> is
159+
now deprecated. The <code>-i</code> flag instructs the <code>go</code> command
160+
to install packages imported by packages named on the command line. Since
161+
the build cache was introduced in Go 1.10, the <code>-i</code> flag no longer
162+
has a significant effect on build times, and it causes errors when the install
163+
directory is not writable.
164+
</p>
165+
154166
<h4 id="list-buildid">The <code>list</code> command</h4>
155167

156168
<p><!-- golang.org/cl/263542 -->

src/cmd/go/alldocs.go

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/test/test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ In addition to the build flags, the flags handled by 'go test' itself are:
150150
-i
151151
Install packages that are dependencies of the test.
152152
Do not run the test.
153+
The -i flag is deprecated. Compiled packages are cached automatically.
153154
154155
-json
155156
Convert test output to JSON suitable for automated processing.
@@ -640,6 +641,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
640641
b.Init()
641642

642643
if cfg.BuildI {
644+
fmt.Fprint(os.Stderr, "go test: -i flag is deprecated\n")
643645
cfg.BuildV = testV
644646

645647
deps := make(map[string]bool)

src/cmd/go/internal/work/build.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
var CmdBuild = &base.Command{
34-
UsageLine: "go build [-o output] [-i] [build flags] [packages]",
34+
UsageLine: "go build [-o output] [build flags] [packages]",
3535
Short: "compile packages and dependencies",
3636
Long: `
3737
Build compiles the packages named by the import paths,
@@ -59,6 +59,7 @@ ends with a slash or backslash, then any resulting executables
5959
will be written to that directory.
6060
6161
The -i flag installs the packages that are dependencies of the target.
62+
The -i flag is deprecated. Compiled packages are cached automatically.
6263
6364
The build flags are shared by the build, clean, get, install, list, run,
6465
and test commands:
@@ -381,6 +382,7 @@ func runBuild(ctx context.Context, cmd *base.Command, args []string) {
381382
depMode := ModeBuild
382383
if cfg.BuildI {
383384
depMode = ModeInstall
385+
fmt.Fprint(os.Stderr, "go build: -i flag is deprecated\n")
384386
}
385387

386388
pkgs = omitTestOnly(pkgsFilter(load.Packages(ctx, args)))
@@ -444,7 +446,7 @@ func runBuild(ctx context.Context, cmd *base.Command, args []string) {
444446
}
445447

446448
var CmdInstall = &base.Command{
447-
UsageLine: "go install [-i] [build flags] [packages]",
449+
UsageLine: "go install [build flags] [packages]",
448450
Short: "compile and install packages and dependencies",
449451
Long: `
450452
Install compiles and installs the packages named by the import paths.
@@ -486,6 +488,7 @@ directory $GOPATH/pkg/$GOOS_$GOARCH. When module-aware mode is enabled,
486488
other packages are built and cached but not installed.
487489
488490
The -i flag installs the dependencies of the named packages as well.
491+
The -i flag is deprecated. Compiled packages are cached automatically.
489492
490493
For more about the build flags, see 'go help build'.
491494
For more about specifying packages, see 'go help packages'.
@@ -551,14 +554,35 @@ func libname(args []string, pkgs []*load.Package) (string, error) {
551554
}
552555

553556
func runInstall(ctx context.Context, cmd *base.Command, args []string) {
557+
// TODO(golang.org/issue/41696): print a deprecation message for the -i flag
558+
// whenever it's set (or just remove it). For now, we don't print a message
559+
// if all named packages are in GOROOT. cmd/dist (run by make.bash) uses
560+
// 'go install -i' when bootstrapping, and we don't want to show deprecation
561+
// messages in that case.
554562
for _, arg := range args {
555563
if strings.Contains(arg, "@") && !build.IsLocalImport(arg) && !filepath.IsAbs(arg) {
564+
if cfg.BuildI {
565+
fmt.Fprint(os.Stderr, "go install: -i flag is deprecated\n")
566+
}
556567
installOutsideModule(ctx, args)
557568
return
558569
}
559570
}
560571
BuildInit()
561-
InstallPackages(ctx, args, load.PackagesForBuild(ctx, args))
572+
pkgs := load.PackagesForBuild(ctx, args)
573+
if cfg.BuildI {
574+
allGoroot := true
575+
for _, pkg := range pkgs {
576+
if !pkg.Goroot {
577+
allGoroot = false
578+
break
579+
}
580+
}
581+
if !allGoroot {
582+
fmt.Fprint(os.Stderr, "go install: -i flag is deprecated\n")
583+
}
584+
}
585+
InstallPackages(ctx, args, pkgs)
562586
}
563587

564588
// omitTestOnly returns pkgs with test-only packages removed.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Check that deprecation warnings are printed when the -i flag is used.
2+
# TODO(golang.org/issue/41696): remove the -i flag after Go 1.16, and this test.
3+
4+
go build -n -i
5+
stderr '^go build: -i flag is deprecated$'
6+
7+
go install -n -i
8+
stderr '^go install: -i flag is deprecated$'
9+
10+
go test -n -i
11+
stderr '^go test: -i flag is deprecated$'
12+
13+
14+
# 'go clean -i' should not print a deprecation warning.
15+
# It will continue working.
16+
go clean -i .
17+
! stderr .
18+
19+
-- go.mod --
20+
module m
21+
22+
go 1.16
23+
-- m.go --
24+
package m

0 commit comments

Comments
 (0)