~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/go/pkg.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        Root       string `json:",omitempty"` // Go root or Go path dir containing this package
37
37
 
38
38
        // Source files
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
45
48
 
46
49
        // Cgo directives
47
50
        CgoCFLAGS    []string `json:",omitempty"` // cgo: flags for C compiler
69
72
        imports      []*Package
70
73
        deps         []*Package
71
74
        gofiles      []string // GoFiles+CgoFiles+TestGoFiles+XTestGoFiles files, absolute paths
 
75
        sfiles       []string
 
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
78
84
}
79
85
 
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
119
128
        }
 
129
        if len(p.ImportStack) == 0 {
 
130
                return p.Err
 
131
        }
120
132
        return "package " + strings.Join(p.ImportStack, "\n\timports ") + ": " + p.Err
121
133
}
122
134
 
246
258
                if p.Error == nil {
247
259
                        p.Error = &PackageError{
248
260
                                ImportStack: stk.copy(),
249
 
                                Err:         "import loop",
 
261
                                Err:         "import cycle not allowed",
250
262
                        }
251
263
                }
252
264
                p.Incomplete = true
260
272
// isGoTool is the list of directories for Go programs that are installed in
261
273
// $GOROOT/pkg/tool.
262
274
var isGoTool = map[string]bool{
263
 
        "cmd/api":      true,
264
 
        "cmd/cgo":      true,
265
 
        "cmd/fix":      true,
266
 
        "cmd/vet":      true,
267
 
        "cmd/yacc":     true,
268
 
        "exp/gotype":   true,
269
 
        "exp/ebnflint": true,
 
275
        "cmd/api":  true,
 
276
        "cmd/cgo":  true,
 
277
        "cmd/fix":  true,
 
278
        "cmd/vet":  true,
 
279
        "cmd/yacc": true,
270
280
}
271
281
 
272
282
// expandScanner expands a scanner.List error into all the errors in the list.
316
326
                        // Install cross-compiled binaries to subdirectories of bin.
317
327
                        elem = full
318
328
                }
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)
 
331
                }
 
332
                if p.Goroot && (isGoTool[p.ImportPath] || strings.HasPrefix(p.ImportPath, "exp/")) {
321
333
                        p.target = filepath.Join(gorootPkg, "tool", full)
322
334
                }
323
 
                if buildContext.GOOS == "windows" {
 
335
                if p.target != "" && buildContext.GOOS == "windows" {
324
336
                        p.target += ".exe"
325
337
                }
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")
 
359
                }
343
360
        }
344
361
 
345
362
        // Build list of full paths to all Go files in the package,
350
367
        }
351
368
        sort.Strings(p.gofiles)
352
369
 
 
370
        p.sfiles = stringList(p.SFiles)
 
371
        for i := range p.sfiles {
 
372
                p.sfiles[i] = filepath.Join(p.Dir, p.sfiles[i])
 
373
        }
 
374
        sort.Strings(p.sfiles)
 
375
 
 
376
        p.allgofiles = stringList(p.IgnoredGoFiles)
 
377
        for i := range p.allgofiles {
 
378
                p.allgofiles[i] = filepath.Join(p.Dir, p.allgofiles[i])
 
379
        }
 
380
        p.allgofiles = append(p.allgofiles, p.gofiles...)
 
381
        sort.Strings(p.allgofiles)
 
382
 
 
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
 
386
        // comparison.
 
387
        f1, f2 := foldDup(stringList(
 
388
                p.GoFiles,
 
389
                p.CgoFiles,
 
390
                p.IgnoredGoFiles,
 
391
                p.CFiles,
 
392
                p.HFiles,
 
393
                p.SFiles,
 
394
                p.SysoFiles,
 
395
                p.SwigFiles,
 
396
                p.SwigCXXFiles,
 
397
                p.TestGoFiles,
 
398
                p.XTestGoFiles,
 
399
        ))
 
400
        if f1 != "" {
 
401
                p.Error = &PackageError{
 
402
                        ImportStack: stk.copy(),
 
403
                        Err:         fmt.Sprintf("case-insensitive file name collision: %q and %q", f1, f2),
 
404
                }
 
405
                return p
 
406
        }
 
407
 
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") {
404
459
                p.target = ""
405
460
        }
406
 
 
407
461
        p.Target = p.target
 
462
 
 
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)
 
467
                if dep1 != "" {
 
468
                        p.Error = &PackageError{
 
469
                                ImportStack: stk.copy(),
 
470
                                Err:         fmt.Sprintf("case-insensitive import collision: %q and %q", dep1, dep2),
 
471
                        }
 
472
                        return p
 
473
                }
 
