)
var cmdBuild = &Command{
- UsageLine: "build [-o output] [build flags] [packages]",
+ UsageLine: "build [-o output] [-i] [build flags] [packages]",
Short: "compile packages and dependencies",
Long: `
Build compiles the packages named by the import paths,
f1.go f2.go'; with no files provided ('go build'), the output file
name is the base name of the containing directory.
+The -i flag installs the packages that are dependencies of the target.
+
The build flags are shared by the build, install, run, and test commands:
-a
cmdBuild.Run = runBuild
cmdInstall.Run = runInstall
+ cmdBuild.Flag.BoolVar(&buildI, "i", false, "")
+
addBuildFlags(cmdBuild)
addBuildFlags(cmdInstall)
}
var buildP = runtime.NumCPU() // -p flag
var buildV bool // -v flag
var buildX bool // -x flag
+var buildI bool // -i flag
var buildO = cmdBuild.Flag.String("o", "", "output file")
var buildWork bool // -work flag
var buildGcflags []string // -gcflags flag
}
a := &action{}
+ depMode := modeBuild
+ if buildI {
+ depMode = modeInstall
+ }
for _, p := range packages(args) {
- a.deps = append(a.deps, b.action(modeBuild, modeBuild, p))
+ a.deps = append(a.deps, b.action(modeBuild, depMode, p))
}
b.do(a)
}
fi
unset GOPATH
+TEST list template can use context function
+if ! ./testgo list -f "GOARCH: {{context.GOARCH}}"; then
+ echo unable to use context in list template
+ ok=false
+fi
+
+TEST build -i installs dependencies
+d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
+export GOPATH=$d
+mkdir -p $d/src/x/y/foo $d/src/x/y/bar
+echo '
+package foo
+func F() {}
+' >$d/src/x/y/foo/foo.go
+echo '
+package bar
+import "x/y/foo"
+func F() { foo.F() }
+' >$d/src/x/y/bar/bar.go
+if ! ./testgo build -v -i x/y/bar &> $d/err; then
+ echo build -i failed
+ cat $d/err
+ ok=false
+elif ! grep x/y/foo $d/err >/dev/null; then
+ echo first build -i did not build x/y/foo
+ cat $d/err
+ ok=false
+fi
+if ! ./testgo build -v -i x/y/bar &> $d/err; then
+ echo second build -i failed
+ cat $d/err
+ ok=false
+elif grep x/y/foo $d/err >/dev/null; then
+ echo second build -i built x/y/foo
+ cat $d/err
+ ok=false
+fi
+rm -rf $d
+unset GOPATH
+
# clean up
if $started; then stop; fi
rm -rf testdata/bin testdata/bin1
testCoverPkgs []*Package // -coverpkg flag
testProfile bool // some profiling flag
testNeedBinary bool // profile needs to keep binary around
- testI bool // -i flag
testV bool // -v flag
testFiles []string // -file flag(s) TODO: not respected
testTimeout string // -timeout flag
var b builder
b.init()
- if testI {
+ if buildI {
buildV = testV
deps := make(map[string]bool)
// local.
{name: "c", boolVar: &testC},
{name: "file", multiOK: true},
- {name: "i", boolVar: &testI},
{name: "cover", boolVar: &testCover},
{name: "coverpkg"},
{name: "n", boolVar: &buildN},
{name: "p"},
{name: "x", boolVar: &buildX},
+ {name: "i", boolVar: &buildI},
{name: "work", boolVar: &buildWork},
{name: "ccflags"},
{name: "gcflags"},