var gofiles, cfiles, sfiles, objects, cgoObjects []string
- // If we're doing coverage, preprocess the .go files and put them in the work directory
- if a.p.coverMode != "" {
- for _, file := range a.p.GoFiles {
- sourceFile := filepath.Join(a.p.Dir, file)
- cover := a.p.coverVars[file]
- if cover == nil || isTestFile(file) {
- // Not covering this file.
- gofiles = append(gofiles, file)
- continue
- }
- coverFile := filepath.Join(obj, file)
- if err := b.cover(a, coverFile, sourceFile, 0644, cover.Var); err != nil {
- return err
- }
- gofiles = append(gofiles, coverFile)
- }
- } else {
- gofiles = append(gofiles, a.p.GoFiles...)
- }
+ gofiles = append(gofiles, a.p.GoFiles...)
cfiles = append(cfiles, a.p.CFiles...)
sfiles = append(sfiles, a.p.SFiles...)
gofiles = append(gofiles, outGo...)
}
+ // If we're doing coverage, preprocess the .go files and put them in the work directory
+ if a.p.coverMode != "" {
+ for i, file := range gofiles {
+ var sourceFile string
+ var coverFile string
+ var key string
+ if strings.HasSuffix(file, ".cgo1.go") {
+ // cgo files have absolute paths
+ base := filepath.Base(file)
+ sourceFile = file
+ coverFile = filepath.Join(obj, base)
+ key = strings.TrimSuffix(base, ".cgo1.go") + ".go"
+ } else {
+ sourceFile = filepath.Join(a.p.Dir, file)
+ coverFile = filepath.Join(obj, file)
+ key = file
+ }
+ cover := a.p.coverVars[key]
+ if cover == nil || isTestFile(file) {
+ // Not covering this file.
+ continue
+ }
+ if err := b.cover(a, coverFile, sourceFile, 0666, cover.Var); err != nil {
+ return err
+ }
+ gofiles[i] = coverFile
+ }
+ }
+
// Prepare Go import path list.
inc := b.includeArgs("-I", a.deps)
p.Stale = true // rebuild
p.fake = true // do not warn about rebuild
p.coverMode = testCoverMode
- p.coverVars = declareCoverVars(p.ImportPath, p.GoFiles...)
+ var coverFiles []string
+ coverFiles = append(coverFiles, p.GoFiles...)
+ coverFiles = append(coverFiles, p.CgoFiles...)
+ p.coverVars = declareCoverVars(p.ImportPath, coverFiles...)
}
}
if localCover {
ptest.coverMode = testCoverMode
- ptest.coverVars = declareCoverVars(ptest.ImportPath, ptest.GoFiles...)
+ var coverFiles []string
+ coverFiles = append(coverFiles, ptest.GoFiles...)
+ coverFiles = append(coverFiles, ptest.CgoFiles...)
+ ptest.coverVars = declareCoverVars(ptest.ImportPath, coverFiles...)
}
} else {
ptest = p