Skip to content

Commit 7b77ff4

Browse files
committed
cmd/go: add IgnoredOtherFiles to go list; pass IgnoredFiles to vet
Show constraint-ignored non-.go files in go list, as Package.IgnoredOtherFiles (same as go/build's IgnoredOtherFiles). Pass full list of ignored files to vet, to help buildtag checker. For #41184. Change-Id: I749868de9082cbbc1efbc59370783c8c82fe735f Reviewed-on: https://go-review.googlesource.com/c/go/+/240553 Trust: Russ Cox <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 8b289a1 commit 7b77ff4

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

src/cmd/go/internal/load/pkg.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,20 @@ type PackagePublic struct {
7575
// Source files
7676
// If you add to this list you MUST add to p.AllFiles (below) too.
7777
// Otherwise file name security lists will not apply to any new additions.
78-
GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
79-
CgoFiles []string `json:",omitempty"` // .go source files that import "C"
80-
CompiledGoFiles []string `json:",omitempty"` // .go output from running cgo on CgoFiles
81-
IgnoredGoFiles []string `json:",omitempty"` // .go source files ignored due to build constraints
82-
CFiles []string `json:",omitempty"` // .c source files
83-
CXXFiles []string `json:",omitempty"` // .cc, .cpp and .cxx source files
84-
MFiles []string `json:",omitempty"` // .m source files
85-
HFiles []string `json:",omitempty"` // .h, .hh, .hpp and .hxx source files
86-
FFiles []string `json:",omitempty"` // .f, .F, .for and .f90 Fortran source files
87-
SFiles []string `json:",omitempty"` // .s source files
88-
SwigFiles []string `json:",omitempty"` // .swig files
89-
SwigCXXFiles []string `json:",omitempty"` // .swigcxx files
90-
SysoFiles []string `json:",omitempty"` // .syso system object files added to package
78+
GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
79+
CgoFiles []string `json:",omitempty"` // .go source files that import "C"
80+
CompiledGoFiles []string `json:",omitempty"` // .go output from running cgo on CgoFiles
81+
IgnoredGoFiles []string `json:",omitempty"` // .go source files ignored due to build constraints
82+
IgnoredOtherFiles []string `json:",omitempty"` // non-.go source files ignored due to build constraints
83+
CFiles []string `json:",omitempty"` // .c source files
84+
CXXFiles []string `json:",omitempty"` // .cc, .cpp and .cxx source files
85+
MFiles []string `json:",omitempty"` // .m source files
86+
HFiles []string `json:",omitempty"` // .h, .hh, .hpp and .hxx source files
87+
FFiles []string `json:",omitempty"` // .f, .F, .for and .f90 Fortran source files
88+
SFiles []string `json:",omitempty"` // .s source files
89+
SwigFiles []string `json:",omitempty"` // .swig files
90+
SwigCXXFiles []string `json:",omitempty"` // .swigcxx files
91+
SysoFiles []string `json:",omitempty"` // .syso system object files added to package
9192

9293
// Cgo directives
9394
CgoCFLAGS []string `json:",omitempty"` // cgo: flags for C compiler
@@ -127,6 +128,7 @@ func (p *Package) AllFiles() []string {
127128
p.CgoFiles,
128129
// no p.CompiledGoFiles, because they are from GoFiles or generated by us
129130
p.IgnoredGoFiles,
131+
p.IgnoredOtherFiles,
130132
p.CFiles,
131133
p.CXXFiles,
132134
p.MFiles,
@@ -330,6 +332,7 @@ func (p *Package) copyBuild(pp *build.Package) {
330332
p.GoFiles = pp.GoFiles
331333
p.CgoFiles = pp.CgoFiles
332334
p.IgnoredGoFiles = pp.IgnoredGoFiles
335+
p.IgnoredOtherFiles = pp.IgnoredOtherFiles
333336
p.CFiles = pp.CFiles
334337
p.CXXFiles = pp.CXXFiles
335338
p.MFiles = pp.MFiles

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

+19-15
Original file line numberDiff line numberDiff line change
@@ -922,12 +922,13 @@ func (b *Builder) loadCachedSrcFiles(a *Action) error {
922922

923923
// vetConfig is the configuration passed to vet describing a single package.
924924
type vetConfig struct {
925-
ID string // package ID (example: "fmt [fmt.test]")
926-
Compiler string // compiler name (gc, gccgo)
927-
Dir string // directory containing package
928-
ImportPath string // canonical import path ("package path")
929-
GoFiles []string // absolute paths to package source files
930-
NonGoFiles []string // absolute paths to package non-Go files
925+
ID string // package ID (example: "fmt [fmt.test]")
926+
Compiler string // compiler name (gc, gccgo)
927+
Dir string // directory containing package
928+
ImportPath string // canonical import path ("package path")
929+
GoFiles []string // absolute paths to package source files
930+
NonGoFiles []string // absolute paths to package non-Go files
931+
IgnoredFiles []string // absolute paths to ignored source files
931932

932933
ImportMap map[string]string // map import path in source code to package path
933934
PackageFile map[string]string // map package path to .a file with export data
@@ -951,20 +952,23 @@ func buildVetConfig(a *Action, srcfiles []string) {
951952
}
952953
}
953954

955+
ignored := str.StringList(a.Package.IgnoredGoFiles, a.Package.IgnoredOtherFiles)
956+
954957
// Pass list of absolute paths to vet,
955958
// so that vet's error messages will use absolute paths,
956959
// so that we can reformat them relative to the directory
957960
// in which the go command is invoked.
958961
vcfg := &vetConfig{
959-
ID: a.Package.ImportPath,
960-
Compiler: cfg.BuildToolchainName,
961-
Dir: a.Package.Dir,
962-
GoFiles: mkAbsFiles(a.Package.Dir, gofiles),
963-
NonGoFiles: mkAbsFiles(a.Package.Dir, nongofiles),
964-
ImportPath: a.Package.ImportPath,
965-
ImportMap: make(map[string]string),
966-
PackageFile: make(map[string]string),
967-
Standard: make(map[string]bool),
962+
ID: a.Package.ImportPath,
963+
Compiler: cfg.BuildToolchainName,
964+
Dir: a.Package.Dir,
965+
GoFiles: mkAbsFiles(a.Package.Dir, gofiles),
966+
NonGoFiles: mkAbsFiles(a.Package.Dir, nongofiles),
967+
IgnoredFiles: mkAbsFiles(a.Package.Dir, ignored),
968+
ImportPath: a.Package.ImportPath,
969+
ImportMap: make(map[string]string),
970+
PackageFile: make(map[string]string),
971+
Standard: make(map[string]bool),
968972
}
969973
a.vetCfg = vcfg
970974
for i, raw := range a.Package.Internal.RawImports {

0 commit comments

Comments
 (0)