Skip to content

Commit 98bacde

Browse files
thanmgopherbot
authored andcommitted
internal/coverage: separate out cmd defs to separate package
Relocate the definitions in cmddefs.go (used by the compiler and the cover tool) to a separate package "covcmd". No change in functionality, this is a pure refactoring, in preparation for a subsequent change that will require updating the imports for the package. Change-Id: Ic1d277c94d9a574de0a11ec5ed77e892302b9a47 Reviewed-on: https://go-review.googlesource.com/c/go/+/517696 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent ac64a36 commit 98bacde

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

src/cmd/compile/internal/base/flag.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"flag"
1010
"fmt"
1111
"internal/buildcfg"
12-
"internal/coverage"
12+
"internal/coverage/covcmd"
1313
"internal/platform"
1414
"log"
1515
"os"
@@ -133,11 +133,11 @@ type CmdFlags struct {
133133
Patterns map[string][]string
134134
Files map[string]string
135135
}
136-
ImportDirs []string // appended to by -I
137-
ImportMap map[string]string // set by -importcfg
138-
PackageFile map[string]string // set by -importcfg; nil means not in use
139-
CoverageInfo *coverage.CoverFixupConfig // set by -coveragecfg
140-
SpectreIndex bool // set by -spectre=index or -spectre=all
136+
ImportDirs []string // appended to by -I
137+
ImportMap map[string]string // set by -importcfg
138+
PackageFile map[string]string // set by -importcfg; nil means not in use
139+
CoverageInfo *covcmd.CoverFixupConfig // set by -coveragecfg
140+
SpectreIndex bool // set by -spectre=index or -spectre=all
141141
// Whether we are adding any sort of code instrumentation, such as
142142
// when the race detector is enabled.
143143
Instrumenting bool
@@ -504,7 +504,7 @@ func readImportCfg(file string) {
504504
}
505505

506506
func readCoverageCfg(file string) {
507-
var cfg coverage.CoverFixupConfig
507+
var cfg covcmd.CoverFixupConfig
508508
data, err := os.ReadFile(file)
509509
if err != nil {
510510
log.Fatalf("-coveragecfg: %v", err)

src/cmd/cover/cfg_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package main_test
77
import (
88
"encoding/json"
99
"fmt"
10-
"internal/coverage"
10+
"internal/coverage/covcmd"
1111
"internal/testenv"
1212
"os"
1313
"path/filepath"
@@ -24,7 +24,7 @@ func writeFile(t *testing.T, path string, contents []byte) {
2424
func writePkgConfig(t *testing.T, outdir, tag, ppath, pname string, gran string) string {
2525
incfg := filepath.Join(outdir, tag+"incfg.txt")
2626
outcfg := filepath.Join(outdir, "outcfg.txt")
27-
p := coverage.CoverPkgConfig{
27+
p := covcmd.CoverPkgConfig{
2828
PkgPath: ppath,
2929
PkgName: pname,
3030
Granularity: gran,

src/cmd/cover/cover.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"go/parser"
1414
"go/token"
1515
"internal/coverage"
16+
"internal/coverage/covcmd"
1617
"internal/coverage/encodemeta"
1718
"internal/coverage/slicewriter"
1819
"io"
@@ -50,7 +51,7 @@ where -pkgcfg points to a file containing the package path,
5051
package name, module path, and related info from "go build",
5152
and -outfilelist points to a file containing the filenames
5253
of the instrumented output files (one per input file).
53-
See https://pkg.go.dev/internal/coverage#CoverPkgConfig for
54+
See https://pkg.go.dev/internal/coverage/covcmd#CoverPkgConfig for
5455
more on the package config.
5556
`
5657

@@ -72,7 +73,7 @@ var (
7273
pkgcfg = flag.String("pkgcfg", "", "enable full-package instrumentation mode using params from specified config file")
7374
)
7475

75-
var pkgconfig coverage.CoverPkgConfig
76+
var pkgconfig covcmd.CoverPkgConfig
7677

7778
// outputfiles is the list of *.cover.go instrumented outputs to write,
7879
// one per input (set when -pkgcfg is in use)
@@ -1122,7 +1123,7 @@ func (p *Package) emitMetaData(w io.Writer) {
11221123
}
11231124
fmt.Fprintf(w, "}\n")
11241125

1125-
fixcfg := coverage.CoverFixupConfig{
1126+
fixcfg := covcmd.CoverFixupConfig{
11261127
Strategy: "normal",
11271128
MetaVar: mkMetaVar(),
11281129
MetaLen: len(payload),

src/cmd/dist/buildtool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var bootstrapDirs = []string{
6363
"go/constant",
6464
"internal/abi",
6565
"internal/coverage",
66+
"internal/coverage/covcmd",
6667
"internal/bisect",
6768
"internal/buildcfg",
6869
"internal/goarch",

src/cmd/go/internal/work/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"errors"
1515
"fmt"
1616
"go/token"
17-
"internal/coverage"
17+
"internal/coverage/covcmd"
1818
"internal/lazyregexp"
1919
"io"
2020
"io/fs"
@@ -2064,7 +2064,7 @@ func (b *Builder) cover2(a *Action, infiles, outfiles []string, varName string,
20642064
func (b *Builder) writeCoverPkgInputs(a *Action, pconfigfile string, covoutputsfile string, outfiles []string) error {
20652065
p := a.Package
20662066
p.Internal.CoverageCfg = a.Objdir + "coveragecfg"
2067-
pcfg := coverage.CoverPkgConfig{
2067+
pcfg := covcmd.CoverPkgConfig{
20682068
PkgPath: p.ImportPath,
20692069
PkgName: p.Name,
20702070
// Note: coverage granularity is currently hard-wired to

src/internal/coverage/cmddefs.go renamed to src/internal/coverage/covcmd/cmddefs.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package coverage
5+
package covcmd
66

77
// CoverPkgConfig is a bundle of information passed from the Go
88
// command to the cover command during "go build -cover" runs. The
@@ -71,17 +71,3 @@ type CoverFixupConfig struct {
7171
// Counter granularity (perblock or perfunc).
7272
CounterGranularity string
7373
}
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"

src/internal/coverage/defs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,20 @@ func (cm CounterGranularity) String() string {
261261
return "<invalid>"
262262
}
263263

264+
// Name of file within the "go test -cover" temp coverdir directory
265+
// containing a list of meta-data files for packages being tested
266+
// in a "go test -coverpkg=... ..." run. This constant is shared
267+
// by the Go command and by the coverage runtime.
268+
const MetaFilesFileName = "metafiles.txt"
269+
270+
// MetaFilePaths contains information generated by the Go command and
271+
// the read in by coverage test support functions within an executing
272+
// "go test -cover" binary.
273+
type MetaFileCollection struct {
274+
ImportPaths []string
275+
MetaFileFragments []string
276+
}
277+
264278
//.....................................................................
265279
//
266280
// Counter data definitions:

0 commit comments

Comments
 (0)