"errors"
"fmt"
"go/ast"
+ "go/build"
"go/build/constraint"
"go/token"
"io"
var defaultToolTags, defaultReleaseTags []string
-// A Package describes the Go package found in a directory.
-type Package struct {
- Dir string // directory containing package sources
- Name string // package name
- ImportComment string // path in import comment on package statement
- Doc string // documentation synopsis
- ImportPath string // import path of package ("" if unknown)
- Root string // root of Go tree where this package lives
- SrcRoot string // package source root directory ("" if unknown)
- PkgRoot string // package install root directory ("" if unknown)
- PkgTargetRoot string // architecture dependent install root directory ("" if unknown)
- BinDir string // command install directory ("" if unknown)
- Goroot bool // package found in Go root
- PkgObj string // installed .a file
- AllTags []string // tags that can influence file selection in this directory
- ConflictDir string // this directory shadows Dir in $GOPATH
- 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 (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
- CgoCPPFLAGS []string // Cgo CPPFLAGS directives
- CgoCXXFLAGS []string // Cgo CXXFLAGS directives
- CgoFFLAGS []string // Cgo FFLAGS directives
- CgoLDFLAGS []string // Cgo LDFLAGS directives
- CgoPkgConfig []string // Cgo pkg-config directives
-
- // Test information
- TestGoFiles []string // _test.go files in package
- XTestGoFiles []string // _test.go files outside package
-
- // Dependency information
- Imports []string // import paths from GoFiles, CgoFiles
- ImportPos map[string][]token.Position // line information for Imports
- TestImports []string // import paths from TestGoFiles
- TestImportPos map[string][]token.Position // line information for TestImports
- XTestImports []string // import paths from XTestGoFiles
- XTestImportPos map[string][]token.Position // line information for XTestImports
-
- // //go:embed patterns found in Go source files
- // For example, if a source file says
- // //go:embed a* b.c
- // then the list will contain those two strings as separate entries.
- // (See package embed for more details about //go:embed.)
- EmbedPatterns []string // patterns from GoFiles, CgoFiles
- EmbedPatternPos map[string][]token.Position // line information for EmbedPatterns
- TestEmbedPatterns []string // patterns from TestGoFiles
- TestEmbedPatternPos map[string][]token.Position // line information for TestEmbedPatterns
- XTestEmbedPatterns []string // patterns from XTestGoFiles
- XTestEmbedPatternPos map[string][]token.Position // line information for XTestEmbedPatternPos
-}
-
-// IsCommand reports whether the package is considered a
-// command to be installed (not just a library).
-// Packages named "main" are treated as commands.
-func (p *Package) IsCommand() bool {
- return p.Name == "main"
-}
-
// NoGoError is the error used by Import to describe a directory
// containing no buildable Go source files. (It may still contain
// test files, files hidden by build tags, and so on.)
return name[i:]
}
-func fileListForExt(p *Package, ext string) *[]string {
+func fileListForExt(p *build.Package, ext string) *[]string {
switch ext {
case ".c":
return &p.CFiles
return word, rest
}
-var dummyPkg Package
+var dummyPkg build.Package
// fileInfo records information learned about a file included in a build.
type fileInfo struct {
// saveCgo saves the information from the #cgo lines in the import "C" comment.
// These lines set CFLAGS, CPPFLAGS, CXXFLAGS and LDFLAGS and pkg-config directives
// that affect the way cgo's C code is built.
-func (ctxt *Context) saveCgo(filename string, di *Package, text string) error {
+func (ctxt *Context) saveCgo(filename string, di *build.Package, text string) error {
for _, line := range strings.Split(text, "\n") {
orig := line