build

package
v2.0.0-...-ee63433 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GO_BUILD = iota
	GO_INSTALL
)

Variables

This section is empty.

Functions

func CustomParseCmdAndArgs

func CustomParseCmdAndArgs(cmd *cobra.Command, args []string) *pflag.FlagSet

CustomParseCmdAndArgs 因为关闭了 cobra 的解析功能,需要手动构造并解析 goc flags

func TmpFolderName

func TmpFolderName(path string) string

TmpFolderName generates a directory name according to the path

func WithArgs

func WithArgs(args []string) gocOption

func WithBuild

func WithBuild() gocOption

func WithDebug

func WithDebug(enable bool) gocOption

func WithFlagSets

func WithFlagSets(sets *pflag.FlagSet) gocOption

func WithHost

func WithHost(host string) gocOption

func WithInstall

func WithInstall() gocOption

func WithMode

func WithMode(mode string) gocOption

Types

type Build

type Build struct {
	Args      []string // all goc + go command line args + flags
	FlagSets  *pflag.FlagSet
	BuildType int

	Debug bool
	Host  string
	Mode  string // cover mode

	GOPATH           string
	GOBIN            string
	CurWd            string
	TmpWd            string
	CurModProjectDir string
	TmpModProjectDir string

	Goflags  []string // go command line flags
	GoArgs   []string // go command line args
	Packages []string // go command line [packages]

	IsVendorMod bool // vendor, readonly, or mod?
	IsModEdit   bool // is mod file edited?

	ImportPath                  string // the whole import path of the project
	Pkgs                        map[string]*Package
	GlobalCoverVarImportPath    string
	GlobalCoverVarImportPathDir string
}

Build struct a build

func NewBuild

func NewBuild(opts ...gocOption) *Build

NewBuild creates a Build struct

func NewInstall

func NewInstall(opts ...gocOption) *Build

func NewRun

func NewRun(opts ...gocOption) *Build

func (*Build) Build

func (b *Build) Build()

Build starts go build

1. copy project to temp, 2. inject cover variables and functions into the project, 3. build the project in temp.

func (*Build) Inject

func (b *Build) Inject()

Inject injects cover variables for all the .go files in the target directory

func (*Build) Install

func (b *Build) Install()

Install starts go install

1. copy project to temp, 2. inject cover variables and functions into the project, 3. install the project in temp.

func (*Build) Run

func (b *Build) Run()

Run starts go run

1. copy project to temp, 2. inject cover variables and functions into the project, 3. run the project in temp.

type FileVar

type FileVar struct {
	File string // 这里其实不是文件名,是 importpath + filename
	Var  string
}

FileVar holds the name of the generated coverage variables targeting the named file.

type ModuleError

type ModuleError struct {
	Err string // error text
}

ModuleError represents the error loading module

type ModulePublic

type ModulePublic struct {
	Path      string        `json:",omitempty"` // module path
	Version   string        `json:",omitempty"` // module version
	Versions  []string      `json:",omitempty"` // available module versions
	Replace   *ModulePublic `json:",omitempty"` // replaced by this module
	Time      *time.Time    `json:",omitempty"` // time version was created
	Update    *ModulePublic `json:",omitempty"` // available update (with -u)
	Main      bool          `json:",omitempty"` // is this the main module?
	Indirect  bool          `json:",omitempty"` // module is only indirectly needed by main module
	Dir       string        `json:",omitempty"` // directory holding local copy of files, if any
	GoMod     string        `json:",omitempty"` // path to go.mod file describing module, if any
	GoVersion string        `json:",omitempty"` // go version used in module
	Error     *ModuleError  `json:",omitempty"` // error loading module
}

ModulePublic represents the package info of a module

type Package

type Package struct {
	Dir        string `json:"Dir"`        // directory containing package sources
	ImportPath string `json:"ImportPath"` // import path of package in dir
	Name       string `json:"Name"`       // package name
	Target     string `json:",omitempty"` // installed target for this package (may be executable)
	Root       string `json:",omitempty"` // Go root, Go path dir, or module root dir containing this package

	Module   *ModulePublic `json:",omitempty"`         // info about package's module, if any
	Goroot   bool          `json:"Goroot,omitempty"`   // is this package in the Go root?
	Standard bool          `json:"Standard,omitempty"` // is this package part of the standard Go library?
	DepOnly  bool          `json:"DepOnly,omitempty"`  // package is only a dependency, not explicitly listed

	// Source files
	GoFiles  []string `json:"GoFiles,omitempty"`  // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
	CgoFiles []string `json:"CgoFiles,omitempty"` // .go source files that import "C"

	// Dependency information
	Deps      []string          `json:"Deps,omitempty"` // all (recursively) imported dependencies
	Imports   []string          `json:",omitempty"`     // import paths used by this package
	ImportMap map[string]string `json:",omitempty"`     // map from source import to ImportPath (identity entries omitted)

	// Error information
	Incomplete bool            `json:"Incomplete,omitempty"` // this package or a dependency has an error
	Error      *PackageError   `json:"Error,omitempty"`      // error loading package
	DepsErrors []*PackageError `json:"DepsErrors,omitempty"` // errors loading dependencies
}

Package map a package output by go list this is subset of package struct in: https://github.com/golang/go/blob/master/src/cmd/go/internal/load/pkg.go#L58

type PackageCover

type PackageCover struct {
	Package *Package
	Vars    map[string]*FileVar
}

PackageCover holds all the generate coverage variables of a package

type PackageError

type PackageError struct {
	ImportStack []string // shortest path from package named on command line to this one
	Pos         string   // position of error (if present, file:line:col)
	Err         string   // the error itself
}

PackageError is the error info for a package when list failed

Directories

Path Synopsis
internal
tool
Package edit implements buffered position-based editing of byte slices.
Package edit implements buffered position-based editing of byte slices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL