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