Skip to content

Commit

Permalink
go/build: add Package.IgnoredOtherFiles
Browse files Browse the repository at this point in the history
Just like it is useful to report ignored .go files,
it is also useful to report ignored non-.go files.

Also, remove _* and .* files from IgnoredGoFiles.
The fact that they were there at all was a mistake.
This list is for files being ignored due to build constraints.

Change-Id: Ie08252dde9f56bda08647e7ebeab7906e9271c54
Reviewed-on: https://go-review.googlesource.com/c/go/+/240551
Trust: Russ Cox <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
rsc committed Oct 12, 2020
1 parent e0cb80e commit 5acec48
Showing 1 changed file with 61 additions and 50 deletions.
111 changes: 61 additions & 50 deletions src/go/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,20 @@ type Package struct {
BinaryOnly bool // cannot be rebuilt from source (has //go:binary-only-package comment)

// Source files
GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
CgoFiles []string // .go source files that import "C"
IgnoredGoFiles []string // .go source files ignored for this build
InvalidGoFiles []string // .go source files with detected problems (parse error, wrong package name, and so on)
CFiles []string // .c source files
CXXFiles []string // .cc, .cpp and .cxx source files
MFiles []string // .m (Objective-C) source files
HFiles []string // .h, .hh, .hpp and .hxx source files
FFiles []string // .f, .F, .for and .f90 Fortran source files
SFiles []string // .s source files
SwigFiles []string // .swig files
SwigCXXFiles []string // .swigcxx files
SysoFiles []string // .syso system object files to add to archive
GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
CgoFiles []string // .go source files that import "C"
IgnoredGoFiles []string // .go source files ignored for this build (including ignored _test.go files)
InvalidGoFiles []string // .go source files with detected problems (parse error, wrong package name, and so on)
IgnoredOtherFiles []string // non-.go source files ignored for this build
CFiles []string // .c source files
CXXFiles []string // .cc, .cpp and .cxx source files
MFiles []string // .m (Objective-C) source files
HFiles []string // .h, .hh, .hpp and .hxx source files
FFiles []string // .f, .F, .for and .f90 Fortran source files
SFiles []string // .s source files
SwigFiles []string // .swig files
SwigCXXFiles []string // .swigcxx files
SysoFiles []string // .syso system object files to add to archive

// Cgo directives
CgoCFLAGS []string // Cgo CFLAGS directives
Expand Down Expand Up @@ -816,46 +817,28 @@ Found:
continue
}
if !match {
if ext == ".go" {
if strings.HasPrefix(name, "_") || strings.HasPrefix(name, ".") {
// not due to build constraints - don't report
} else if ext == ".go" {
p.IgnoredGoFiles = append(p.IgnoredGoFiles, name)
} else if fileListForExt(p, ext) != nil {
p.IgnoredOtherFiles = append(p.IgnoredOtherFiles, name)
}
continue
}

// Going to save the file. For non-Go files, can stop here.
switch ext {
case ".c":
p.CFiles = append(p.CFiles, name)
continue
case ".cc", ".cpp", ".cxx":
p.CXXFiles = append(p.CXXFiles, name)
continue
case ".m":
p.MFiles = append(p.MFiles, name)
continue
case ".h", ".hh", ".hpp", ".hxx":
p.HFiles = append(p.HFiles, name)
continue
case ".f", ".F", ".for", ".f90":
p.FFiles = append(p.FFiles, name)
continue
case ".s":
p.SFiles = append(p.SFiles, name)
continue
case ".go":
// keep going
case ".S", ".sx":
// special case for cgo, handled at end
Sfiles = append(Sfiles, name)
continue
case ".swig":
p.SwigFiles = append(p.SwigFiles, name)
continue
case ".swigcxx":
p.SwigCXXFiles = append(p.SwigCXXFiles, name)
continue
case ".syso":
// binary objects to add to package archive
// Likely of the form foo_windows.syso, but
// the name was vetted above with goodOSArchFile.
p.SysoFiles = append(p.SysoFiles, name)
default:
if list := fileListForExt(p, ext); list != nil {
*list = append(*list, name)
}
continue
}

Expand Down Expand Up @@ -996,6 +979,9 @@ Found:
if len(p.CgoFiles) > 0 {
p.SFiles = append(p.SFiles, Sfiles...)
sort.Strings(p.SFiles)
} else {
p.IgnoredOtherFiles = append(p.IgnoredOtherFiles, Sfiles...)
sort.Strings(p.IgnoredOtherFiles)
}

if badGoError != nil {
Expand All @@ -1007,6 +993,30 @@ Found:
return p, pkgerr
}

func fileListForExt(p *Package, ext string) *[]string {
switch ext {
case ".c":
return &p.CFiles
case ".cc", ".cpp", ".cxx":
return &p.CXXFiles
case ".m":
return &p.MFiles
case ".h", ".hh", ".hpp", ".hxx":
return &p.HFiles
case ".f", ".F", ".for", ".f90":
return &p.FFiles
case ".s", ".S", ".sx":
return &p.SFiles
case ".swig":
return &p.SwigFiles
case ".swigcxx":
return &p.SwigCXXFiles
case ".syso":
return &p.SysoFiles
}
return nil
}

var errNoModules = errors.New("not using modules")

// importGo checks whether it can use the go command to find the directory for path.
Expand Down Expand Up @@ -1302,6 +1312,8 @@ func (ctxt *Context) MatchFile(dir, name string) (match bool, err error) {
return
}

var dummyPkg Package

// matchFile determines whether the file with the given name in the given directory
// should be included in the package being constructed.
// It returns the data read from the file.
Expand All @@ -1326,16 +1338,15 @@ func (ctxt *Context) matchFile(dir, name string, allTags map[string]bool, binary
return
}

switch ext {
case ".go", ".c", ".cc", ".cxx", ".cpp", ".m", ".s", ".h", ".hh", ".hpp", ".hxx", ".f", ".F", ".f90", ".S", ".sx", ".swig", ".swigcxx":
// tentatively okay - read to make sure
case ".syso":
if ext != ".go" && fileListForExt(&dummyPkg, ext) == nil {
// skip
return
}

if ext == ".syso" {
// binary, no reading
match = true
return
default:
// skip
return
}

filename = ctxt.joinPath(dir, name)
Expand Down

0 comments on commit 5acec48

Please sign in to comment.