36
36
Root string `json:",omitempty"` // Go root or Go path dir containing this package
39
GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
40
CgoFiles []string `json:",omitempty"` // .go sources files that import "C"
41
CFiles []string `json:",omitempty"` // .c source files
42
HFiles []string `json:",omitempty"` // .h source files
43
SFiles []string `json:",omitempty"` // .s source files
44
SysoFiles []string `json:",omitempty"` // .syso system object files added to package
39
GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
40
CgoFiles []string `json:",omitempty"` // .go sources files that import "C"
41
IgnoredGoFiles []string `json:",omitempty"` // .go sources ignored due to build constraints
42
CFiles []string `json:",omitempty"` // .c source files
43
HFiles []string `json:",omitempty"` // .h source files
44
SFiles []string `json:",omitempty"` // .s source files
45
SysoFiles []string `json:",omitempty"` // .syso system object files added to package
46
SwigFiles []string `json:",omitempty"` // .swig files
47
SwigCXXFiles []string `json:",omitempty"` // .swigcxx files
47
50
CgoCFLAGS []string `json:",omitempty"` // cgo: flags for C compiler
71
74
gofiles []string // GoFiles+CgoFiles+TestGoFiles+XTestGoFiles files, absolute paths
76
allgofiles []string // gofiles + IgnoredGoFiles, absolute paths
72
77
target string // installed file for this package (may be executable)
73
78
fake bool // synthesized package
74
79
forceBuild bool // this package must be rebuilt
75
80
forceLibrary bool // this package is a library (even if named "main")
76
81
local bool // imported via local path (./ or ../)
77
82
localPrefix string // interpret ./ and ../ imports relative to this prefix
83
exeName string // desired name for temporary executable
80
86
func (p *Package) copyBuild(pp *build.Package) {
90
96
p.Standard = p.Goroot && p.ImportPath != "" && !strings.Contains(p.ImportPath, ".")
91
97
p.GoFiles = pp.GoFiles
92
98
p.CgoFiles = pp.CgoFiles
99
p.IgnoredGoFiles = pp.IgnoredGoFiles
93
100
p.CFiles = pp.CFiles
94
101
p.HFiles = pp.HFiles
95
102
p.SFiles = pp.SFiles
96
103
p.SysoFiles = pp.SysoFiles
104
p.SwigFiles = pp.SwigFiles
105
p.SwigCXXFiles = pp.SwigCXXFiles
97
106
p.CgoCFLAGS = pp.CgoCFLAGS
98
107
p.CgoLDFLAGS = pp.CgoLDFLAGS
99
108
p.CgoPkgConfig = pp.CgoPkgConfig
117
126
// is the most important thing.
118
127
return p.Pos + ": " + p.Err
129
if len(p.ImportStack) == 0 {
120
132
return "package " + strings.Join(p.ImportStack, "\n\timports ") + ": " + p.Err
316
326
// Install cross-compiled binaries to subdirectories of bin.
319
p.target = filepath.Join(p.build.BinDir, elem)
320
if p.Goroot && isGoTool[p.ImportPath] {
329
if p.build.BinDir != "" {
330
p.target = filepath.Join(p.build.BinDir, elem)
332
if p.Goroot && (isGoTool[p.ImportPath] || strings.HasPrefix(p.ImportPath, "exp/")) {
321
333
p.target = filepath.Join(gorootPkg, "tool", full)
323
if buildContext.GOOS == "windows" {
335
if p.target != "" && buildContext.GOOS == "windows" {
324
336
p.target += ".exe"
326
338
} else if p.local {
340
352
// Everything depends on runtime, except runtime and unsafe.
341
353
if !p.Standard || (p.ImportPath != "runtime" && p.ImportPath != "unsafe") {
342
354
importPaths = append(importPaths, "runtime")
355
// When race detection enabled everything depends on runtime/race.
356
// Exclude runtime/cgo and cmd/cgo to avoid circular dependencies.
357
if buildRace && (!p.Standard || (p.ImportPath != "runtime/race" && p.ImportPath != "runtime/cgo" && p.ImportPath != "cmd/cgo")) {
358
importPaths = append(importPaths, "runtime/race")
345
362
// Build list of full paths to all Go files in the package,
351
368
sort.Strings(p.gofiles)
370
p.sfiles = stringList(p.SFiles)
371
for i := range p.sfiles {
372
p.sfiles[i] = filepath.Join(p.Dir, p.sfiles[i])
374
sort.Strings(p.sfiles)
376
p.allgofiles = stringList(p.IgnoredGoFiles)
377
for i := range p.allgofiles {
378
p.allgofiles[i] = filepath.Join(p.Dir, p.allgofiles[i])
380
p.allgofiles = append(p.allgofiles, p.gofiles...)
381
sort.Strings(p.allgofiles)
383
// Check for case-insensitive collision of input files.
384
// To avoid problems on case-insensitive files, we reject any package
385
// where two different input files have equal names under a case-insensitive
387
f1, f2 := foldDup(stringList(
401
p.Error = &PackageError{
402
ImportStack: stk.copy(),
403
Err: fmt.Sprintf("case-insensitive file name collision: %q and %q", f1, f2),
353
408
// Build list of imported packages and full dependency list.
354
409
imports := make([]*Package, 0, len(p.Imports))
355
410
deps := make(map[string]bool)
403
458
if p.Standard && (p.ImportPath == "unsafe" || buildContext.Compiler == "gccgo") {
407
461
p.Target = p.target
463
// In the absence of errors lower in the dependency tree,
464
// check for case-insensitive collisions of import paths.
465
if len(p.DepsErrors) == 0 {
466
dep1, dep2 := foldDup(p.Deps)
468
p.Error = &PackageError{
469
ImportStack: stk.copy(),
470
Err: fmt.Sprintf("case-insensitive import collision: %q and %q", dep1, dep2),
479
// usesSwig returns whether the package needs to run SWIG.
480
func (p *Package) usesSwig() bool {
481
return len(p.SwigFiles) > 0 || len(p.SwigCXXFiles) > 0
484
// swigSoname returns the name of the shared library we create for a
486
func (p *Package) swigSoname(file string) string {
487
return strings.Replace(p.ImportPath, "/", "-", -1) + "-" + strings.Replace(file, ".", "-", -1) + ".so"
490
// swigDir returns the name of the shared SWIG directory for a
492
func (p *Package) swigDir(ctxt *build.Context) string {
493
dir := p.build.PkgRoot
494
if ctxt.Compiler == "gccgo" {
495
dir = filepath.Join(dir, "gccgo_"+ctxt.GOOS+"_"+ctxt.GOARCH)
497
dir = filepath.Join(dir, ctxt.GOOS+"_"+ctxt.GOARCH)
499
return filepath.Join(dir, "swig")
411
502
// packageList returns the list of packages in the dag rooted at roots
412
503
// as visited in a depth-first post-order traversal.
413
504
func packageList(roots []*Package) []*Package {
491
582
// As a courtesy to developers installing new versions of the compiler
492
583
// frequently, define that packages are stale if they are
493
584
// older than the compiler, and commands if they are older than
494
// the linker. This heuristic will not work if the binaries are back-dated,
495
// as some binary distributions may do, but it does handle a very
496
// common case. See issue 3036.
497
if olderThan(buildToolchain.compiler()) {
500
if p.build.IsCommand() && olderThan(buildToolchain.linker()) {
585
// the linker. This heuristic will not work if the binaries are
586
// back-dated, as some binary distributions may do, but it does handle
587
// a very common case.
589
// Assume code in $GOROOT is up to date, since it may not be writeable.
591
if p.Root != goroot {
592
if olderThan(buildToolchain.compiler()) {
595
if p.build.IsCommand() && olderThan(buildToolchain.linker()) {
504
600
// Have installed copy, probably built using current compilers,
621
for _, src := range stringList(p.SwigFiles, p.SwigCXXFiles) {
622
if olderThan(filepath.Join(p.Dir, src)) {
625
soname := p.swigSoname(src)
626
fi, err := os.Stat(soname)
630
fiSrc, err := os.Stat(src)
631
if err != nil || fiSrc.ModTime().After(fi.ModTime()) {
549
if strings.HasPrefix(arg, "cmd/") && !strings.Contains(arg[4:], "/") {
660
if strings.HasPrefix(arg, "cmd/") {
550
661
if p := cmdCache[arg]; p != nil {
555
bp, err := build.ImportDir(filepath.Join(gorootSrc, arg), 0)
667
if strings.Contains(arg[4:], "/") {
669
Error: &PackageError{
670
ImportStack: stk.copy(),
671
Err: fmt.Sprintf("invalid import path: cmd/... is reserved for Go commands"),
677
bp, err := buildContext.ImportDir(filepath.Join(gorootSrc, arg), 0)
556
678
bp.ImportPath = arg
558
680
bp.BinDir = gorootBin
580
702
// referring to io/ioutil rather than a hypothetical import of
582
704
if build.IsLocalImport(arg) {
583
bp, _ := build.ImportDir(filepath.Join(cwd, arg), build.FindOnly)
705
bp, _ := buildContext.ImportDir(filepath.Join(cwd, arg), build.FindOnly)
584
706
if bp.ImportPath != "" && bp.ImportPath != "." {
585
707
arg = bp.ImportPath
621
743
args = importPaths(args)
622
744
var pkgs []*Package
623
745
var stk importStack
746
var set = make(map[string]bool)
624
748
for _, arg := range args {
625
pkgs = append(pkgs, loadPackage(arg, &stk))
750
pkgs = append(pkgs, loadPackage(arg, &stk))
628
754
computeStale(pkgs...)