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