LEFT | RIGHT |
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 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 if p.Error != nil && stk.shorterThan(p.Error.ImportStack) { | 272 if p.Error != nil && stk.shorterThan(p.Error.ImportStack) { |
273 p.Error.ImportStack = stk.copy() | 273 p.Error.ImportStack = stk.copy() |
274 } | 274 } |
275 return p | 275 return p |
276 } | 276 } |
277 | 277 |
278 // isGoTool is the list of directories for Go programs that are installed in | 278 // isGoTool is the list of directories for Go programs that are installed in |
279 // $GOROOT/pkg/tool. | 279 // $GOROOT/pkg/tool. |
280 var isGoTool = map[string]bool{ | 280 var isGoTool = map[string]bool{ |
281 » "cmd/api": true, | 281 » "cmd/api": true, |
282 » "cmd/cgo": true, | 282 » "cmd/cgo": true, |
283 » "cmd/fix": true, | 283 » "cmd/fix": true, |
284 » "cmd/vet": true, | 284 » "cmd/yacc": true, |
285 » "cmd/yacc": true, | 285 » "code.google.com/p/go.tools/cmd/vet": true, |
286 } | 286 } |
287 | 287 |
288 // expandScanner expands a scanner.List error into all the errors in the list. | 288 // expandScanner expands a scanner.List error into all the errors in the list. |
289 // The default Error method only shows the first error. | 289 // The default Error method only shows the first error. |
290 func expandScanner(err error) error { | 290 func expandScanner(err error) error { |
291 // Look for parser errors. | 291 // Look for parser errors. |
292 if err, ok := err.(scanner.ErrorList); ok { | 292 if err, ok := err.(scanner.ErrorList); ok { |
293 // Prepare error with \n before each message. | 293 // Prepare error with \n before each message. |
294 // When printed in something like context: %v | 294 // When printed in something like context: %v |
295 // this will put the leading file positions each on | 295 // this will put the leading file positions each on |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if p.Name == "main" { | 328 if p.Name == "main" { |
329 _, elem := filepath.Split(p.Dir) | 329 _, elem := filepath.Split(p.Dir) |
330 full := buildContext.GOOS + "_" + buildContext.GOARCH + "/" + el
em | 330 full := buildContext.GOOS + "_" + buildContext.GOARCH + "/" + el
em |
331 if buildContext.GOOS != toolGOOS || buildContext.GOARCH != toolG
OARCH { | 331 if buildContext.GOOS != toolGOOS || buildContext.GOARCH != toolG
OARCH { |
332 // Install cross-compiled binaries to subdirectories of
bin. | 332 // Install cross-compiled binaries to subdirectories of
bin. |
333 elem = full | 333 elem = full |
334 } | 334 } |
335 if p.build.BinDir != "" { | 335 if p.build.BinDir != "" { |
336 p.target = filepath.Join(p.build.BinDir, elem) | 336 p.target = filepath.Join(p.build.BinDir, elem) |
337 } | 337 } |
338 » » if p.Goroot && (isGoTool[p.ImportPath] || strings.HasPrefix(p.Im
portPath, "exp/")) { | 338 » » if isGoTool[p.ImportPath] { |
339 p.target = filepath.Join(gorootPkg, "tool", full) | 339 p.target = filepath.Join(gorootPkg, "tool", full) |
340 } | 340 } |
341 if p.target != "" && buildContext.GOOS == "windows" { | 341 if p.target != "" && buildContext.GOOS == "windows" { |
342 p.target += ".exe" | 342 p.target += ".exe" |
343 } | 343 } |
344 } else if p.local { | 344 } else if p.local { |
345 // Local import turned into absolute path. | 345 // Local import turned into absolute path. |
346 // No permanent install target. | 346 // No permanent install target. |
347 p.target = "" | 347 p.target = "" |
348 } else { | 348 } else { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 481 } |
482 | 482 |
483 return p | 483 return p |
484 } | 484 } |
485 | 485 |
486 // usesSwig returns whether the package needs to run SWIG. | 486 // usesSwig returns whether the package needs to run SWIG. |
487 func (p *Package) usesSwig() bool { | 487 func (p *Package) usesSwig() bool { |
488 return len(p.SwigFiles) > 0 || len(p.SwigCXXFiles) > 0 | 488 return len(p.SwigFiles) > 0 || len(p.SwigCXXFiles) > 0 |
489 } | 489 } |
490 | 490 |
| 491 // usesCgo returns whether the package needs to run cgo |
| 492 func (p *Package) usesCgo() bool { |
| 493 return len(p.CgoFiles) > 0 |
| 494 } |
| 495 |
491 // swigSoname returns the name of the shared library we create for a | 496 // swigSoname returns the name of the shared library we create for a |
492 // SWIG input file. | 497 // SWIG input file. |
493 func (p *Package) swigSoname(file string) string { | 498 func (p *Package) swigSoname(file string) string { |
494 return strings.Replace(p.ImportPath, "/", "-", -1) + "-" + strings.Repla
ce(file, ".", "-", -1) + ".so" | 499 return strings.Replace(p.ImportPath, "/", "-", -1) + "-" + strings.Repla
ce(file, ".", "-", -1) + ".so" |
495 } | 500 } |
496 | 501 |
497 // swigDir returns the name of the shared SWIG directory for a | 502 // swigDir returns the name of the shared SWIG directory for a |
498 // package. | 503 // package. |
499 func (p *Package) swigDir(ctxt *build.Context) string { | 504 func (p *Package) swigDir(ctxt *build.Context) string { |
500 dir := p.build.PkgRoot | 505 dir := p.build.PkgRoot |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 root = filepath.Clean(root) | 808 root = filepath.Clean(root) |
804 if !strings.HasSuffix(root, sep) { | 809 if !strings.HasSuffix(root, sep) { |
805 root += sep | 810 root += sep |
806 } | 811 } |
807 dir = filepath.Clean(dir) | 812 dir = filepath.Clean(dir) |
808 if !strings.HasPrefix(dir, root) { | 813 if !strings.HasPrefix(dir, root) { |
809 return "", false | 814 return "", false |
810 } | 815 } |
811 return filepath.ToSlash(dir[len(root):]), true | 816 return filepath.ToSlash(dir[len(root):]), true |
812 } | 817 } |
LEFT | RIGHT |