github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/cov/covcmd/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 covcmd 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 // EmitMetaFile if non-empty is the path to which the cover tool should 37 // directly emit a coverage meta-data file for the package, if the 38 // package has any functions in it. The go command will pass in a value 39 // here if we've been asked to run "go test -cover" on a package that 40 // doesn't have any *_test.go files. 41 EmitMetaFile string 42 } 43 44 // CoverFixupConfig contains annotations/notes generated by the 45 // cmd/cover tool (during instrumentation) to be passed on to the 46 // compiler when the instrumented code is compiled. The cmd/cover tool 47 // creates a struct of this type, JSON-encodes it, and emits the 48 // result to a file, which the Go command then passes to the compiler 49 // when the instrumented package is built. 50 type CoverFixupConfig struct { 51 // Name of the variable (created by cmd/cover) containing the 52 // encoded meta-data for the package. 53 MetaVar string 54 55 // Length of the meta-data. 56 MetaLen int 57 58 // Hash computed by cmd/cover of the meta-data. 59 MetaHash string 60 61 // Instrumentation strategy. For now this is always set to 62 // "normal", but in the future we may add new values (for example, 63 // if panic paths are instrumented, or if the instrumenter 64 // eliminates redundant counters). 65 Strategy string 66 67 // Prefix assigned to the names of counter variables generated 68 // during instrumentation by cmd/cover. 69 CounterPrefix string 70 71 // Name chosen for the package ID variable generated during 72 // instrumentation. 73 PkgIdVar string 74 75 // Counter mode (e.g. set/count/atomic) 76 CounterMode string 77 78 // Counter granularity (perblock or perfunc). 79 CounterGranularity string 80 } 81 82 // MetaFileForPackage returns the expected name of the meta-data file 83 // for the package whose import path is 'importPath' in cases where 84 // we're using meta-data generated by the cover tool, as opposed to a 85 // meta-data file created at runtime. 86 func MetaFileForPackage(importPath string) string