github.com/gernest/nezuko@v0.1.2/internal/cfg/cfg.go (about)

     1  // Copyright 2017 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 cfg holds configuration shared by multiple parts
     6  // of the go command.
     7  package cfg
     8  
     9  import (
    10  	"os"
    11  	"path/filepath"
    12  	"runtime"
    13  
    14  	"github.com/gernest/nezuko/internal/build"
    15  )
    16  
    17  // These are general "build flags" used by build and other commands.
    18  var (
    19  	BuildA                 bool   // -a flag
    20  	BuildBuildmode         string // -buildmode flag
    21  	BuildContext           = defaultContext()
    22  	BuildMod               string             // -mod flag
    23  	BuildI                 bool               // -i flag
    24  	BuildLinkshared        bool               // -linkshared flag
    25  	BuildMSan              bool               // -msan flag
    26  	BuildN                 bool               // -n flag
    27  	BuildO                 string             // -o flag
    28  	BuildP                 = runtime.NumCPU() // -p flag
    29  	BuildPkgdir            string             // -pkgdir flag
    30  	BuildRace              bool               // -race flag
    31  	BuildToolexec          []string           // -toolexec flag
    32  	BuildToolchainName     string
    33  	BuildToolchainCompiler func() string
    34  	BuildToolchainLinker   func() string
    35  	BuildV                 bool // -v flag
    36  	BuildWork              bool // -work flag
    37  	BuildX                 bool // -x flag
    38  
    39  	CmdName string // "build", "install", "list", etc.
    40  
    41  	DebugActiongraph string // -debug-actiongraph flag (undocumented, unstable)
    42  )
    43  
    44  func defaultContext() build.Context {
    45  	ctxt := build.Default
    46  	ctxt.JoinPath = filepath.Join // back door to say "do not use go command"
    47  	return ctxt
    48  }
    49  
    50  func init() {
    51  	BuildToolchainCompiler = func() string { return "missing-compiler" }
    52  	BuildToolchainLinker = func() string { return "missing-linker" }
    53  }
    54  
    55  // An EnvVar is an environment variable Name=Value.
    56  type EnvVar struct {
    57  	Name  string
    58  	Value string
    59  }
    60  
    61  // OrigEnv is the original environment of the program at startup.
    62  var OrigEnv []string
    63  
    64  // CmdEnv is the new environment for running go tool commands.
    65  // User binaries (during go test or go run) are run with OrigEnv,
    66  // not CmdEnv.
    67  var CmdEnv []EnvVar
    68  
    69  // Global build parameters (used during package load)
    70  var (
    71  	// path to zig binary
    72  	ZigPath   string
    73  	ExeSuffix string
    74  	// ModulesEnabled specifies whether the go command is running
    75  	// in module-aware mode (as opposed to GOPATH mode).
    76  	// It is equal to modload.Enabled, but not all packages can import modload.
    77  	ModulesEnabled bool
    78  )
    79  
    80  // isSameDir reports whether dir1 and dir2 are the same directory.
    81  func isSameDir(dir1, dir2 string) bool {
    82  	if dir1 == dir2 {
    83  		return true
    84  	}
    85  	info1, err1 := os.Stat(dir1)
    86  	info2, err2 := os.Stat(dir2)
    87  	return err1 == nil && err2 == nil && os.SameFile(info1, info2)
    88  }