474
        }
 
475
 
408
476
        return p
409
477
}
410
478
 
 
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
 
482
}
 
483
 
 
484
// swigSoname returns the name of the shared library we create for a
 
485
// SWIG input file.
 
486
func (p *Package) swigSoname(file string) string {
 
487
        return strings.Replace(p.ImportPath, "/", "-", -1) + "-" + strings.Replace(file, ".", "-", -1) + ".so"
 
488
}
 
489
 
 
490
// swigDir returns the name of the shared SWIG directory for a
 
491
// package.
 
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)
 
496
        } else {
 
497
                dir = filepath.Join(dir, ctxt.GOOS+"_"+ctxt.GOARCH)
 
498
        }
 
499
        return filepath.Join(dir, "swig")
 
500
}
 
501
 
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 {
459
550
        // distributions of Go packages, although such binaries are
460
551
        // only useful with the specific version of the toolchain that
461
552
        // created them.
462
 
        if len(p.gofiles) == 0 {
 
553
        if len(p.gofiles) == 0 && !p.usesSwig() {
463
554
                return false
464
555
        }
465
556
 
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()) {
498
 
                return true
499
 
        }
500
 
        if p.build.IsCommand() && olderThan(buildToolchain.linker()) {
501
 
                return true
 
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.
 
588
        // See issue 3036.
 
589
        // Assume code in $GOROOT is up to date, since it may not be writeable.
 
590
        // See issue 4106.
 
591
        if p.Root != goroot {
 
592
                if olderThan(buildToolchain.compiler()) {
 
593
                        return true
 
594
                }
 
595
                if p.build.IsCommand() && olderThan(buildToolchain.linker()) {
 
596
                        return true
 
597
                }
502
598
        }
503
599
 
504
600
        // Have installed copy, probably built using current compilers,
522
618
                }
523
619
        }
524
620
 
 
621
        for _, src := range stringList(p.SwigFiles, p.SwigCXXFiles) {
 
622
                if olderThan(filepath.Join(p.Dir, src)) {
 
623
                        return true
 
624
                }
 
625
                soname := p.swigSoname(src)
 
626
                fi, err := os.Stat(soname)
 
627
                if err != nil {
 
628
                        return true
 
629
                }
 
630
                fiSrc, err := os.Stat(src)
 
631
                if err != nil || fiSrc.ModTime().After(fi.ModTime()) {
 
632
                        return true
 
633
                }
 
634
        }
 
635
 
525
636
        return false
526
637
}
527
638
 
546
657
                        arg = sub
547
658
                }
548
659
        }
549
 
        if strings.HasPrefix(arg, "cmd/") && !strings.Contains(arg[4:], "/") {
 
660
        if strings.HasPrefix(arg, "cmd/") {
550
661
                if p := cmdCache[arg]; p != nil {
551
662
                        return p
552
663
                }
553
664
                stk.push(arg)
554
665
                defer stk.pop()
555
 
                bp, err := build.ImportDir(filepath.Join(gorootSrc, arg), 0)
 
666
 
 
667
                if strings.Contains(arg[4:], "/") {
 
668
                        p := &Package{
 
669
                                Error: &PackageError{
 
670
                                        ImportStack: stk.copy(),
 
671
                                        Err:         fmt.Sprintf("invalid import path: cmd/... is reserved for Go commands"),
 
672
                                },
 
673
                        }
 
674
                        return p
 
675
                }
 
676
 
 
677
                bp, err := buildContext.ImportDir(filepath.Join(gorootSrc, arg), 0)
556
678
                bp.ImportPath = arg
557
679
                bp.Goroot = true
558
680
                bp.BinDir = gorootBin
580
702
        // referring to io/ioutil rather than a hypothetical import of
581
703
        // "./ioutil".
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
586
708
                }
621
743
        args = importPaths(args)
622
744
        var pkgs []*Package
623
745
        var stk importStack
 
746
        var set = make(map[string]bool)
 
747
 
624
748
        for _, arg := range args {
625
 
                pkgs = append(pkgs, loadPackage(arg, &stk))
 
749
                if !set[arg] {
 
750
                        pkgs = append(pkgs, loadPackage(arg, &stk))
 
751
                        set[arg] = true
 
752
                }
626
753
        }
627
 
 
628
754
        computeStale(pkgs...)
629
755
 
630
756
        return pkgs