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

Delta Between Two Patch Sets: src/cmd/go/pkg.go

Issue 5595044: code review 5595044: cmd/go: add go tools to rearrangement (Closed)
Left Patch Set: diff -r e0f5f0f07741 https://code.google.com/p/go/ Created 13 years, 2 months ago
Right Patch Set: diff -r aad272ba37c8 https://code.google.com/p/go/ Created 13 years, 2 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 | « src/cmd/go/fix.go ('k') | src/cmd/go/vet.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 package main 5 package main
6 6
7 import ( 7 import (
8 "go/build" 8 "go/build"
9 "os" 9 "os"
10 "path/filepath" 10 "path/filepath"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 b = append(b, ' ') 217 b = append(b, ' ')
218 } 218 }
219 default: 219 default:
220 space = false 220 space = false
221 b = append(b, c) 221 b = append(b, c)
222 } 222 }
223 } 223 }
224 return string(b) 224 return string(b)
225 } 225 }
226 226
227 // isGoTool is the list of directories for Go programs that are installed in
228 // $GOROOT/bin/go-tool.
227 var isGoTool = map[string]bool{ 229 var isGoTool = map[string]bool{
228 » "fix": true, 230 » "cmd/fix": true,
229 » "vet": true, 231 » "cmd/vet": true,
230 » "yacc": true, 232 » "cmd/yacc": true,
231 } 233 }
232 234
233 func scanPackage(ctxt *build.Context, t *build.Tree, arg, importPath, dir string , stk *importStack) *Package { 235 func scanPackage(ctxt *build.Context, t *build.Tree, arg, importPath, dir string , stk *importStack) *Package {
234 // Read the files in the directory to learn the structure 236 // Read the files in the directory to learn the structure
235 // of the package. 237 // of the package.
236 p := &Package{ 238 p := &Package{
237 ImportPath: importPath, 239 ImportPath: importPath,
238 Dir: dir, 240 Dir: dir,
239 Standard: t.Goroot && !strings.Contains(importPath, "."), 241 Standard: t.Goroot && !strings.Contains(importPath, "."),
240 t: t, 242 t: t,
(...skipping 20 matching lines...) Expand all
261 p.XTestGoFiles = info.XTestGoFiles 263 p.XTestGoFiles = info.XTestGoFiles
262 p.CFiles = info.CFiles 264 p.CFiles = info.CFiles
263 p.HFiles = info.HFiles 265 p.HFiles = info.HFiles
264 p.SFiles = info.SFiles 266 p.SFiles = info.SFiles
265 p.CgoFiles = info.CgoFiles 267 p.CgoFiles = info.CgoFiles
266 p.CgoCFLAGS = info.CgoCFLAGS 268 p.CgoCFLAGS = info.CgoCFLAGS
267 p.CgoLDFLAGS = info.CgoLDFLAGS 269 p.CgoLDFLAGS = info.CgoLDFLAGS
268 270
269 if info.Package == "main" { 271 if info.Package == "main" {
270 _, elem := filepath.Split(importPath) 272 _, elem := filepath.Split(importPath)
271 » » if t.Goroot && isGoTool[elem] { 273 » » if t.Goroot && isGoTool[p.ImportPath] {
rsc 2012/01/29 18:51:11 I am a little worried about people hitting this ac
272 p.target = filepath.Join(t.Path, "bin/go-tool", elem) 274 p.target = filepath.Join(t.Path, "bin/go-tool", elem)
273 } else { 275 } else {
274 p.target = filepath.Join(t.BinDir(), elem) 276 p.target = filepath.Join(t.BinDir(), elem)
275 } 277 }
276 if ctxt.GOOS == "windows" { 278 if ctxt.GOOS == "windows" {
277 p.target += ".exe" 279 p.target += ".exe"
278 } 280 }
279 } else { 281 } else {
280 p.target = filepath.Join(t.PkgDir(), filepath.FromSlash(importPa th)+".a") 282 p.target = filepath.Join(t.PkgDir(), filepath.FromSlash(importPa th)+".a")
281 } 283 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // to load dependencies of a named package, the named 412 // to load dependencies of a named package, the named
411 // package is still returned, with p.Incomplete = true 413 // package is still returned, with p.Incomplete = true
412 // and details in p.DepsErrors. 414 // and details in p.DepsErrors.
413 func packages(args []string) []*Package { 415 func packages(args []string) []*Package {
414 args = importPaths(args) 416 args = importPaths(args)
415 var pkgs []*Package 417 var pkgs []*Package
416 var stk importStack 418 var stk importStack
417 for _, arg := range args { 419 for _, arg := range args {
418 pkg := loadPackage(arg, &stk) 420 pkg := loadPackage(arg, &stk)
419 if pkg.Error != nil { 421 if pkg.Error != nil {
420 » » » errorf("%s", pkg.Error) 422 » » » errorf("can't load package: %s", pkg.Error)
421 continue 423 continue
422 } 424 }
423 pkgs = append(pkgs, pkg) 425 pkgs = append(pkgs, pkg)
424 } 426 }
425 return pkgs 427 return pkgs
426 } 428 }
427 429
428 // packagesAndErrors is like 'packages' but returns a· 430 // packagesAndErrors is like 'packages' but returns a·
429 // *Package for every argument, even the ones that 431 // *Package for every argument, even the ones that
430 // cannot be loaded at all. 432 // cannot be loaded at all.
431 // The packages that fail to load will have p.Error != nil. 433 // The packages that fail to load will have p.Error != nil.
432 func packagesAndErrors(args []string) []*Package { 434 func packagesAndErrors(args []string) []*Package {
433 args = importPaths(args) 435 args = importPaths(args)
434 var pkgs []*Package 436 var pkgs []*Package
435 var stk importStack 437 var stk importStack
436 for _, arg := range args { 438 for _, arg := range args {
437 pkgs = append(pkgs, loadPackage(arg, &stk)) 439 pkgs = append(pkgs, loadPackage(arg, &stk))
438 } 440 }
439 return pkgs 441 return pkgs
440 } 442 }
441 443
442 // packagesForBuild is like 'packages' but fails if any of 444 // packagesForBuild is like 'packages' but fails if any of
443 // the packages or their dependencies have errors 445 // the packages or their dependencies have errors
444 // (cannot be built). 446 // (cannot be built).
445 func packagesForBuild(args []string) []*Package { 447 func packagesForBuild(args []string) []*Package {
446 pkgs := packagesAndErrors(args) 448 pkgs := packagesAndErrors(args)
447 printed := map[*PackageError]bool{} 449 printed := map[*PackageError]bool{}
448 for _, pkg := range pkgs { 450 for _, pkg := range pkgs {
449 if pkg.Error != nil { 451 if pkg.Error != nil {
450 » » » errorf("%s", pkg.Error) 452 » » » errorf("can't load package: %s", pkg.Error)
451 } 453 }
452 for _, err := range pkg.DepsErrors { 454 for _, err := range pkg.DepsErrors {
453 // Since these are errors in dependencies, 455 // Since these are errors in dependencies,
454 // the same error might show up multiple times, 456 // the same error might show up multiple times,
455 // once in each package that depends on it. 457 // once in each package that depends on it.
456 // Only print each once. 458 // Only print each once.
457 if !printed[err] { 459 if !printed[err] {
458 printed[err] = true 460 printed[err] = true
459 errorf("%s", err) 461 errorf("%s", err)
460 } 462 }
461 } 463 }
462 } 464 }
463 exitIfErrors() 465 exitIfErrors()
464 return pkgs 466 return pkgs
465 } 467 }
LEFTRIGHT

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