github.com/AndrienkoAleksandr/go@v0.0.19/src/intern/coverage/cmddefs.go (about)

     1  // Copyright 2022 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 coverage
     6  
     7  // CoverPkgConfig is a bundle of information passed from the Go
     8  // command to the cover command during "go build -cover" runs. The
     9  // Go command creates and fills in a struct as below, then passes
    10  // file containing the encoded JSON for the struct to the "cover"
    11  // tool when instrumenting the source files in a Go package.
    12  type CoverPkgConfig struct {
    13  	// File into which cmd/cover should emit summary info
    14  	// when instrumentation is complete.
    15  	OutConfig string
    16  
    17  	// Import path for the package being instrumented.
    18  	PkgPath string
    19  
    20  	// Package name.
    21  	PkgName string
    22  
    23  	// Instrumentation granularity: one of "perfunc" or "perblock" (default)
    24  	Granularity string
    25  
    26  	// Module path for this package (empty if no go.mod in use)
    27  	ModulePath string
    28  
    29  	// Local mode indicates we're doing a coverage build or test of a
    30  	// package selected via local import path, e.g. "./..." or
    31  	// "./foo/bar" as opposed to a non-relative import path. See the
    32  	// corresponding field in cmd/go's PackageInternal struct for more
    33  	// info.
    34  	Local bool
    35  }
    36  
    37  // CoverFixupConfig contains annotations/notes generated by the
    38  // cmd/cover tool (during instrumentation) to be passed on to the
    39  // compiler when the instrumented code is compiled. The cmd/cover tool
    40  // creates a struct of this type, JSON-encodes it, and emits the
    41  // result to a file, which the Go command then passes to the compiler
    42  // when the instrumented package is built.
    43  type CoverFixupConfig struct {
    44  	// Name of the variable (created by cmd/cover) containing the
    45  	// encoded meta-data for the package.
    46  	MetaVar string
    47  
    48  	// Length of the meta-data.
    49  	MetaLen int
    50  
    51  	// Hash computed by cmd/cover of the meta-data.
    52  	MetaHash string
    53  
    54  	// Instrumentation strategy. For now this is always set to
    55  	// "normal", but in the future we may add new values (for example,
    56  	// if panic paths are instrumented, or if the instrumenter
    57  	// eliminates redundant counters).
    58  	Strategy string
    59  
    60  	// Prefix assigned to the names of counter variables generated
    61  	// during instrumentation by cmd/cover.
    62  	CounterPrefix string
    63  
    64  	// Name chosen for the package ID variable generated during
    65  	// instrumentation.
    66  	PkgIdVar string
    67  
    68  	// Counter mode (e.g. set/count/atomic)
    69  	CounterMode string
    70  
    71  	// Counter granularity (perblock or perfunc).
    72  	CounterGranularity string
    73  }
    74  
    75  // MetaFilePaths contains information generated by the Go command and
    76  // the read in by coverage test support functions within an executing
    77  // "go test -cover" binary.
    78  type MetaFileCollection struct {
    79  	ImportPaths       []string
    80  	MetaFileFragments []string
    81  }
    82  
    83  // Name of file within the "go test -cover" temp coverdir directory
    84  // containing a list of meta-data files for packages being tested
    85  // in a "go test -coverpkg=... ..." run. This constant is shared
    86  // by the Go command and by the coverage runtime.
    87  const MetaFilesFileName = "metafiles.txt"