github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/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 As a special case, if the package list is a list of .go files from a 83 single directory, the command is applied to a single synthesized 84 package made up of exactly those files, ignoring any build constraints 85 in those files and ignoring any other files in the directory. 86 87 Directory and file names that begin with "." or "_" are ignored 88 by the go tool, as are directories named "testdata". 89 `, 90 } 91 92 var helpImportPath = &Command{ 93 UsageLine: "importpath", 94 Short: "import path syntax", 95 Long: ` 96 97 An import path (see 'go help packages') denotes a package 98 stored in the local file system. In general, an import path denotes 99 either a standard package (such as "unicode/utf8") or a package 100 found in one of the work spaces (see 'go help gopath'). 101 102 Relative import paths 103 104 An import path beginning with ./ or ../ is called a relative path. 105 The toolchain supports relative import paths as a shortcut in two ways. 106 107 First, a relative path can be used as a shorthand on the command line. 108 If you are working in the directory containing the code imported as 109 "unicode" and want to run the tests for "unicode/utf8", you can type 110 "go test ./utf8" instead of needing to specify the full path. 111 Similarly, in the reverse situation, "go test .." will test "unicode" from 112 the "unicode/utf8" directory. Relative patterns are also allowed, like 113 "go test ./..." to test all subdirectories. See 'go help packages' for details 114 on the pattern syntax. 115 116 Second, if you are compiling a Go program not in a work space, 117 you can use a relative path in an import statement in that program 118 to refer to nearby code also not in a work space. 119 This makes it easy to experiment with small multipackage programs 120 outside of the usual work spaces, but such programs cannot be 121 installed with "go install" (there is no work space in which to install them), 122 so they are rebuilt from scratch each time they are built. 123 To avoid ambiguity, Go programs cannot use relative import paths 124 within a work space. 125 126 Remote import paths 127 128 Certain import paths also 129 describe how to obtain the source code for the package using 130 a revision control system. 131 132 A few common code hosting sites have special syntax: 133 134 Bitbucket (Git, Mercurial) 135 136 import "bitbucket.org/user/project" 137 import "bitbucket.org/user/project/sub/directory" 138 139 GitHub (Git) 140 141 import "github.com/user/project" 142 import "github.com/user/project/sub/directory" 143 144 Google Code Project Hosting (Git, Mercurial, Subversion) 145 146 import "code.google.com/p/project" 147 import "code.google.com/p/project/sub/directory" 148 149 import "code.google.com/p/project.subrepository" 150 import "code.google.com/p/project.subrepository/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 If the vendoring experiment is enabled (see 'go help gopath'), 265 then import path checking is disabled for code found within vendor trees. 266 This makes it possible to copy code into alternate locations in vendor trees 267 without needing to update import comments. 268 269 See https://golang.org/s/go14customimport for details. 270 `, 271 } 272 273 var helpGopath = &Command{ 274 UsageLine: "gopath", 275 Short: "GOPATH environment variable", 276 Long: ` 277 The Go path is used to resolve import statements. 278 It is implemented by and documented in the go/build package. 279 280 The GOPATH environment variable lists places to look for Go code. 281 On Unix, the value is a colon-separated string. 282 On Windows, the value is a semicolon-separated string. 283 On Plan 9, the value is a list. 284 285 GOPATH must be set to get, build and install packages outside the 286 standard Go tree. 287 288 Each directory listed in GOPATH must have a prescribed structure: 289 290 The src directory holds source code. The path below src 291 determines the import path or executable name. 292 293 The pkg directory holds installed package objects. 294 As in the Go tree, each target operating system and 295 architecture pair has its own subdirectory of pkg 296 (pkg/GOOS_GOARCH). 297 298 If DIR is a directory listed in the GOPATH, a package with 299 source in DIR/src/foo/bar can be imported as "foo/bar" and 300 has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a". 301 302 The bin directory holds compiled commands. 303 Each command is named for its source directory, but only 304 the final element, not the entire path. That is, the 305 command with source in DIR/src/foo/quux is installed into 306 DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped 307 so that you can add DIR/bin to your PATH to get at the 308 installed commands. If the GOBIN environment variable is 309 set, commands are installed to the directory it names instead 310 of DIR/bin. GOBIN must be an absolute path. 311 312 Here's an example directory layout: 313 314 GOPATH=/home/user/gocode 315 316 /home/user/gocode/ 317 src/ 318 foo/ 319 bar/ (go code in package bar) 320 x.go 321 quux/ (go code in package main) 322 y.go 323 bin/ 324 quux (installed command) 325 pkg/ 326 linux_amd64/ 327 foo/ 328 bar.a (installed package object) 329 330 Go searches each directory listed in GOPATH to find source code, 331 but new packages are always downloaded into the first directory 332 in the list. 333 334 See https://golang.org/doc/code.html for an example. 335 336 Internal Directories 337 338 Code in or below a directory named "internal" is importable only 339 by code in the directory tree rooted at the parent of "internal". 340 Here's an extended version of the directory layout above: 341 342 /home/user/gocode/ 343 src/ 344 crash/ 345 bang/ (go code in package bang) 346 b.go 347 foo/ (go code in package foo) 348 f.go 349 bar/ (go code in package bar) 350 x.go 351 internal/ 352 baz/ (go code in package baz) 353 z.go 354 quux/ (go code in package main) 355 y.go 356 357 358 The code in z.go is imported as "foo/internal/baz", but that 359 import statement can only appear in source files in the subtree 360 rooted at foo. The source files foo/f.go, foo/bar/x.go, and 361 foo/quux/y.go can all import "foo/internal/baz", but the source file 362 crash/bang/b.go cannot. 363 364 See https://golang.org/s/go14internal for details. 365 366 Vendor Directories 367 368 Go 1.6 includes support for using local copies of external dependencies 369 to satisfy imports of those dependencies, often referred to as vendoring. 370 371 Code below a directory named "vendor" is importable only 372 by code in the directory tree rooted at the parent of "vendor", 373 and only using an import path that omits the prefix up to and 374 including the vendor element. 375 376 Here's the example from the previous section, 377 but with the "internal" directory renamed to "vendor" 378 and a new foo/vendor/crash/bang directory added: 379 380 /home/user/gocode/ 381 src/ 382 crash/ 383 bang/ (go code in package bang) 384 b.go 385 foo/ (go code in package foo) 386 f.go 387 bar/ (go code in package bar) 388 x.go 389 vendor/ 390 crash/ 391 bang/ (go code in package bang) 392 b.go 393 baz/ (go code in package baz) 394 z.go 395 quux/ (go code in package main) 396 y.go 397 398 The same visibility rules apply as for internal, but the code 399 in z.go is imported as "baz", not as "foo/vendor/baz". 400 401 Code in vendor directories deeper in the source tree shadows 402 code in higher directories. Within the subtree rooted at foo, an import 403 of "crash/bang" resolves to "foo/vendor/crash/bang", not the 404 top-level "crash/bang". 405 406 Code in vendor directories is not subject to import path 407 checking (see 'go help importpath'). 408 409 When 'go get' checks out or updates a git repository, it now also 410 updates submodules. 411 412 Vendor directories do not affect the placement of new repositories 413 being checked out for the first time by 'go get': those are always 414 placed in the main GOPATH, never in a vendor subtree. 415 416 In Go 1.5, as an experiment, setting the environment variable 417 GO15VENDOREXPERIMENT=1 enabled these features. 418 As of Go 1.6 they are on by default. To turn them off, set 419 GO15VENDOREXPERIMENT=0. In Go 1.7, the environment 420 variable will stop having any effect. 421 422 The vendoring semantics are an experiment, and they may change 423 in future releases. Once settled, they will be on by default. 424 425 See https://golang.org/s/go15vendor for details. 426 `, 427 } 428 429 var helpEnvironment = &Command{ 430 UsageLine: "environment", 431 Short: "environment variables", 432 Long: ` 433 434 The go command, and the tools it invokes, examine a few different 435 environment variables. For many of these, you can see the default 436 value of on your system by running 'go env NAME', where NAME is the 437 name of the variable. 438 439 General-purpose environment variables: 440 441 GCCGO 442 The gccgo command to run for 'go build -compiler=gccgo'. 443 GOARCH 444 The architecture, or processor, for which to compile code. 445 Examples are amd64, 386, arm, ppc64. 446 GOBIN 447 The directory where 'go install' will install a command. 448 GOOS 449 The operating system for which to compile code. 450 Examples are linux, darwin, windows, netbsd. 451 GOPATH 452 See 'go help gopath'. 453 GORACE 454 Options for the race detector. 455 See https://golang.org/doc/articles/race_detector.html. 456 GOROOT 457 The root of the go tree. 458 459 Environment variables for use with cgo: 460 461 CC 462 The command to use to compile C code. 463 CGO_ENABLED 464 Whether the cgo command is supported. Either 0 or 1. 465 CGO_CFLAGS 466 Flags that cgo will pass to the compiler when compiling 467 C code. 468 CGO_CPPFLAGS 469 Flags that cgo will pass to the compiler when compiling 470 C or C++ code. 471 CGO_CXXFLAGS 472 Flags that cgo will pass to the compiler when compiling 473 C++ code. 474 CGO_LDFLAGS 475 Flags that cgo will pass to the compiler when linking. 476 CXX 477 The command to use to compile C++ code. 478 479 Architecture-specific environment variables: 480 481 GOARM 482 For GOARCH=arm, the ARM architecture for which to compile. 483 Valid values are 5, 6, 7. 484 GO386 485 For GOARCH=386, the floating point instruction set. 486 Valid values are 387, sse2. 487 488 Special-purpose environment variables: 489 490 GOROOT_FINAL 491 The root of the installed Go tree, when it is 492 installed in a location other than where it is built. 493 File names in stack traces are rewritten from GOROOT to 494 GOROOT_FINAL. 495 GO15VENDOREXPERIMENT 496 Set to 1 to enable the Go 1.5 vendoring experiment. 497 GO_EXTLINK_ENABLED 498 Whether the linker should use external linking mode 499 when using -linkmode=auto with code that uses cgo. 500 Set to 0 to disable external linking mode, 1 to enable it. 501 `, 502 } 503 504 var helpFileType = &Command{ 505 UsageLine: "filetype", 506 Short: "file types", 507 Long: ` 508 The go command examines the contents of a restricted set of files 509 in each directory. It identifies which files to examine based on 510 the extension of the file name. These extensions are: 511 512 .go 513 Go source files. 514 .c, .h 515 C source files. 516 If the package uses cgo or SWIG, these will be compiled with the 517 OS-native compiler (typically gcc); otherwise they will 518 trigger an error. 519 .cc, .cpp, .cxx, .hh, .hpp, .hxx 520 C++ source files. Only useful with cgo or SWIG, and always 521 compiled with the OS-native compiler. 522 .m 523 Objective-C source files. Only useful with cgo, and always 524 compiled with the OS-native compiler. 525 .s, .S 526 Assembler source files. 527 If the package uses cgo or SWIG, these will be assembled with the 528 OS-native assembler (typically gcc (sic)); otherwise they 529 will be assembled with the Go assembler. 530 .swig, .swigcxx 531 SWIG definition files. 532 .syso 533 System object files. 534 535 Files of each of these types except .syso may contain build 536 constraints, but the go command stops scanning for build constraints 537 at the first item in the file that is not a blank line or //-style 538 line comment. 539 `, 540 } 541 542 var helpBuildmode = &Command{ 543 UsageLine: "buildmode", 544 Short: "description of build modes", 545 Long: ` 546 The 'go build' and 'go install' commands take a -buildmode argument which 547 indicates which kind of object file is to be built. Currently supported values 548 are: 549 550 -buildmode=archive 551 Build the listed non-main packages into .a files. Packages named 552 main are ignored. 553 554 -buildmode=c-archive 555 Build the listed main package, plus all packages it imports, 556 into a C archive file. The only callable symbols will be those 557 functions exported using a cgo //export comment. Requires 558 exactly one main package to be listed. 559 560 -buildmode=c-shared 561 Build the listed main packages, plus all packages that they 562 import, into C shared libraries. The only callable symbols will 563 be those functions exported using a cgo //export comment. 564 Non-main packages are ignored. 565 566 -buildmode=default 567 Listed main packages are built into executables and listed 568 non-main packages are built into .a files (the default 569 behavior). 570 571 -buildmode=shared 572 Combine all the listed non-main packages into a single shared 573 library that will be used when building with the -linkshared 574 option. Packages named main are ignored. 575 576 -buildmode=exe 577 Build the listed main packages and everything they import into 578 executables. Packages not named main are ignored. 579 580 -buildmode=pie 581 Build the listed main packages and everything they import into 582 position independent executables (PIE). Packages not named 583 main are ignored. 584 `, 585 }