diff options
Diffstat (limited to 'src/cmd/go/list.go')
-rw-r--r-- | src/cmd/go/list.go | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/src/cmd/go/list.go b/src/cmd/go/list.go index f56ebed38..0ead43502 100644 --- a/src/cmd/go/list.go +++ b/src/cmd/go/list.go @@ -14,7 +14,7 @@ import ( ) var cmdList = &Command{ - UsageLine: "list [-e] [-race] [-f format] [-json] [-tags 'tag list'] [packages]", + UsageLine: "list [-e] [-f format] [-json] [build flags] [packages]", Short: "list packages", Long: ` List lists the packages named by the import paths, one per line. @@ -27,8 +27,7 @@ The default output shows the package import path: The -f flag specifies an alternate format for the list, using the syntax of package template. The default output is equivalent to -f -'{{.ImportPath}}'. One extra template function is available, "join", -which calls strings.Join. The struct being passed to the template is: +'{{.ImportPath}}'. The struct being passed to the template is: type Package struct { Dir string // directory containing package sources @@ -47,6 +46,7 @@ which calls strings.Join. The struct being passed to the template is: IgnoredGoFiles []string // .go sources ignored due to build constraints CFiles []string // .c source files CXXFiles []string // .cc, .cxx and .cpp source files + MFiles []string // .m source files HFiles []string // .h, .hh, .hpp and .hxx source files SFiles []string // .s source files SwigFiles []string // .swig files @@ -75,6 +75,26 @@ which calls strings.Join. The struct being passed to the template is: XTestImports []string // imports from XTestGoFiles } +The template function "join" calls strings.Join. + +The template function "context" returns the build context, defined as: + + type Context struct { + GOARCH string // target architecture + GOOS string // target operating system + GOROOT string // Go root + GOPATH string // Go path + CgoEnabled bool // whether cgo can be used + UseAllFiles bool // use files regardless of +build lines, file names + Compiler string // compiler to assume when computing target paths + BuildTags []string // build constraints to match in +build lines + ReleaseTags []string // releases the current release is compatible with + InstallSuffix string // suffix to use in the name of the install dir + } + +For more information about the meaning of these fields see the documentation +for the go/build package's Context type. + The -json flag causes the package data to be printed in JSON format instead of using the template format. @@ -88,11 +108,7 @@ printing. Erroneous packages will have a non-empty ImportPath and a non-nil Error field; other information may or may not be missing (zeroed). -The -tags flag specifies a list of build tags, like in the 'go build' -command. - -The -race flag causes the package data to include the dependencies -required by the race detector. +For more about build flags, see 'go help build'. For more about specifying packages, see 'go help packages'. `, @@ -100,24 +116,18 @@ For more about specifying packages, see 'go help packages'. func init() { cmdList.Run = runList // break init cycle - cmdList.Flag.Var(buildCompiler{}, "compiler", "") - cmdList.Flag.Var((*stringsFlag)(&buildContext.BuildTags), "tags", "") + addBuildFlags(cmdList) } var listE = cmdList.Flag.Bool("e", false, "") var listFmt = cmdList.Flag.String("f", "{{.ImportPath}}", "") var listJson = cmdList.Flag.Bool("json", false, "") -var listRace = cmdList.Flag.Bool("race", false, "") var nl = []byte{'\n'} func runList(cmd *Command, args []string) { out := newTrackingWriter(os.Stdout) defer out.w.Flush() - if *listRace { - buildRace = true - } - var do func(*Package) if *listJson { do = func(p *Package) { @@ -130,7 +140,18 @@ func runList(cmd *Command, args []string) { out.Write(nl) } } else { - tmpl, err := template.New("main").Funcs(template.FuncMap{"join": strings.Join}).Parse(*listFmt) + var cachedCtxt *Context + context := func() *Context { + if cachedCtxt == nil { + cachedCtxt = newContext(&buildContext) + } + return cachedCtxt + } + fm := template.FuncMap{ + "join": strings.Join, + "context": context, + } + tmpl, err := template.New("main").Funcs(fm).Parse(*listFmt) if err != nil { fatalf("%s", err) } @@ -140,7 +161,7 @@ func runList(cmd *Command, args []string) { fatalf("%s", err) } if out.NeedNL() { - out.Write([]byte{'\n'}) + out.Write(nl) } } } |