Skip to content

Commit

Permalink
Wire up cover_mode and cgo srcs
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jul 27, 2024
1 parent 9d68b2c commit 7349a4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 9 additions & 2 deletions go/private/actions/compilepkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ def emit_compilepkg(
uniquify = True,
expand_directories = False,
)
cover_mode = None
if cover and go.coverdata:
inputs.append(go.coverdata.data.export_file)
args.add("-arc", _archive(go.coverdata))
if go.mode.race:
args.add("-cover_mode", "atomic")
cover_mode = "atomic"
else:
args.add("-cover_mode", "set")
cover_mode = "set"
args.add("-cover_mode", cover_mode)
args.add("-cover_format", go.cover_format)
args.add_all(cover, before_each = "-cover")
args.add_all(archives, before_each = "-arc", map_each = _archive)
Expand Down Expand Up @@ -207,6 +209,7 @@ def emit_compilepkg(
importmap = importmap,
archives = archives,
recompile_internal_deps = recompile_internal_deps,
cover_mode = cover_mode,
cgo_go_srcs = cgo_go_srcs,
out_facts = out_facts,
out_log = out_nogo_log,
Expand All @@ -222,6 +225,7 @@ def _run_nogo(
importmap,
archives,
recompile_internal_deps,
cover_mode,
cgo_go_srcs,
out_facts,
out_log,
Expand All @@ -237,7 +241,10 @@ def _run_nogo(
args = go.builder_args(go, "nogo", use_path_mapping = True)
args.add_all(sources, before_each = "-src")
if cgo_go_srcs:
inputs.append(cgo_go_srcs)
args.add_all([cgo_go_srcs], before_each = "-src")
if cover_mode:
args.add("-cover_mode", cover_mode)
if recompile_internal_deps:
args.add_all(recompile_internal_deps, before_each = "-recompile_internal_deps")
args.add_all(archives, before_each = "-arc", map_each = _archive)
Expand Down
5 changes: 1 addition & 4 deletions go/tools/builders/compilepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func compilePkg(args []string) error {
fs := flag.NewFlagSet("GoCompilePkg", flag.ExitOnError)
goenv := envFlags(fs)
var unfilteredSrcs, coverSrcs, embedSrcs, embedLookupDirs, embedRoots, recompileInternalDeps multiFlag
var deps, facts archiveMultiFlag
var deps archiveMultiFlag
var importPath, packagePath, packageListPath, coverMode string
var outLinkobjPath, outInterfacePath, cgoExportHPath, cgoGoSrcsPath string
var testFilter string
Expand All @@ -51,7 +51,6 @@ func compilePkg(args []string) error {
fs.Var(&embedLookupDirs, "embedlookupdir", "Root-relative paths to directories relative to which //go:embed directives are resolved")
fs.Var(&embedRoots, "embedroot", "Bazel output root under which a file passed via -embedsrc resides")
fs.Var(&deps, "arc", "Import path, package path, and file name of a direct dependency, separated by '='")
fs.Var(&facts, "facts", "Import path, package path, and file name of a direct dependency's nogo facts file, separated by '='")
fs.StringVar(&importPath, "importpath", "", "The import path of the package being compiled. Not passed to the compiler, but may be displayed in debug data.")
fs.StringVar(&packagePath, "p", "", "The package path (importmap) of the package being compiled")
fs.Var(&gcFlags, "gcflags", "Go compiler flags")
Expand Down Expand Up @@ -131,7 +130,6 @@ func compilePkg(args []string) error {
packagePath,
srcs,
deps,
facts,
coverMode,
coverSrcs,
embedSrcs,
Expand Down Expand Up @@ -163,7 +161,6 @@ func compileArchive(
packagePath string,
srcs archiveSrcs,
deps []archive,
facts []archive,
coverMode string,
coverSrcs []string,
embedSrcs []string,
Expand Down
20 changes: 20 additions & 0 deletions go/tools/builders/nogo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"errors"
"flag"
"fmt"
"os"
Expand All @@ -23,13 +24,15 @@ func nogo(args []string) error {
var deps, facts archiveMultiFlag
var importPath, packagePath, nogoPath, packageListPath string
var outFactsPath, outLogPath string
var coverMode string
fs.Var(&unfilteredSrcs, "src", ".go, .c, .cc, .m, .mm, .s, or .S file to be filtered and compiled")
fs.Var(&deps, "arc", "Import path, package path, and file name of a direct dependency, separated by '='")
fs.Var(&facts, "facts", "Import path, package path, and file name of a direct dependency's nogo facts file, separated by '='")
fs.StringVar(&importPath, "importpath", "", "The import path of the package being compiled. Not passed to the compiler, but may be displayed in debug data.")
fs.StringVar(&packagePath, "p", "", "The package path (importmap) of the package being compiled")
fs.StringVar(&packageListPath, "package_list", "", "The file containing the list of standard library packages")
fs.Var(&recompileInternalDeps, "recompile_internal_deps", "The import path of the direct dependencies that needs to be recompiled.")
fs.StringVar(&coverMode, "cover_mode", "", "The coverage mode to use. Empty if coverage instrumentation should not be added.")
fs.StringVar(&nogoPath, "nogo", "", "The nogo binary")
fs.StringVar(&outFactsPath, "out_facts", "", "The file to emit serialized nogo facts to")
fs.StringVar(&outLogPath, "out_log", "", "The file to emit nogo logs into")
Expand Down Expand Up @@ -76,6 +79,23 @@ func nogo(args []string) error {
imports["syscall"] = nil
imports["unsafe"] = nil
}
if coverMode != "" {
if coverMode == "atomic" {
imports["sync/atomic"] = nil
}
const coverdataPath = "github.com/bazelbuild/rules_go/go/tools/coverdata"
var coverdata *archive
for i := range deps {
if deps[i].importPath == coverdataPath {
coverdata = &deps[i]
break
}
}
if coverdata == nil {
return errors.New("coverage requested but coverdata dependency not provided")
}
imports[coverdataPath] = coverdata
}

importcfgPath, err := buildImportcfgFileForCompile(imports, goenv.installSuffix, filepath.Dir(outFactsPath))
if err != nil {
Expand Down

0 comments on commit 7349a4b

Please sign in to comment.