@@ -31,7 +31,7 @@ import (
31
31
)
32
32
33
33
var CmdBuild = & base.Command {
34
- UsageLine : "go build [-o output] [-i] [ build flags] [packages]" ,
34
+ UsageLine : "go build [-o output] [build flags] [packages]" ,
35
35
Short : "compile packages and dependencies" ,
36
36
Long : `
37
37
Build compiles the packages named by the import paths,
@@ -59,6 +59,7 @@ ends with a slash or backslash, then any resulting executables
59
59
will be written to that directory.
60
60
61
61
The -i flag installs the packages that are dependencies of the target.
62
+ The -i flag is deprecated. Compiled packages are cached automatically.
62
63
63
64
The build flags are shared by the build, clean, get, install, list, run,
64
65
and test commands:
@@ -381,6 +382,7 @@ func runBuild(ctx context.Context, cmd *base.Command, args []string) {
381
382
depMode := ModeBuild
382
383
if cfg .BuildI {
383
384
depMode = ModeInstall
385
+ fmt .Fprint (os .Stderr , "go build: -i flag is deprecated\n " )
384
386
}
385
387
386
388
pkgs = omitTestOnly (pkgsFilter (load .Packages (ctx , args )))
@@ -444,7 +446,7 @@ func runBuild(ctx context.Context, cmd *base.Command, args []string) {
444
446
}
445
447
446
448
var CmdInstall = & base.Command {
447
- UsageLine : "go install [-i] [ build flags] [packages]" ,
449
+ UsageLine : "go install [build flags] [packages]" ,
448
450
Short : "compile and install packages and dependencies" ,
449
451
Long : `
450
452
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,
486
488
other packages are built and cached but not installed.
487
489
488
490
The -i flag installs the dependencies of the named packages as well.
491
+ The -i flag is deprecated. Compiled packages are cached automatically.
489
492
490
493
For more about the build flags, see 'go help build'.
491
494
For more about specifying packages, see 'go help packages'.
@@ -551,14 +554,35 @@ func libname(args []string, pkgs []*load.Package) (string, error) {
551
554
}
552
555
553
556
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.
554
562
for _ , arg := range args {
555
563
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
+ }
556
567
installOutsideModule (ctx , args )
557
568
return
558
569
}
559
570
}
560
571
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 )
562
586
}
563
587
564
588
// omitTestOnly returns pkgs with test-only packages removed.
0 commit comments