github.com/euank/go@v0.0.0-20160829210321-495514729181/src/cmd/go/help.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 var helpC = &Command{ 8 UsageLine: "c", 9 Short: "calling between Go and C", 10 Long: ` 11 There are two different ways to call between Go and C/C++ code. 12 13 The first is the cgo tool, which is part of the Go distribution. For 14 information on how to use it see the cgo documentation (go doc cmd/cgo). 15 16 The second is the SWIG program, which is a general tool for 17 interfacing between languages. For information on SWIG see 18 http://swig.org/. When running go build, any file with a .swig 19 extension will be passed to SWIG. Any file with a .swigcxx extension 20 will be passed to SWIG with the -c++ option. 21 22 When either cgo or SWIG is used, go build will pass any .c, .m, .s, 23 or .S files to the C compiler, and any .cc, .cpp, .cxx files to the C++ 24 compiler. The CC or CXX environment variables may be set to determine 25 the C or C++ compiler, respectively, to use. 26 `, 27 } 28 29 var helpPackages = &Command{ 30 UsageLine: "packages", 31 Short: "description of package lists", 32 Long: ` 33 Many commands apply to a set of packages: 34 35 go action [packages] 36 37 Usually, [packages] is a list of import paths. 38 39 An import path that is a rooted path or that begins with 40 a . or .. element is interpreted as a file system path and 41 denotes the package in that directory. 42 43 Otherwise, the import path P denotes the package found in 44 the directory DIR/src/P for some DIR listed in the GOPATH 45 environment variable (see 'go help gopath'). 46 47 If no import paths are given, the action applies to the 48 package in the current directory. 49 50 There are four reserved names for paths that should not be used 51 for packages to be built with the go tool: 52 53 - "main" denotes the top-level package in a stand-alone executable. 54 55 - "all" expands to all package directories found in all the GOPATH 56 trees. For example, 'go list all' lists all the packages on the local 57 system. 58 59 - "std" is like all but expands to just the packages in the standard 60 Go library. 61 62 - "cmd" expands to the Go repository's commands and their 63 internal libraries. 64 65 An import path is a pattern if it includes one or more "..." wildcards, 66 each of which can match any string, including the empty string and 67 strings containing slashes. Such a pattern expands to all package 68 directories found in the GOPATH trees with names matching the 69 patterns. As a special case, x/... matches x as well as x's subdirectories. 70 For example, net/... expands to net and packages in its subdirectories. 71 72 An import path can also name a package to be downloaded from 73 a remote repository. Run 'go help importpath' for details. 74 75 Every package in a program must have a unique import path. 76 By convention, this is arranged by starting each path with a 77 unique prefix that belongs to you. For example, paths used 78 internally at Google all begin with 'google', and paths 79 denoting remote repositories begin with the path to the code, 80 such as 'github.com/user/repo'. 81 82 Packages in a program need not have unique package names, 83 but there are two reserved package names with special meaning. 84 The name main indicates a command, not a library. 85 Commands are built into binaries and cannot be imported. 86 The name documentation indicates documentation for 87 a non-Go program in the directory. Files in package documentation 88 are ignored by the go command. 89 90 As a special case, if the package list is a list of .go files from a 91 single directory, the command is applied to a single synthesized 92 package made up of exactly those files, ignoring any build constraints 93 in those files and ignoring any other files in the directory. 94 95 Directory and file names that begin with "." or "_" are ignored 96 by the go tool, as are directories named "testdata". 97 `, 98 } 99 100 var helpImportPath = &Command{ 101 UsageLine: "importpath", 102 Short: "import path syntax", 103 Long: ` 104 105 An import path (see 'go help packages') denotes a package 106 stored in the local file system. In general, an import path denotes 107 either a standard package (such as "unicode/utf8") or a package 108 found in one of the work spaces (see 'go help gopath'). 109 110 Relative import paths 111 112 An import path beginning with ./ or ../ is called a relative path. 113 The toolchain supports relative import paths as a shortcut in two ways. 114 115 First, a relative path can be used as a shorthand on the command line. 116 If you are working in the directory containing the code imported as 117 "unicode" and want to run the tests for "unicode/utf8", you can type 118 "go test ./utf8" instead of needing to specify the full path. 119 Similarly, in the reverse situation, "go test .." will test "unicode" from 120 the "unicode/utf8" directory. Relative patterns are also allowed, like 121 "go test ./..." to test all subdirectories. See 'go help packages' for details 122 on the pattern syntax. 123 124 Second, if you are compiling a Go program not in a work space, 125 you can use a relative path in an import statement in that program 126 to refer to nearby code also not in a work space. 127 This makes it easy to experiment with small multipackage programs 128 outside of the usual work spaces, but such programs cannot be 129 installed with "go install" (there is no work space in which to install them), 130 so they are rebuilt from scratch each time they are built. 131 To avoid ambiguity, Go programs cannot use relative import paths 132 within a work space. 133 134 Remote import paths 135 136 Certain import paths also 137 describe how to obtain the source code for the package using 138 a revision control system. 139 140 A few common code hosting sites have special syntax: 141 142 Bitbucket (Git, Mercurial) 143 144 import "bitbucket.org/user/project" 145 import "bitbucket.org/user/project/sub/directory" 146 147 GitHub (Git) 148 149 import "github.com/user/project" 150 import "github.com/user/project/sub/directory" 151 152 Launchpad (Bazaar) 153 154 import "launchpad.net/project" 155 import "launchpad.net/project/series" 156 import "launchpad.net/project/series/sub/directory" 157 158 import "launchpad.net/~user/project/branch" 159 import "launchpad.net/~user/project/branch/sub/directory" 160 161 IBM DevOps Services (Git) 162 163 import "hub.jazz.net/git/user/project" 164 import "hub.jazz.net/git/user/project/sub/directory" 165 166 For code hosted on other servers, import paths may either be qualified 167 with the version control type, or the go tool can dynamically fetch 168 the import path over https/http and discover where the code resides 169 from a <meta> tag in the HTML. 170 171 To declare the code location, an import path of the form 172 173 repository.vcs/path 174 175 specifies the given repository, with or without the .vcs suffix, 176 using the named version control system, and then the path inside 177 that repository. The supported version control systems are: 178 179 Bazaar .bzr 180 Git .git 181 Mercurial .hg 182 Subversion .svn 183 184 For example, 185 186 import "example.org/user/foo.hg" 187 188 denotes the root directory of the Mercurial repository at 189 example.org/user/foo or foo.hg, and 190 191 import "example.org/repo.git/foo/bar" 192 193 denotes the foo/bar directory of the Git repository at 194 example.org/repo or repo.git. 195 196 When a version control system supports multiple protocols, 197 each is tried in turn when downloading. For example, a Git 198 download tries https://, then git+ssh://. 199 200 If the import path is not a known code hosting site and also lacks a 201 version control qualifier, the go tool attempts to fetch the import 202 over https/http and looks for a <meta> tag in the document's HTML 203 <head>. 204 205 The meta tag has the form: 206 207 <meta name="go-import" content="import-prefix vcs repo-root"> 208 209 The import-prefix is the import path corresponding to the repository 210 root. It must be a prefix or an exact match of the package being 211 fetched with "go get". If it's not an exact match, another http 212 request is made at the prefix to verify the <meta> tags match. 213 214 The meta tag should appear as early in the file as possible. 215 In particular, it should appear before any raw JavaScript or CSS, 216 to avoid confusing the go command's restricted parser. 217 218 The vcs is one of "git", "hg", "svn", etc, 219 220 The repo-root is the root of the version control system 221 containing a scheme and not containing a .vcs qualifier. 222 223 For example, 224 225 import "example.org/pkg/foo" 226 227 will result in the following requests: 228 229 https://example.org/pkg/foo?go-get=1 (preferred) 230 http://example.org/pkg/foo?go-get=1 (fallback, only with -insecure) 231 232 If that page contains the meta tag 233 234 <meta name="go-import" content="example.org git https://code.org/r/p/exproj"> 235 236 the go tool will verify that https://example.org/?go-get=1 contains the 237 same meta tag and then git clone https://code.org/r/p/exproj into 238 GOPATH/src/example.org. 239 240 New downloaded packages are written to the first directory 241 listed in the GOPATH environment variable (see 'go help gopath'). 242 243 The go command attempts to download the version of the 244 package appropriate for the Go release being used. 245 Run 'go help get' for more. 246 247 Import path checking 248 249 When the custom import path feature described above redirects to a 250 known code hosting site, each of the resulting packages has two possible 251 import paths, using the custom domain or the known hosting site. 252 253 A package statement is said to have an "import comment" if it is immediately 254 followed (before the next newline) by a comment of one of these two forms: 255 256 package math // import "path" 257 package math /* import "path" */ 258 259 The go command will refuse to install a package with an import comment 260 unless it is being referred to by that import path. In this way, import comments 261 let package authors make sure the custom import path is used and not a 262 direct path to the underlying code hosting site. 263 264 Import path checking is disabled for code found within vendor trees. 265 This makes it possible to copy code into alternate locations in vendor trees 266 without needing to update import comments. 267 268 See https://golang.org/s/go14customimport for details. 269 `, 270 } 271 272 var helpGopath = &Command{ 273 UsageLine: "gopath", 274 Short: "GOPATH environment variable", 275 Long: ` 276 The Go path is used to resolve import statements. 277 It is implemented by and documented in the go/build package. 278 279 The GOPATH environment variable lists places to look for Go code. 280 On Unix, the value is a colon-separated string. 281 On Windows, the value is a semicolon-separated string. 282 On Plan 9, the value is a list. 283 284 GOPATH must be set to get, build and install packages outside the 285 standard Go tree. 286 287 Each directory listed in GOPATH must have a prescribed structure: 288 289 The src directory holds source code. The path below src 290 determines the import path or executable name. 291 292 The pkg directory holds installed package objects. 293 As in the Go tree, each target operating system and 294 architecture pair has its own subdirectory of pkg 295 (pkg/GOOS_GOARCH). 296 297 If DIR is a directory listed in the GOPATH, a package with 298 source in DIR/src/foo/bar can be imported as "foo/bar" and 299 has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a". 300 301 The bin directory holds compiled commands. 302 Each command is named for its source directory, but only 303 the final element, not the entire path. That is, the 304 command with source in DIR/src/foo/quux is installed into 305 DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped 306 so that you can add DIR/bin to your PATH to get at the 307 installed commands. If the GOBIN environment variable is 308 set, commands are installed to the directory it names instead 309 of DIR/bin. GOBIN must be an absolute path. 310 311 Here's an example directory layout: 312 313 GOPATH=/home/user/gocode 314 315 /home/user/gocode/ 316 src/ 317 foo/ 318 bar/ (go code in package bar) 319 x.go 320 quux/ (go code in package main) 321 y.go 322 bin/ 323 quux (installed command) 324 pkg/ 325 linux_amd64/ 326 foo/ 327 bar.a (installed package object) 328 329 Go searches each directory listed in GOPATH to find source code, 330 but new packages are always downloaded into the first directory 331 in the list. 332 333 See https://golang.org/doc/code.html for an example. 334 335 Internal Directories 336 337 Code in or below a directory named "internal" is importable only 338 by code in the directory tree rooted at the parent of "internal". 339 Here's an extended version of the directory layout above: 340 341 /home/user/gocode/ 342 src/ 343 crash/ 344 bang/ (go code in package bang) 345 b.go 346 foo/ (go code in package foo) 347 f.go 348 bar/ (go code in package bar) 349 x.go 350 internal/ 351 baz/ (go code in package baz) 352 z.go 353 quux/ (go code in package main) 354 y.go 355 356 357 The code in z.go is imported as "foo/internal/baz", but that 358 import statement can only appear in source files in the subtree 359 rooted at foo. The source files foo/f.go, foo/bar/x.go, and 360 foo/quux/y.go can all import "foo/internal/baz", but the source file 361 crash/bang/b.go cannot. 362 363 See https://golang.org/s/go14internal for details. 364 365 Vendor Directories 366 367 Go 1.6 includes support for using local copies of external dependencies 368 to satisfy imports of those dependencies, often referred to as vendoring. 369 370 Code below a directory named "vendor" is importable only 371 by code in the directory tree rooted at the parent of "vendor", 372 and only using an import path that omits the prefix up to and 373 including the vendor element. 374 375 Here's the example from the previous section, 376 but with the "internal" directory renamed to "vendor" 377 and a new foo/vendor/crash/bang directory added: 378 379 /home/user/gocode/ 380 src/ 381 crash/ 382 bang/ (go code in package bang) 383 b.go 384 foo/ (go code in package foo) 385 f.go 386 bar/ (go code in package bar) 387 x.go 388 vendor/ 389 crash/ 390 bang/ (go code in package bang) 391 b.go 392 baz/ (go code in package baz) 393 z.go 394 quux/ (go code in package main) 395 y.go 396 397 The same visibility rules apply as for internal, but the code 398 in z.go is imported as "baz", not as "foo/vendor/baz". 399 400 Code in vendor directories deeper in the source tree shadows 401 code in higher directories. Within the subtree rooted at foo, an import 402 of "crash/bang" resolves to "foo/vendor/crash/bang", not the 403 top-level "crash/bang". 404 405 Code in vendor directories is not subject to import path 406 checking (see 'go help importpath'). 407 408 When 'go get' checks out or updates a git repository, it now also 409 updates submodules. 410 411 Vendor directories do not affect the placement of new repositories 412 being checked out for the first time by 'go get': those are always 413 placed in the main GOPATH, never in a vendor subtree. 414 415 See https://golang.org/s/go15vendor for details. 416 `, 417 } 418 419 var helpEnvironment = &Command{ 420 UsageLine: "environment", 421 Short: "environment variables", 422 Long: ` 423 424 The go command, and the tools it invokes, examine a few different 425 environment variables. For many of these, you can see the default 426 value of on your system by running 'go env NAME', where NAME is the 427 name of the variable. 428 429 General-purpose environment variables: 430 431 GCCGO 432 The gccgo command to run for 'go build -compiler=gccgo'. 433 GOARCH 434 The architecture, or processor, for which to compile code. 435 Examples are amd64, 386, arm, ppc64. 436 GOBIN 437 The directory where 'go install' will install a command. 438 GOOS 439 The operating system for which to compile code. 440 Examples are linux, darwin, windows, netbsd. 441 GOPATH 442 See 'go help gopath'. 443 GORACE 444 Options for the race detector. 445 See https://golang.org/doc/articles/race_detector.html. 446 GOROOT 447 The root of the go tree. 448 449 Environment variables for use with cgo: 450 451 CC 452 The command to use to compile C code. 453 CGO_ENABLED 454 Whether the cgo command is supported. Either 0 or 1. 455 CGO_CFLAGS 456 Flags that cgo will pass to the compiler when compiling 457 C code. 458 CGO_CPPFLAGS 459 Flags that cgo will pass to the compiler when compiling 460 C or C++ code. 461 CGO_CXXFLAGS 462 Flags that cgo will pass to the compiler when compiling 463 C++ code. 464 CGO_LDFLAGS 465 Flags that cgo will pass to the compiler when linking. 466 CXX 467 The command to use to compile C++ code. 468 469 Architecture-specific environment variables: 470 471 GOARM 472 For GOARCH=arm, the ARM architecture for which to compile. 473 Valid values are 5, 6, 7. 474 GO386 475 For GOARCH=386, the floating point instruction set. 476 Valid values are 387, sse2. 477 478 Special-purpose environment variables: 479 480 GOROOT_FINAL 481 The root of the installed Go tree, when it is 482 installed in a location other than where it is built. 483 File names in stack traces are rewritten from GOROOT to 484 GOROOT_FINAL. 485 GO_EXTLINK_ENABLED 486 Whether the linker should use external linking mode 487 when using -linkmode=auto with code that uses cgo. 488 Set to 0 to disable external linking mode, 1 to enable it. 489 `, 490 } 491 492 var helpFileType = &Command{ 493 UsageLine: "filetype", 494 Short: "file types", 495 Long: ` 496 The go command examines the contents of a restricted set of files 497 in each directory. It identifies which files to examine based on 498 the extension of the file name. These extensions are: 499 500 .go 501 Go source files. 502 .c, .h 503 C source files. 504 If the package uses cgo or SWIG, these will be compiled with the 505 OS-native compiler (typically gcc); otherwise they will 506 trigger an error. 507 .cc, .cpp, .cxx, .hh, .hpp, .hxx 508 C++ source files. Only useful with cgo or SWIG, and always 509 compiled with the OS-native compiler. 510 .m 511 Objective-C source files. Only useful with cgo, and always 512 compiled with the OS-native compiler. 513 .s, .S 514 Assembler source files. 515 If the package uses cgo or SWIG, these will be assembled with the 516 OS-native assembler (typically gcc (sic)); otherwise they 517 will be assembled with the Go assembler. 518 .swig, .swigcxx 519 SWIG definition files. 520 .syso 521 System object files. 522 523 Files of each of these types except .syso may contain build 524 constraints, but the go command stops scanning for build constraints 525 at the first item in the file that is not a blank line or //-style 526 line comment. See the go/build package documentation for 527 more details. 528 529 Non-test Go source files can also include a //go:binary-only-package 530 comment, indicating that the package sources are included 531 for documentation only and must not be used to build the 532 package binary. This enables distribution of Go packages in 533 their compiled form alone. See the go/build package documentation 534 for more details. 535 `, 536 } 537 538 var helpBuildmode = &Command{ 539 UsageLine: "buildmode", 540 Short: "description of build modes", 541 Long: ` 542 The 'go build' and 'go install' commands take a -buildmode argument which 543 indicates which kind of object file is to be built. Currently supported values 544 are: 545 546 -buildmode=archive 547 Build the listed non-main packages into .a files. Packages named 548 main are ignored. 549 550 -buildmode=c-archive 551 Build the listed main package, plus all packages it imports, 552 into a C archive file. The only callable symbols will be those 553 functions exported using a cgo //export comment. Requires 554 exactly one main package to be listed. 555 556 -buildmode=c-shared 557 Build the listed main packages, plus all packages that they 558 import, into C shared libraries. The only callable symbols will 559 be those functions exported using a cgo //export comment. 560 Non-main packages are ignored. 561 562 -buildmode=default 563 Listed main packages are built into executables and listed 564 non-main packages are built into .a files (the default 565 behavior). 566 567 -buildmode=shared 568 Combine all the listed non-main packages into a single shared 569 library that will be used when building with the -linkshared 570 option. Packages named main are ignored. 571 572 -buildmode=exe 573 Build the listed main packages and everything they import into 574 executables. Packages not named main are ignored. 575 576 -buildmode=pie 577 Build the listed main packages and everything they import into 578 position independent executables (PIE). Packages not named 579 main are ignored. 580 `, 581 }