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 "fmt" | 8 "fmt" |
9 "os" | 9 "os" |
10 "os/exec" | 10 "os/exec" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if p.Name != "main" { | 64 if p.Name != "main" { |
65 fatalf("go run: cannot run non-main package") | 65 fatalf("go run: cannot run non-main package") |
66 } | 66 } |
67 p.target = "" // must build - not up to date | 67 p.target = "" // must build - not up to date |
68 var src string | 68 var src string |
69 if len(p.GoFiles) > 0 { | 69 if len(p.GoFiles) > 0 { |
70 src = p.GoFiles[0] | 70 src = p.GoFiles[0] |
71 } else if len(p.CgoFiles) > 0 { | 71 } else if len(p.CgoFiles) > 0 { |
72 src = p.CgoFiles[0] | 72 src = p.CgoFiles[0] |
73 } else { | 73 } else { |
74 » » fatalf("go run: no suitable source file (cgo disabled?)") | 74 » » // this case could only happen if the provided source uses cgo |
| 75 » » // while cgo is disabled. |
| 76 » » hint := "" |
| 77 » » if !buildContext.CgoEnabled { |
| 78 » » » hint = " (cgo is disabled)" |
| 79 » » } |
| 80 » » fatalf("go run: no suitable source files%s", hint) |
75 } | 81 } |
76 p.exeName = src[:len(src)-len(".go")] // name temporary executable for f
irst go file | 82 p.exeName = src[:len(src)-len(".go")] // name temporary executable for f
irst go file |
77 a1 := b.action(modeBuild, modeBuild, p) | 83 a1 := b.action(modeBuild, modeBuild, p) |
78 a := &action{f: (*builder).runProgram, args: cmdArgs, deps: []*action{a1
}} | 84 a := &action{f: (*builder).runProgram, args: cmdArgs, deps: []*action{a1
}} |
79 b.do(a) | 85 b.do(a) |
80 } | 86 } |
81 | 87 |
82 // runProgram is the action for running a binary that has already | 88 // runProgram is the action for running a binary that has already |
83 // been compiled. We ignore exit status. | 89 // been compiled. We ignore exit status. |
84 func (b *builder) runProgram(a *action) error { | 90 func (b *builder) runProgram(a *action) error { |
(...skipping 13 matching lines...) Expand all Loading... |
98 cmdline := stringList(cmdargs...) | 104 cmdline := stringList(cmdargs...) |
99 cmd := exec.Command(cmdline[0], cmdline[1:]...) | 105 cmd := exec.Command(cmdline[0], cmdline[1:]...) |
100 cmd.Stdin = os.Stdin | 106 cmd.Stdin = os.Stdin |
101 cmd.Stdout = os.Stdout | 107 cmd.Stdout = os.Stdout |
102 cmd.Stderr = os.Stderr | 108 cmd.Stderr = os.Stderr |
103 startSigHandlers() | 109 startSigHandlers() |
104 if err := cmd.Run(); err != nil { | 110 if err := cmd.Run(); err != nil { |
105 errorf("%v", err) | 111 errorf("%v", err) |
106 } | 112 } |
107 } | 113 } |
LEFT | RIGHT |