/
packages.go
250 lines (204 loc) · 7.87 KB
/
packages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Licensed Materials - Property of IBM
// Copyright IBM Corp. 2023.
// US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
package packages
import (
"go/ast"
"go/token"
"go/types"
)
// These shouldn't change so we can have these as globals for easy reference
var Goos string
var BuildTags map[string]bool
var globalpkgs map[string]*Package = make(map[string]*Package, 50)
func ClearGlobalpkgs() {
globalpkgs = make(map[string]*Package, 50)
}
type ProcGroup struct {
Packages []*Package
Next *ProcGroup
Level int
}
// Information regarding how the package was discovered
type RefType uint8
const (
Inactive RefType = iota // Package is unused in default configuration
Dependency // Package would be built as it is dependended upon
Main // Package was specified in provided arguments
)
// Additional configuration options for load behaviour
type LoadOption uint
const (
LoadHaltMistyped LoadOption = 1 << iota // Halt loading on mistyped (reserved for stdlib packages)
LoadAllConfigs // Load all source files and parse configs
)
// State for validation during loading
type ldcolor uint8
const (
// Stage 1 mask values
unloaded ldcolor = iota
firstload
// Stage 2 mask values
searchable
searching
searched
)
type Package struct {
// Metadata
Dir string
ImportPath string
Name string
Goroot bool
Export string
Module *Module
// Layer the package is on
Layer *ProcGroup
// Used in / Imported packages
Parents []*Package
Imports map[string]*Package
// Build Configurations
//
// Index 0 is the default build configuration
// The rest are ordered using the most generic unix-like ordering (see tags.go)
Configs []BuildConfig
// Active config
//
// Config to use when attempting a build
CfgIdx int
// Map file names and their import names to paths
FileImports map[string]map[string]string
// Fileset for loading all files for this package
Fset *token.FileSet
// Whether or not the package would actually get built in the default environment
Active bool
// Flags used for external processing (the porting package uses this, has no impact on load)
ExtFlags uint8
// Mark used for performing DFS
color ldcolor
// Partially loaded type data
Types *types.Package
// Any errors that occurred during load
Errors []error
}
func (pkg *Package) String() string {
if pkg == nil {
return "<nil>"
}
return pkg.ImportPath
}
type GoFile struct {
Name string
Syntax *ast.File
IsCgo bool
}
type ExtGoFile struct {
Path string
Syntax *ast.File
Meta any
}
func (gf *GoFile) String() string {
if gf == nil {
return "<nil>"
}
return gf.Name
}
type BuildConfig struct {
Platforms []string
GoFiles []*GoFile
Syntax []*ast.File
Override map[string]*ExtGoFile
}
type Importer func(path string) (*types.Package, error)
type iImporter Importer
func (f iImporter) Import(path string) (*types.Package, error) {
return f(path)
}
// Fields that are commented out are provided by go-list
// however that are not need by wharf so leave them
// commented out in case they ever do become useful
type RawPackage struct {
Dir string // directory containing package sources
ImportPath string // import path of package in dir
// ImportComment string // path in import comment on package statement
Name string // package name
// Shlib string // the shared library that contains this package (only set when -linkshared)
Goroot bool // is this package in the Go root?
Standard bool // is this package part of the standard Go library?
// Stale bool // would 'go install' do anything for this package?
// StaleReason string // explanation for Stale==true
// Root string // Go root or Go path dir containing this package
// ConflictDir string // this directory shadows Dir in $GOPATH
// BinaryOnly bool // binary-only package (no longer supported)
// ForTest string // package is only for use in named test
Export string // file containing export data (when using -export)
// BuildID string // build ID of the compiled package (when using -export)
Module *Module // info about package's containing module, if any (can be nil)
Match []string // command-line patterns matching this package
DepOnly bool // package is only a dependency, not explicitly
// Source files
GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
CgoFiles []string // .go source files that import "C"
// CompiledGoFiles []string // .go files presented to compiler (when using -compiled)
IgnoredGoFiles []string // .go source files ignored due to build constraints
// IgnoredOtherFiles []string // non-.go source files ignored due to build constraints
// CFiles []string // .c source files
// CXXFiles []string // .cc, .cxx and .cpp source files
// MFiles []string // .m 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 object files to add to archive
// TestGoFiles []string // _test.go files in package
// XTestGoFiles []string // _test.go files outside package
// Embedded files
// EmbedPatterns []string // //go:embed patterns
// EmbedFiles []string // files matched by EmbedPatterns
// TestEmbedPatterns []string // //go:embed patterns in TestGoFiles
// TestEmbedFiles []string // files matched by TestEmbedPatterns
// XTestEmbedPatterns []string // //go:embed patterns in XTestGoFiles
// XTestEmbedFiles []string // files matched by XTestEmbedPatterns
// Cgo directives
// CgoCFLAGS []string // cgo: flags for C compiler
// CgoCPPFLAGS []string // cgo: flags for C preprocessor
// CgoCXXFLAGS []string // cgo: flags for C++ compiler
// CgoFFLAGS []string // cgo: flags for Fortran compiler
// CgoLDFLAGS []string // cgo: flags for linker
// CgoPkgConfig []string // cgo: pkg-config names
// Dependency information
Imports []string // import paths used by this package
ImportMap map[string]string // map from source import to ImportPath (identity entries omitted)
// Deps []string // all (recursively) imported dependencies
// TestImports []string // imports from TestGoFiles
// XTestImports []string // imports from XTestGoFiles
// Error information
Incomplete bool // this package or a dependency has an error
Error *rawPackageError // error loading package
DepsErrors []*rawPackageError // errors loading dependencies
}
type rawPackageError struct {
ImportStack []string // shortest path from package named on command line to this one
Pos string // position of error (if present, file:line:col)
Err string // the error itself
}
type Module struct {
Path string // module path
// Query string // version query corresponding to this version
Version string // module version
// Versions []string // available module versions
Replace *Module // replaced by this module
// Time *time.Time // time version was created
// Update *Module // available update (with -u)
Main bool // is this the main module?
Indirect bool // module is only indirectly needed by main module
Dir string // directory holding local copy of files, if any
GoMod string // path to go.mod file describing module, if any
GoVersion string // go version used in module
// Retracted []string // retraction information, if any (with -retracted or -u)
// Deprecated string // deprecation message, if any (with -u)
Error *ModuleError // error loading module
}
type ModuleError struct {
Err string // the error itself
}