Documentation
¶
Overview ¶
Package tool simplifies the process of locating, configuring and running binary tools.
Index ¶
- Constants
- type CCompiler
- type ExitError
- type ForwardMode
- type GoTool
- type SwiftCompiler
- type SwiftGoCC
- type Tool
- func (tool *Tool) CombinedOutput(args ...string) (output []byte, exitCode int, err error)
- func (tool *Tool) Command(mode ForwardMode, args ...string) (cmd *exec.Cmd)
- func (tool *Tool) Locate() (err error)
- func (tool *Tool) Output(args ...string) (output []byte, exitCode int, err error)
- func (tool *Tool) Run(args ...string) (exitCode int, err error)
Constants ¶
const ( ForwardInput ForwardMode = 1 << iota ForwardOutput ForwardErrors Forward = ForwardInput | ForwardOutput | ForwardErrors CaptureInput = ForwardOutput | ForwardErrors CaptureOutput = ForwardInput | ForwardErrors CaptureErrors = ForwardInput | ForwardOutput Capture = 0 )
const CCOverrideKey = "__SWIFTGO_PRIVATE_CC"
CCOverrideKey is the environment variable that the end-user may set to override the location of the C compiler.
const GoOverrideKey = "SWIFTGO_GOTOOL"
GoOverrideKey is the environment variable that the end-user may set to override the location of the Go tool.
const SwiftGoCCBuildDirKey = "__SWIFTGO_PRIVATE_BUILDDIR"
SwiftGoCCBuildDirKey is the environment variable that is used internally to pass the global temporary build directory.
const SwiftcFlagsKey = "SWIFTGO_SWIFTFLAGS"
SwiftcFlagsKey is the environment variable that the end-user may set to pass additional flags to the Swift compiler.
const SwiftcOverrideKey = "SWIFTGO_SWIFTC"
SwiftcOverrideKey is the environment variable that the end-user may set to override the location of the Swift compiler.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CCompiler ¶
type CCompiler struct { Tool // IsClang is true if the located compiler appears to be Clang. IsClang bool }
CCompiler holds the path, arguments and configuration of the C compiler.
func LocateCCompiler ¶
LocateCCompiler looks up the binary of the C compiler according to the following heuristics:
- if the __SWIFTGO_PRIVATE_CC environment variable is set, it is parsed as a command followed by a sequence of arguments and used to look up the binary;
- otherwise, LocateCCompiler looks for a binary named 'xcrun' in the directories named by the PATH environment variable and tries to obtain a path by running the command 'xcrun -f clang';
- finally, LocateCCompiler looks for a binary named 'clang' in the directories named by the PATH environment variable.
When the binary is found, the tool.IsClang field is set appropriately.
func (*CCompiler) NakedCommand ¶
func (tool *CCompiler) NakedCommand(mode ForwardMode, args ...string) (cmd *exec.Cmd)
NakedCommand returns a Cmd struct instance configured to execute the compiler with the given arguments, but with no default arguments, i.e. the tool.Args field is ignored. Otherwise, it works exactly as tool.Command.
type ExitError ¶
An ExitError reports an unsuccessful exit by some tool while a Locate* function was gathering information.
type ForwardMode ¶
type ForwardMode int
ForwardMode stores a set of bitwise or-ed flags that determine which streams should be automatically forwarded when running the Go build tool.
type GoTool ¶
type GoTool struct { Tool // Version holds the major, minor version and patch number of the tool binary. Version struct { String string Major int Minor int Patch int } // Env holds the Go environment variables as reported by the 'go env' command. Env map[string]string }
GoTool holds the path, arguments and configuration of the Go build tool.
func LocateGoTool ¶
LocateGoTool looks up the binary of the Go build tool according to the following heuristics:
- if the SWIFTGO_GOTOOL environment variable is set, it is parsed as a command followed by a sequence of arguments and used to look up the binary;
- if the GOROOT variable is set either in the program environment or in the Go environment configuration, LocateGoTool looks up for a binary at '$GOROOT/bin/go';
- otherwise, LocateGoTool looks for a binary named 'go' in the directories named by the PATH environment variable.
When the binary is found, tool.Env is populated with the Go environment as reported by the 'go env' command.
type SwiftCompiler ¶
type SwiftCompiler struct { Tool // Version holds the major, minor version and patch number of the compiler binary. Version struct { String string Major int Minor int Patch int } // LinkerFlags holds the flags that must be passed on to the linker // when linking swift modules compiled with the current configuration. LinkerFlags []string }
SwiftCompiler holds the path, arguments and configuration of the Swift compiler.
func LocateSwiftCompiler ¶
func LocateSwiftCompiler(flags []string) (tool *SwiftCompiler, err error)
LocateSwiftCompiler looks up the binary of the Swift compiler according to the following heuristics:
- if the SWIFTGO_SWIFTC environment variable is set, it is parsed as a command followed by a sequence of arguments and used to look up the binary;
- otherwise, LocateSwiftCompiler looks for a binary named 'xcrun' in the directories named by the PATH environment variable and tries to obtain a path by running the command 'xcrun -f swiftc';
- finally, LocateSwiftCompiler looks for a binary named 'swiftc' in the directories named by the PATH environment variable.
When the binary is found, tool.LinkerFlags is populated with the appropriate linker flags for the current configuration, as specified by the flags parameter.
type SwiftGoCC ¶
type SwiftGoCC struct { Tool // Revision holds the VCS revision from which the binary was compiled. Revision string }
SwiftGoCC holds the path, arguments and configuration of our internal C compiler wrapper.
func LocateSwiftGoCC ¶
LocateSwiftGoCC looks up the binary of our internal C compiler wrapper according to the following heuristics:
- first, LocateSwiftGoCC looks for a binary named 'swiftgocc' in the same directory as the currently running binary;
- if the GOPATH variable is set either in the program environment or in the Go environment configuration, LocateSwiftGoCC looks up for a binary at '$GOPATH/bin/swiftgocc';
- otherwise, LocateSwiftGoCC looks for a binary named 'swiftgocc' in the directories named by the PATH environment variable.
When the binary is found, the tool.Revision field is set appropriately.
type Tool ¶
type Tool struct { // Desc is a user-readable description of the tool to be used in error messages. Desc string // Hint is the path that was used to look up the tool binary. Hint string // Path is the absolute path to the tool binary. Path string // Args holds command line argument that must be passed on whenever the tool is invoked. Args []string }
Tool holds the path, arguments and configuration of a binary tool.
func (*Tool) CombinedOutput ¶
CombinedOutput runs the Go tool with the given arguments and returns its combined output and error streams as well as the exit code. No error is returned when the invocation succeded with non-zero exit code. The input stream is forwarded to os.Stdin.
func (*Tool) Command ¶
func (tool *Tool) Command(mode ForwardMode, args ...string) (cmd *exec.Cmd)
Command returns a Cmd struct instance configured to execute the tool with the given arguments. Any argument present in tool.Args is prepended to the given argument list. If the ForwardInput flag is present in the mode argument, the input stream is forwarded to os.Stdin. Similarly, if the ForwardOutput or ForwardErrors flags are present, output and error streams are forwarded respectively to os.Stdout and os.Stderr.
func (*Tool) Locate ¶
Locate looks up the path of the tool binary, if unknown, based on the content of the tool.Hint field.
func (*Tool) Output ¶
Output runs the Go tool with the given arguments and returns its standard output and the exit code. No error is returned when the invocation succeded with non-zero exit code. Input and error streams are forwarded to os.Stdin and os.Stderr.