const DefaultCFlags … // actionList returns the list of actions in the dag rooted at root // as visited in a depth-first post-order traversal. func actionList(root *Action) []*Action { … } // Do runs the action graph rooted at root. func (b *Builder) Do(ctx context.Context, root *Action) { … } // buildActionID computes the action ID for a build action. func (b *Builder) buildActionID(a *Action) cache.ActionID { … } // needCgoHdr reports whether the actions triggered by this one // expect to be able to access the cgo-generated header file. func (b *Builder) needCgoHdr(a *Action) bool { … } // allowedVersion reports whether the version v is an allowed version of go // (one that we can compile). // v is known to be of the form "1.23". func allowedVersion(v string) bool { … } const needBuild … const needCgoHdr … const needVet … const needCompiledGoFiles … const needCovMetaFile … const needStale … // build is the action for building a single package. // Note that any new influence on this logic must be reported in b.buildActionID above as well. func (b *Builder) build(ctx context.Context, a *Action) (err error) { … } func (b *Builder) checkDirectives(a *Action) error { … } func (b *Builder) cacheObjdirFile(a *Action, c cache.Cache, name string) error { … } func (b *Builder) findCachedObjdirFile(a *Action, c cache.Cache, name string) (string, error) { … } func (b *Builder) loadCachedObjdirFile(a *Action, c cache.Cache, name string) error { … } func (b *Builder) cacheCgoHdr(a *Action) { … } func (b *Builder) loadCachedCgoHdr(a *Action) error { … } func (b *Builder) cacheSrcFiles(a *Action, srcfiles []string) { … } func (b *Builder) loadCachedVet(a *Action) error { … } func (b *Builder) loadCachedCompiledGoFiles(a *Action) error { … } type vetConfig … func buildVetConfig(a *Action, srcfiles []string) { … } var VetTool … var VetFlags … var VetExplicit … func (b *Builder) vet(ctx context.Context, a *Action) error { … } // linkActionID computes the action ID for a link action. func (b *Builder) linkActionID(a *Action) cache.ActionID { … } // printLinkerConfig prints the linker config into the hash h, // as part of the computation of a linker-related action ID. func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) { … } // link is the action for linking a single command. // Note that any new influence on this logic must be reported in b.linkActionID above as well. func (b *Builder) link(ctx context.Context, a *Action) (err error) { … } func (b *Builder) writeLinkImportcfg(a *Action, file string) error { … } // PkgconfigCmd returns a pkg-config binary name // defaultPkgConfig is defined in zdefaultcc.go, written by cmd/dist. func (b *Builder) PkgconfigCmd() string { … } // splitPkgConfigOutput parses the pkg-config output into a slice of flags. // This implements the shell quoting semantics described in // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02, // except that it does not support parameter or arithmetic expansion or command // substitution and hard-codes the <blank> delimiters instead of reading them // from LC_LOCALE. func splitPkgConfigOutput(out []byte) ([]string, error) { … } // Calls pkg-config if needed and returns the cflags/ldflags needed to build a's package. func (b *Builder) getPkgConfigFlags(a *Action) (cflags, ldflags []string, err error) { … } func (b *Builder) installShlibname(ctx context.Context, a *Action) error { … } func (b *Builder) linkSharedActionID(a *Action) cache.ActionID { … } func (b *Builder) linkShared(ctx context.Context, a *Action) (err error) { … } // BuildInstallFunc is the action for installing a single package or executable. func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error) { … } var AllowInstall … // cleanup removes a's object dir to keep the amount of // on-disk garbage down in a large build. On an operating system // with aggressive buffering, cleaning incrementally like // this keeps the intermediate objects from hitting the disk. func (b *Builder) cleanup(a *Action) { … } // Install the cgo export header file, if there is one. func (b *Builder) installHeader(ctx context.Context, a *Action) error { … } // cover runs, in effect, // // go tool cover -mode=b.coverMode -var="varName" -o dst.go src.go func (b *Builder) cover(a *Action, dst, src string, varName string) error { … } // cover2 runs, in effect, // // go tool cover -pkgcfg=<config file> -mode=b.coverMode -var="varName" -o <outfiles> <infiles> // // Return value is an updated output files list; in addition to the // regular outputs (instrumented source files) the cover tool also // writes a separate file (appearing first in the list of outputs) // that will contain coverage counters and meta-data. func (b *Builder) cover2(a *Action, infiles, outfiles []string, varName string, mode string) ([]string, error) { … } func (b *Builder) writeCoverPkgInputs(a *Action, pconfigfile string, covoutputsfile string, outfiles []string) error { … } var objectMagic … func isObject(s string) bool { … } // cCompilerEnv returns environment variables to set when running the // C compiler. This is needed to disable escape codes in clang error // messages that confuse tools like cgo. func (b *Builder) cCompilerEnv() []string { … } // mkAbs returns an absolute path corresponding to // evaluating f in the directory dir. // We always pass absolute paths of source files so that // the error messages will include the full path to a file // in need of attention. func mkAbs(dir, f string) string { … } type toolchain … type noToolchain … func noCompiler() error { … } func (noToolchain) compiler() string { … } func (noToolchain) linker() string { … } func (noToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg []byte, symabis string, asmhdr bool, pgoProfile string, gofiles []string) (ofile string, out []byte, err error) { … } func (noToolchain) asm(b *Builder, a *Action, sfiles []string) ([]string, error) { … } func (noToolchain) symabis(b *Builder, a *Action, sfiles []string) (string, error) { … } func (noToolchain) pack(b *Builder, a *Action, afile string, ofiles []string) error { … } func (noToolchain) ld(b *Builder, root *Action, targetPath, importcfg, mainpkg string) error { … } func (noToolchain) ldShared(b *Builder, root *Action, toplevelactions []*Action, targetPath, importcfg string, allactions []*Action) error { … } func (noToolchain) cc(b *Builder, a *Action, ofile, cfile string) error { … } // gcc runs the gcc C compiler to create an object from a single C file. func (b *Builder) gcc(a *Action, workdir, out string, flags []string, cfile string) error { … } // gxx runs the g++ C++ compiler to create an object from a single C++ file. func (b *Builder) gxx(a *Action, workdir, out string, flags []string, cxxfile string) error { … } // gfortran runs the gfortran Fortran compiler to create an object from a single Fortran file. func (b *Builder) gfortran(a *Action, workdir, out string, flags []string, ffile string) error { … } // ccompile runs the given C or C++ compiler and creates an object from a single source file. func (b *Builder) ccompile(a *Action, outfile string, flags []string, file string, compiler []string) error { … } // gccld runs the gcc linker to create an executable from a set of object files. func (b *Builder) gccld(a *Action, objdir, outfile string, flags []string, objs []string) error { … } // GccCmd returns a gcc command line prefix // defaultCC is defined in zdefaultcc.go, written by cmd/dist. func (b *Builder) GccCmd(incdir, workdir string) []string { … } // GxxCmd returns a g++ command line prefix // defaultCXX is defined in zdefaultcc.go, written by cmd/dist. func (b *Builder) GxxCmd(incdir, workdir string) []string { … } // gfortranCmd returns a gfortran command line prefix. func (b *Builder) gfortranCmd(incdir, workdir string) []string { … } // ccExe returns the CC compiler setting without all the extra flags we add implicitly. func (b *Builder) ccExe() []string { … } // cxxExe returns the CXX compiler setting without all the extra flags we add implicitly. func (b *Builder) cxxExe() []string { … } // fcExe returns the FC compiler setting without all the extra flags we add implicitly. func (b *Builder) fcExe() []string { … } // compilerCmd returns a command line prefix for the given environment // variable and using the default command when the variable is empty. func (b *Builder) compilerCmd(compiler []string, incdir, workdir string) []string { … } // gccNoPie returns the flag to use to request non-PIE. On systems // with PIE (position independent executables) enabled by default, // -no-pie must be passed when doing a partial link with -Wl,-r. // But -no-pie is not supported by all compilers, and clang spells it -nopie. func (b *Builder) gccNoPie(linker []string) string { … } // gccSupportsFlag checks to see if the compiler supports a flag. func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool { … } // statString returns a string form of an os.FileInfo, for serializing and comparison. func statString(info os.FileInfo) string { … } // gccCompilerID returns a build cache key for the current gcc, // as identified by running 'compiler'. // The caller can use subkeys of the key. // Other parts of cmd/go can use the id as a hash // of the installed compiler version. func (b *Builder) gccCompilerID(compiler string) (id cache.ActionID, ok bool) { … } // gccArchArgs returns arguments to pass to gcc based on the architecture. func (b *Builder) gccArchArgs() []string { … } // envList returns the value of the given environment variable broken // into fields, using the default value when the variable is empty. // // The environment variable must be quoted correctly for // quoted.Split. This should be done before building // anything, for example, in BuildInit. func envList(key, def string) []string { … } // CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo. func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) { … } func buildFlags(name, defaults string, fromPackage []string, check func(string, string, []string) error) ([]string, error) { … } var cgoRe … func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgofiles, gccfiles, gxxfiles, mfiles, ffiles []string) (outGo, outObj []string, err error) { … } // flagsNotCompatibleWithInternalLinking scans the list of cgo // compiler flags (C/C++/Fortran) looking for flags that might cause // problems if the build in question uses internal linking. The // primary culprits are use of plugins or use of LTO, but we err on // the side of caution, supporting only those flags that are on the // allow-list for safe flags from security perspective. Return is TRUE // if a sensitive flag is found, FALSE otherwise. func flagsNotCompatibleWithInternalLinking(sourceList []string, flagListList [][]string) bool { … } // dynimport creates a Go source file named importGo containing // //go:cgo_import_dynamic directives for each symbol or library // dynamically imported by the object files outObj. // dynOutGo, if not empty, is a new Go file to build as part of the package. // dynOutObj, if not empty, is a new file to add to the generated archive. func (b *Builder) dynimport(a *Action, objdir, importGo, cgoExe string, cflags, cgoLDFLAGS, outObj []string) (dynOutGo, dynOutObj string, err error) { … } // Run SWIG on all SWIG input files. // TODO: Don't build a shared library, once SWIG emits the necessary // pragmas for external linking. func (b *Builder) swig(a *Action, objdir string, pcCFLAGS []string) (outGo, outC, outCXX []string, err error) { … } var swigCheckOnce … var swigCheck … func (b *Builder) swigDoVersionCheck() error { … } func (b *Builder) swigVersionCheck() error { … } var swigIntSizeOnce … var swigIntSize … var swigIntSizeError … const swigIntSizeCode … // Determine the size of int on the target system for the -intgosize option // of swig >= 2.0.9. Run only once. func (b *Builder) swigDoIntSize(objdir string) (intsize string, err error) { … } // Determine the size of int on the target system for the -intgosize option // of swig >= 2.0.9. func (b *Builder) swigIntSize(objdir string) (intsize string, err error) { … } // Run SWIG on one SWIG input file. func (b *Builder) swigOne(a *Action, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) { … } // disableBuildID adjusts a linker command line to avoid creating a // build ID when creating an object file rather than an executable or // shared library. Some systems, such as Ubuntu, always add // --build-id to every link, but we don't want a build ID when we are // producing an object file. On some of those system a plain -r (not // -Wl,-r) will turn off --build-id, but clang 3.0 doesn't support a // plain -r. I don't know how to turn off --build-id when using clang // other than passing a trailing --build-id=none. So that is what we // do, but only on systems likely to support it, which is to say, // systems that normally use gold or the GNU linker. func (b *Builder) disableBuildID(ldflags []string) []string { … } // mkAbsFiles converts files into a list of absolute files, // assuming they were originally relative to dir, // and returns that new list. func mkAbsFiles(dir string, files []string) []string { … } // passLongArgsInResponseFiles modifies cmd such that, for // certain programs, long arguments are passed in "response files", a // file on disk with the arguments, with one arg per line. An actual // argument starting with '@' means that the rest of the argument is // a filename of arguments to expand. // // See issues 18468 (Windows) and 37768 (Darwin). func passLongArgsInResponseFiles(cmd *exec.Cmd) (cleanup func()) { … } func useResponseFile(path string, argLen int) bool { … } // encodeArg encodes an argument for response file writing. func encodeArg(arg string) string { … }