Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(21)

Delta Between Two Patch Sets: src/cmd/api/goapi.go

Issue 12699048: code review 12699048: cmd/api: eliminate duplicate package import work (Closed)
Left Patch Set: diff -r 4fb48ae1b069 https://code.google.com/p/go/ Created 11 years, 7 months ago
Right Patch Set: diff -r 04726e184720 https://code.google.com/p/go/ Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/cmd/api/run.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build api_tool 5 // +build api_tool
6 6
7 // Binary api computes the exported API of a set of Go packages. 7 // Binary api computes the exported API of a set of Go packages.
8 package main 8 package main
9 9
10 import ( 10 import (
(...skipping 21 matching lines...) Expand all
32 32
33 // Flags 33 // Flags
34 var ( 34 var (
35 checkFile = flag.String("c", "", "optional comma-separated filename(s) to check API against") 35 checkFile = flag.String("c", "", "optional comma-separated filename(s) to check API against")
36 allowNew = flag.Bool("allow_new", true, "allow API additions") 36 allowNew = flag.Bool("allow_new", true, "allow API additions")
37 exceptFile = flag.String("except", "", "optional filename of packages th at are allowed to change without triggering a failure in the tool") 37 exceptFile = flag.String("except", "", "optional filename of packages th at are allowed to change without triggering a failure in the tool")
38 nextFile = flag.String("next", "", "optional filename of tentative upc oming API features for the next release. This file can be lazily maintained. It only affects the delta warnings from the -c file printed on success.") 38 nextFile = flag.String("next", "", "optional filename of tentative upc oming API features for the next release. This file can be lazily maintained. It only affects the delta warnings from the -c file printed on success.")
39 verbose = flag.Bool("v", false, "verbose debugging") 39 verbose = flag.Bool("v", false, "verbose debugging")
40 forceCtx = flag.String("contexts", "", "optional comma-separated list of <goos>-<goarch>[-cgo] to override default contexts.") 40 forceCtx = flag.String("contexts", "", "optional comma-separated list of <goos>-<goarch>[-cgo] to override default contexts.")
41 ) 41 )
42
43 var ourTags = map[string]bool{}
bradfitz 2013/08/09 21:41:29 add a comment. // ourTags is the set of tags we c
gri 2013/08/09 21:46:42 I see this being assigned to, but never used. dreg
rsc 2013/08/09 22:38:07 Yes, gone.
44 42
45 // contexts are the default contexts which are scanned, unless 43 // contexts are the default contexts which are scanned, unless
46 // overridden by the -contexts flag. 44 // overridden by the -contexts flag.
47 var contexts = []*build.Context{ 45 var contexts = []*build.Context{
48 {GOOS: "linux", GOARCH: "386", CgoEnabled: true}, 46 {GOOS: "linux", GOARCH: "386", CgoEnabled: true},
49 {GOOS: "linux", GOARCH: "386"}, 47 {GOOS: "linux", GOARCH: "386"},
50 {GOOS: "linux", GOARCH: "amd64", CgoEnabled: true}, 48 {GOOS: "linux", GOARCH: "amd64", CgoEnabled: true},
51 {GOOS: "linux", GOARCH: "amd64"}, 49 {GOOS: "linux", GOARCH: "amd64"},
52 {GOOS: "linux", GOARCH: "arm", CgoEnabled: true}, 50 {GOOS: "linux", GOARCH: "arm", CgoEnabled: true},
53 {GOOS: "linux", GOARCH: "arm"}, 51 {GOOS: "linux", GOARCH: "arm"},
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 fmt.Printf("Go version is %q, ignoring -next %s\n", runt ime.Version(), *nextFile) 115 fmt.Printf("Go version is %q, ignoring -next %s\n", runt ime.Version(), *nextFile)
118 *nextFile = "" 116 *nextFile = ""
119 } 117 }
120 } 118 }
121 119
122 if *forceCtx != "" { 120 if *forceCtx != "" {
123 setContexts() 121 setContexts()
124 } 122 }
125 for _, c := range contexts { 123 for _, c := range contexts {
126 c.Compiler = build.Default.Compiler 124 c.Compiler = build.Default.Compiler
127 » » ourTags[c.GOOS] = true 125 » }
128 » » ourTags[c.GOARCH] = true
129 » }
130 » ourTags["cgo"] = true
131 126
132 var pkgNames []string 127 var pkgNames []string
133 if flag.NArg() > 0 { 128 if flag.NArg() > 0 {
134 pkgNames = flag.Args() 129 pkgNames = flag.Args()
135 } else { 130 } else {
136 stds, err := exec.Command("go", "list", "std").Output() 131 stds, err := exec.Command("go", "list", "std").Output()
137 if err != nil { 132 if err != nil {
138 log.Fatal(err) 133 log.Fatal(err)
139 } 134 }
140 pkgNames = strings.Fields(string(stds)) 135 pkgNames = strings.Fields(string(stds))
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 380
386 func contains(list []string, s string) bool { 381 func contains(list []string, s string) bool {
387 for _, t := range list { 382 for _, t := range list {
388 if t == s { 383 if t == s {
389 return true 384 return true
390 } 385 }
391 } 386 }
392 return false 387 return false
393 } 388 }
394 389
395 var ( 390 var (
gri 2013/08/09 21:46:42 please add comment about the key // maps tag-base
rsc 2013/08/09 22:38:07 Done.
396 » pkgCache = map[string]*types.Package{} 391 » pkgCache = map[string]*types.Package{} // map tagKey to package
397 » pkgTags = map[string][]string{} 392 » pkgTags = map[string][]string{} // map import dir to list of rele vant tags
gri 2013/08/09 21:46:42 same here
rsc 2013/08/09 22:38:07 Done.
398 ) 393 )
399 394
400 // tagKey returns the tag-based key to use in the pkgCache. 395 // tagKey returns the tag-based key to use in the pkgCache.
401 // It is a comma-separated string; the first part is dir, the rest tags. 396 // It is a comma-separated string; the first part is dir, the rest tags.
bradfitz 2013/08/09 21:41:29 we have structs that support == nowadays. just ma
rsc 2013/08/09 22:38:07 I'd still need the comma-separated key list since
402 // The satisfied tags are derived from context but only those that 397 // The satisfied tags are derived from context but only those that
403 // matter (the ones listed in the tags argument) are used. 398 // matter (the ones listed in the tags argument) are used.
399 // The tags list, which came from go/build's Package.AllTags,
400 // is known to be sorted.
404 func tagKey(dir string, context *build.Context, tags []string) string { 401 func tagKey(dir string, context *build.Context, tags []string) string {
405 ctags := map[string]bool{ 402 ctags := map[string]bool{
406 context.GOOS: true, 403 context.GOOS: true,
407 context.GOARCH: true, 404 context.GOARCH: true,
408 } 405 }
409 if context.CgoEnabled { 406 if context.CgoEnabled {
410 ctags["cgo"] = true 407 ctags["cgo"] = true
411 } 408 }
412 for _, tag := range context.BuildTags { 409 for _, tag := range context.BuildTags {
413 ctags[tag] = true 410 ctags[tag] = true
414 } 411 }
415 // TODO: ReleaseTags (need to load default) 412 // TODO: ReleaseTags (need to load default)
416 key := dir 413 key := dir
bradfitz 2013/08/09 21:41:29 var keyTags []string for _, tag := range tags {
rsc 2013/08/09 22:38:07 The AllTags list is sorted, and the tags list came
417 for _, tag := range tags { 414 for _, tag := range tags {
418 if ctags[tag] { 415 if ctags[tag] {
419 key += "," + tag 416 key += "," + tag
420 } 417 }
421 } 418 }
422 return key 419 return key
423 } 420 }
424 421
425 // Importing is a sentinel taking the place in Walker.imported 422 // Importing is a sentinel taking the place in Walker.imported
426 // for a package that is in the process of being imported. 423 // for a package that is in the process of being imported.
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 837
841 if _, dup := w.features[f]; dup { 838 if _, dup := w.features[f]; dup {
842 panic("duplicate feature inserted: " + f) 839 panic("duplicate feature inserted: " + f)
843 } 840 }
844 w.features[f] = true 841 w.features[f] = true
845 842
846 if *verbose { 843 if *verbose {
847 log.Printf("feature: %s", f) 844 log.Printf("feature: %s", f)
848 } 845 }
849 } 846 }
LEFTRIGHT
« no previous file | src/cmd/api/run.go » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b