]> Cypherpunks repositories - gostls13.git/commitdiff
internal/coverage: separate out cmd defs to separate package
authorThan McIntosh <thanm@google.com>
Wed, 9 Aug 2023 12:50:41 +0000 (08:50 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 14 Aug 2023 12:51:16 +0000 (12:51 +0000)
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 <gobot@golang.org>
Auto-Submit: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/base/flag.go
src/cmd/cover/cfg_test.go
src/cmd/cover/cover.go
src/cmd/dist/buildtool.go
src/cmd/go/internal/work/exec.go
src/internal/coverage/covcmd/cmddefs.go [moved from src/internal/coverage/cmddefs.go with 81% similarity]
src/internal/coverage/defs.go

index 6d9497c3a93e5257319408eea885f3e3d641638b..1eb46e2369168a98137818a0a39d28778518159c 100644 (file)
@@ -9,7 +9,7 @@ import (
        "flag"
        "fmt"
        "internal/buildcfg"
-       "internal/coverage"
+       "internal/coverage/covcmd"
        "internal/platform"
        "log"
        "os"
@@ -133,11 +133,11 @@ type CmdFlags struct {
                        Patterns map[string][]string
                        Files    map[string]string
                }
-               ImportDirs   []string                   // appended to by -I
-               ImportMap    map[string]string          // set by -importcfg
-               PackageFile  map[string]string          // set by -importcfg; nil means not in use
-               CoverageInfo *coverage.CoverFixupConfig // set by -coveragecfg
-               SpectreIndex bool                       // set by -spectre=index or -spectre=all
+               ImportDirs   []string                 // appended to by -I
+               ImportMap    map[string]string        // set by -importcfg
+               PackageFile  map[string]string        // set by -importcfg; nil means not in use
+               CoverageInfo *covcmd.CoverFixupConfig // set by -coveragecfg
+               SpectreIndex bool                     // set by -spectre=index or -spectre=all
                // Whether we are adding any sort of code instrumentation, such as
                // when the race detector is enabled.
                Instrumenting bool
@@ -504,7 +504,7 @@ func readImportCfg(file string) {
 }
 
 func readCoverageCfg(file string) {
-       var cfg coverage.CoverFixupConfig
+       var cfg covcmd.CoverFixupConfig
        data, err := os.ReadFile(file)
        if err != nil {
                log.Fatalf("-coveragecfg: %v", err)
index 6782ec89a4779e30c72978934baef084a04253d7..91c33a0ac2733db0da439acb65312e2f12073959 100644 (file)
@@ -7,7 +7,7 @@ package main_test
 import (
        "encoding/json"
        "fmt"
-       "internal/coverage"
+       "internal/coverage/covcmd"
        "internal/testenv"
        "os"
        "path/filepath"
@@ -24,7 +24,7 @@ func writeFile(t *testing.T, path string, contents []byte) {
 func writePkgConfig(t *testing.T, outdir, tag, ppath, pname string, gran string) string {
        incfg := filepath.Join(outdir, tag+"incfg.txt")
        outcfg := filepath.Join(outdir, "outcfg.txt")
-       p := coverage.CoverPkgConfig{
+       p := covcmd.CoverPkgConfig{
                PkgPath:     ppath,
                PkgName:     pname,
                Granularity: gran,
index a4b837c9ad32f27f7c1a78c2b62cc7e504934b65..eb44d40001d582956ba881d48d0820ec0e1b4210 100644 (file)
@@ -13,6 +13,7 @@ import (
        "go/parser"
        "go/token"
        "internal/coverage"
+       "internal/coverage/covcmd"
        "internal/coverage/encodemeta"
        "internal/coverage/slicewriter"
        "io"
@@ -50,7 +51,7 @@ where -pkgcfg points to a file containing the package path,
 package name, module path, and related info from "go build",
 and -outfilelist points to a file containing the filenames
 of the instrumented output files (one per input file).
-See https://pkg.go.dev/internal/coverage#CoverPkgConfig for
+See https://pkg.go.dev/internal/coverage/covcmd#CoverPkgConfig for
 more on the package config.
 `
 
@@ -72,7 +73,7 @@ var (
        pkgcfg      = flag.String("pkgcfg", "", "enable full-package instrumentation mode using params from specified config file")
 )
 
-var pkgconfig coverage.CoverPkgConfig
+var pkgconfig covcmd.CoverPkgConfig
 
 // outputfiles is the list of *.cover.go instrumented outputs to write,
 // one per input (set when -pkgcfg is in use)
@@ -1122,7 +1123,7 @@ func (p *Package) emitMetaData(w io.Writer) {
        }
        fmt.Fprintf(w, "}\n")
 
-       fixcfg := coverage.CoverFixupConfig{
+       fixcfg := covcmd.CoverFixupConfig{
                Strategy:           "normal",
                MetaVar:            mkMetaVar(),
                MetaLen:            len(payload),
index 0c2f51029a4dc7d818acea6fad24cb0d7eee6cb3..de68f110255179fb484ae31e15747c36d14e9e86 100644 (file)
@@ -63,6 +63,7 @@ var bootstrapDirs = []string{
        "go/constant",
        "internal/abi",
        "internal/coverage",
+       "internal/coverage/covcmd",
        "internal/bisect",
        "internal/buildcfg",
        "internal/goarch",
index 197078a0e9c26e69d1403319607a037f1bdefa77..64b0aae2672eb3469a3de7424cfbc3d0ee921e15 100644 (file)
@@ -14,7 +14,7 @@ import (
        "errors"
        "fmt"
        "go/token"
-       "internal/coverage"
+       "internal/coverage/covcmd"
        "internal/lazyregexp"
        "io"
        "io/fs"
@@ -2064,7 +2064,7 @@ func (b *Builder) cover2(a *Action, infiles, outfiles []string, varName string,
 func (b *Builder) writeCoverPkgInputs(a *Action, pconfigfile string, covoutputsfile string, outfiles []string) error {
        p := a.Package
        p.Internal.CoverageCfg = a.Objdir + "coveragecfg"
-       pcfg := coverage.CoverPkgConfig{
+       pcfg := covcmd.CoverPkgConfig{
                PkgPath: p.ImportPath,
                PkgName: p.Name,
                // Note: coverage granularity is currently hard-wired to
similarity index 81%
rename from src/internal/coverage/cmddefs.go
rename to src/internal/coverage/covcmd/cmddefs.go
index 49376a4665fc2fc063cff99e66d740089f7dbdc7..8a350f39033a9c194c924b7390a655742e76a150 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package coverage
+package covcmd
 
 // CoverPkgConfig is a bundle of information passed from the Go
 // command to the cover command during "go build -cover" runs. The
@@ -71,17 +71,3 @@ type CoverFixupConfig struct {
        // Counter granularity (perblock or perfunc).
        CounterGranularity string
 }
-
-// MetaFilePaths contains information generated by the Go command and
-// the read in by coverage test support functions within an executing
-// "go test -cover" binary.
-type MetaFileCollection struct {
-       ImportPaths       []string
-       MetaFileFragments []string
-}
-
-// Name of file within the "go test -cover" temp coverdir directory
-// containing a list of meta-data files for packages being tested
-// in a "go test -coverpkg=... ..." run. This constant is shared
-// by the Go command and by the coverage runtime.
-const MetaFilesFileName = "metafiles.txt"
index 8751b9f87867570877dc0bcd8d3436334fc1335a..340ac9563559d016ca2f42189284b143d50d52e7 100644 (file)
@@ -261,6 +261,20 @@ func (cm CounterGranularity) String() string {
        return "<invalid>"
 }
 
+// Name of file within the "go test -cover" temp coverdir directory
+// containing a list of meta-data files for packages being tested
+// in a "go test -coverpkg=... ..." run. This constant is shared
+// by the Go command and by the coverage runtime.
+const MetaFilesFileName = "metafiles.txt"
+
+// MetaFilePaths contains information generated by the Go command and
+// the read in by coverage test support functions within an executing
+// "go test -cover" binary.
+type MetaFileCollection struct {
+       ImportPaths       []string
+       MetaFileFragments []string
+}
+
 //.....................................................................
 //
 // Counter data definitions: