golang|Go编译处理过程(一)go工具

首先我们要知道golang自带了哪些工具

Go is a tool for managing Go source code.Usage:go [arguments]The commands are:bugstart a bug report buildcompile packages and dependencies cleanremove object files and cached files docshow documentation for package or symbol envprint Go environment information fixupdate packages to use new APIs fmtgofmt (reformat) package sources generategenerate Go files by processing source getadd dependencies to current module and install them installcompile and install packages and dependencies listlist packages or modules modmodule maintenance workworkspace maintenance runcompile and run Go program testtest packages toolrun specified go tool versionprint Go version vetreport likely mistakes in packagesUse "go help " for more information about a command.Additional help topics:buildconstraint build constraints buildmodebuild modes ccalling between Go and C cachebuild and test caching environmentenvironment variables filetypefile types go.modthe go.mod file gopathGOPATH environment variable gopath-getlegacy GOPATH go get goproxymodule proxy protocol importpathimport path syntax modulesmodules, module versions, and more module-getmodule-aware go get module-authmodule authentication using go.sum packagespackage lists and patterns privateconfiguration for downloading non-public code testflagtesting flags testfunctesting functions vcscontrolling version control with GOVCSUse "go help " for more information about that topic.

go的这些工具也是由golang来实现的,其源码位于src/cmd/,经过编译后,每一个工具都是一个可执行文件,位于pkg/tool/windows_amd64。我发现go列出的这些commands有些在cmd目录下有些又不在,对于没有列出来的命令我们可以使用go tool xxx来调用。
【golang|Go编译处理过程(一)go工具】golang|Go编译处理过程(一)go工具
文章图片

我们上面调用的go命令的源码在src/cmd/go/main.go
func init() { base.Go.Commands = []*base.Command{ bug.CmdBug, work.CmdBuild, clean.CmdClean, doc.CmdDoc, envcmd.CmdEnv, fix.CmdFix, fmtcmd.CmdFmt, generate.CmdGenerate, modget.CmdGet, work.CmdInstall, list.CmdList, modcmd.CmdMod, workcmd.CmdWork, run.CmdRun, test.CmdTest, tool.CmdTool, version.CmdVersion, vet.CmdVet,help.HelpBuildConstraint, help.HelpBuildmode, help.HelpC, help.HelpCache, help.HelpEnvironment, help.HelpFileType, modload.HelpGoMod, help.HelpGopath, get.HelpGopathGet, modfetch.HelpGoproxy, help.HelpImportPath, modload.HelpModules, modget.HelpModuleGet, modfetch.HelpModuleAuth, help.HelpPackages, modfetch.HelpPrivate, test.HelpTestflag, test.HelpTestfunc, modget.HelpVCS, } }

这些命令位于src/cmd/go/internal/目录下

    推荐阅读