Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/please_go/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 1.26.1
--------------
* Make `please_go cover` handle the possiblity that every src is outside the package directory (#385)

Version 1.26.0
--------------
* `generate`: rename `third_part_folder` option to `deps_path`, and remove `t` short option (#379)
Expand Down
2 changes: 1 addition & 1 deletion tools/please_go/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.26.0
1.26.1
11 changes: 10 additions & 1 deletion tools/please_go/cover/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cover
import (
"bytes"
"encoding/json"
"fmt"
"go/parser"
"go/token"
"log"
Expand All @@ -23,6 +24,14 @@ func WriteCoverage(goTool, coverTool, covercfg, output, pkgConfigFile, pkg strin
return err
}

// It is entirely possible that all of the sources to a build target are outside the package
// directory (which is usually the result of using the outputs of other targets as srcs).
// `go tool cover` still wants to write the `_covervars.cover.go` file to the package directory,
// so first ensure that it exists.
if err := os.MkdirAll(pkg, 0755); err != nil {
return fmt.Errorf("ensure package directory exists: %w", err)
}

b, _ := json.Marshal(coverConfig{
OutConfig: covercfg,
PkgPath: pkg,
Expand All @@ -38,7 +47,7 @@ func WriteCoverage(goTool, coverTool, covercfg, output, pkgConfigFile, pkg strin
// 1.27 needs package-relative paths (https://go.dev/issue/70478)
needRelativePaths := needs127RelativePaths(goTool)
if coverTool != "" || needRelativePaths || need121CoverVars {
buf.WriteString(filepath.Join(filepath.Dir(srcs[0]), "_covervars.cover.go\n"))
buf.WriteString(filepath.Join(pkg, "_covervars.cover.go\n"))
}
for _, src := range srcs {
buf.WriteString(strings.TrimSuffix(src, ".go") + ".cover.go\n")
Expand Down