Skip to content

Commit

Permalink
[dev.cc] all: merge default (8d42099cdc23) into dev.cc
Browse files Browse the repository at this point in the history
TBR=austin
CC=golang-codereviews
https://golang.org/cl/178700044
  • Loading branch information
rsc committed Dec 5, 2014
2 parents e04c8b0 + 41c6b84 commit 829b286
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 58 deletions.
1 change: 1 addition & 0 deletions .hgtags
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ f44017549ff9c3cc5eef74ebe7276cd0dfc066b6 go1.3.3
f44017549ff9c3cc5eef74ebe7276cd0dfc066b6 release
1fdfd7dfaedb1b7702141617e621ab7328a236a1 go1.4beta1
bffdd0cae380ce1ccf3e98ed6b6cd53fece7ba72 go1.4rc1
6c4e66ae713704840fcea78c8055b44ba86ae5ea go1.4rc2
21 changes: 8 additions & 13 deletions doc/contrib.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ <h3 id="announce"><a href="//groups.google.com/group/golang-announce">Announceme
<h2 id="go1">Version history</h2>

<h3 id="release"><a href="/doc/devel/release.html">Release History</a></h3>
<p>A summary of the changes between Go releases.</p>

<h4 id="go1notes"><a href="/doc/go1">Go 1 Release Notes</a></h4>
<p>
A guide for updating your code to work with Go 1.
</p>
<p>A <a href="/doc/devel/release.html">summary</a> of the changes between Go releases. Notes for the major releases:</p>

<h4 id="release notes"><a href="/doc/go1.1">Go 1.1 Release Notes</a></h4>
<p>
A list of significant changes in Go 1.1, with instructions for updating
your code where necessary.
Each point release includes a similar document appropriate for that
release: <a href="/doc/go1.2">Go 1.2</a>, <a href="/doc/go1.3">Go 1.3</a>,
and so on.
</p>
<ul>
<li><a href="/doc/go1.4">Go 1.4</a> <small>(December 2014)</small></li>
<li><a href="/doc/go1.3">Go 1.3</a> <small>(June 2014)</small></li>
<li><a href="/doc/go1.2">Go 1.2</a> <small>(December 2013)</small></li>
<li><a href="/doc/go1.1">Go 1.1</a> <small>(May 2013)</small></li>
<li><a href="/doc/go1">Go 1</a> <small>(March 2012)</small></li>
</ul>

<h3 id="go1compat"><a href="/doc/go1compat">Go 1 and the Future of Go Programs</a></h3>
<p>
Expand Down
2 changes: 1 addition & 1 deletion doc/go_spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -5579,7 +5579,7 @@ <h3 id="Appending_and_copying_slices">Appending to and copying slices</h3>
s4 := append(s3[3:6], s3[2:]...) // append overlapping slice s4 == []int{3, 5, 7, 2, 3, 5, 7, 0, 0}

var t []interface{}
t = append(t, 42, 3.1415, "foo") t == []interface{}{42, 3.1415, "foo"}
t = append(t, 42, 3.1415, "foo") // t == []interface{}{42, 3.1415, "foo"}

var b []byte
b = append(b, "bar"...) // append string contents b == []byte{'b', 'a', 'r' }
Expand Down
4 changes: 2 additions & 2 deletions lib/time/update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# downloaded from the ICANN/IANA distribution.

# Versions to use.
CODE=2014d
DATA=2014d
CODE=2014j
DATA=2014j

set -e
rm -rf work
Expand Down
Binary file modified lib/time/zoneinfo.zip
Binary file not shown.
28 changes: 20 additions & 8 deletions src/cmd/go/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,24 @@ create or update Go source files, for instance by running yacc.
Go generate is never run automatically by go build, go get, go test,
and so on. It must be run explicitly.
Directives are written as a whole-line comment of the form
Go generate scans the file for directives, which are lines of
the form,
//go:generate command argument...
(note: no space in "//go") where command is the generator to be
run, corresponding to an executable file that can be run locally.
It must either be in the shell path (gofmt), a fully qualified path
(/usr/you/bin/mytool), or a command alias, described below.
(note: no leading spaces and no space in "//go") where command
is the generator to be run, corresponding to an executable file
that can be run locally. It must either be in the shell path
(gofmt), a fully qualified path (/usr/you/bin/mytool), or a
command alias, described below.
The arguments are space-separated tokens or double-quoted strings
passed to the generator as individual arguments when it is run.
Note that go generate does not parse the file, so lines that look
like directives in comments or multiline strings will be treated
as directives.
The arguments to the directive are space-separated tokens or
double-quoted strings passed to the generator as individual
arguments when it is run.
Quoted strings use Go syntax and are evaluated before execution; a
quoted string appears as a single argument to the generator.
Expand Down Expand Up @@ -317,14 +324,19 @@ Download and install packages and dependencies
Usage:
go get [-d] [-fix] [-t] [-u] [build flags] [packages]
go get [-d] [-f] [-fix] [-t] [-u] [build flags] [packages]
Get downloads and installs the packages named by the import paths,
along with their dependencies.
The -d flag instructs get to stop after downloading the packages; that is,
it instructs get not to install the packages.
The -f flag, valid only when -u is set, forces get -u not to verify that
each package has been checked out from the source control repository
implied by its import path. This can be useful if the source is a local fork
of the original.
The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.
Expand Down
75 changes: 58 additions & 17 deletions src/cmd/go/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,27 @@ create or update Go source files, for instance by running yacc.
Go generate is never run automatically by go build, go get, go test,
and so on. It must be run explicitly.
Directives are written as a whole-line comment of the form
Go generate scans the file for directives, which are lines of
the form,
//go:generate command argument...
(note: no space in "//go") where command is the generator to be
run, corresponding to an executable file that can be run locally.
It must either be in the shell path (gofmt), a fully qualified path
(/usr/you/bin/mytool), or a command alias, described below.
(note: no leading spaces and no space in "//go") where command
is the generator to be run, corresponding to an executable file
that can be run locally. It must either be in the shell path
(gofmt), a fully qualified path (/usr/you/bin/mytool), or a
command alias, described below.
The arguments are space-separated tokens or double-quoted strings
passed to the generator as individual arguments when it is run.
Note that go generate does not parse the file, so lines that look
like directives in comments or multiline strings will be treated
as directives.
The arguments to the directive are space-separated tokens or
double-quoted strings passed to the generator as individual
arguments when it is run.
Quoted strings use Go syntax and are evaluated before execution; a
quoted string appears a single argument to the generator.
quoted string appears as a single argument to the generator.
Go generate sets several variables when it runs the generator:
Expand Down Expand Up @@ -178,13 +185,43 @@ func (g *Generator) run() (ok bool) {
fmt.Fprintf(os.Stderr, "%s\n", shortPath(g.path))
}

s := bufio.NewScanner(g.r)
for s.Scan() {
g.lineNum++
if !bytes.HasPrefix(s.Bytes(), []byte("//go:generate ")) && !bytes.HasPrefix(s.Bytes(), []byte("//go:generate\t")) {
// Scan for lines that start "//go:generate".
// Can't use bufio.Scanner because it can't handle long lines,
// which are likely to appear when using generate.
input := bufio.NewReader(g.r)
var err error
// One line per loop.
for {
g.lineNum++ // 1-indexed.
var buf []byte
buf, err = input.ReadSlice('\n')
if err == bufio.ErrBufferFull {
// Line too long - consume and ignore.
if isGoGenerate(buf) {
g.errorf("directive too long")
}
for err == bufio.ErrBufferFull {
_, err = input.ReadSlice('\n')
}
if err != nil {
break
}
continue
}

if err != nil {
// Check for marker at EOF without final \n.
if err == io.EOF && isGoGenerate(buf) {
err = io.ErrUnexpectedEOF
}
break
}

if !isGoGenerate(buf) {
continue
}
words := g.split(s.Text())

words := g.split(string(buf))
if len(words) == 0 {
g.errorf("no arguments to directive")
}
Expand All @@ -201,19 +238,23 @@ func (g *Generator) run() (ok bool) {
}
g.exec(words)
}
if s.Err() != nil {
g.errorf("error reading %s: %s", shortPath(g.path), s.Err())
if err != nil && err != io.EOF {
g.errorf("error reading %s: %s", shortPath(g.path), err)
}
return true
}

func isGoGenerate(buf []byte) bool {
return bytes.HasPrefix(buf, []byte("//go:generate ")) || bytes.HasPrefix(buf, []byte("//go:generate\t"))
}

// split breaks the line into words, evaluating quoted
// strings and evaluating environment variables.
// The initial //go:generate element is dropped.
// The initial //go:generate element is present in line.
func (g *Generator) split(line string) []string {
// Parse line, obeying quoted strings.
var words []string
line = line[len("//go:generate "):]
line = line[len("//go:generate ") : len(line)-1] // Drop preamble and final newline.
// One (possibly quoted) word per iteration.
Words:
for {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGenerateCommandParse(t *testing.T) {
}
g.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"})
for _, test := range splitTests {
got := g.split("//go:generate " + test.in)
got := g.split("//go:generate " + test.in + "\n")
if !reflect.DeepEqual(got, test.out) {
t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
}
Expand Down
26 changes: 22 additions & 4 deletions src/cmd/pprof/internal/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"os"
"os/exec"
"runtime"
"strings"

"cmd/pprof/internal/plugin"
Expand Down Expand Up @@ -71,15 +72,27 @@ func PProf(c Completer, interactive **bool, svgpan **string) Commands {
"eog": {c, report.Dot, invokeVisualizer(interactive, invokeDot("svg"), "svg", []string{"eog"}), false, "Visualize graph through eog"},
"evince": {c, report.Dot, invokeVisualizer(interactive, invokeDot("pdf"), "pdf", []string{"evince"}), false, "Visualize graph through evince"},
"gv": {c, report.Dot, invokeVisualizer(interactive, invokeDot("ps"), "ps", []string{"gv --noantialias"}), false, "Visualize graph through gv"},
"web": {c, report.Dot, invokeVisualizer(interactive, saveSVGToFile(svgpan), "svg", browsers), false, "Visualize graph through web browser"},
"web": {c, report.Dot, invokeVisualizer(interactive, saveSVGToFile(svgpan), "svg", browsers()), false, "Visualize graph through web browser"},

// Visualize HTML directly generated by report.
"weblist": {c, report.WebList, invokeVisualizer(interactive, awayFromTTY("html"), "html", browsers), true, "Output annotated source in HTML for functions matching regexp or address"},
"weblist": {c, report.WebList, invokeVisualizer(interactive, awayFromTTY("html"), "html", browsers()), true, "Output annotated source in HTML for functions matching regexp or address"},
}
}

// List of web browsers to attempt for web visualization
var browsers = []string{"chrome", "google-chrome", "firefox", "/usr/bin/open"}
// browsers returns a list of commands to attempt for web visualization
// on the current platform
func browsers() []string {
cmds := []string{"chrome", "google-chrome", "firefox"}
switch runtime.GOOS {
case "darwin":
cmds = append(cmds, "/usr/bin/open")
case "windows":
cmds = append(cmds, "cmd /c start")
default:
cmds = append(cmds, "xdg-open")
}
return cmds
}

// NewCompleter creates an autocompletion function for a set of commands.
func NewCompleter(cs Commands) Completer {
Expand Down Expand Up @@ -142,6 +155,10 @@ func awayFromTTY(format string) PostProcessor {
func invokeDot(format string) PostProcessor {
divert := awayFromTTY(format)
return func(input *bytes.Buffer, output io.Writer, ui plugin.UI) error {
if _, err := exec.LookPath("dot"); err != nil {
ui.PrintErr("Cannot find dot, have you installed Graphviz?")
return err
}
cmd := exec.Command("dot", "-T"+format)
var buf bytes.Buffer
cmd.Stdin, cmd.Stdout, cmd.Stderr = input, &buf, os.Stderr
Expand Down Expand Up @@ -174,6 +191,7 @@ func invokeVisualizer(interactive **bool, format PostProcessor, suffix string, v
if err = format(input, tempFile, ui); err != nil {
return err
}
tempFile.Close() // on windows, if the file is Open, start cannot access it.
// Try visualizers until one is successful
for _, v := range visualizers {
// Separate command and arguments for exec.Command.
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/pprof/internal/symbolizer/symbolizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func Symbolize(mode string, prof *profile.Profile, obj plugin.ObjTool, ui plugin
}
}

if len(prof.Mapping) == 0 {
return fmt.Errorf("no known mappings")
}

mt, err := newMapping(prof, obj, ui, force)
if err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions src/go/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1310,11 +1310,13 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
// auto-tagging to apply only to files with a non-empty prefix, so
// "foo_linux.go" is tagged but "linux.go" is not. This allows new operating
// sytems, such as android, to arrive without breaking existing code with
// innocuous source code in "android.go". The easiest fix: files without
// underscores are always included.
if !strings.ContainsRune(name, '_') {
// innocuous source code in "android.go". The easiest fix: cut everything
// in the name before the initial _.
i := strings.Index(name, "_")
if i < 0 {
return true
}
name = name[i:] // ignore everything before first _

l := strings.Split(name, "_")
if n := len(l); n > 0 && l[n-1] == "test" {
Expand Down
1 change: 1 addition & 0 deletions src/go/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ var matchFileTests = []struct {
{ctxtAndroid, "foo_plan9.go", "", false},
{ctxtAndroid, "android.go", "", true},
{ctxtAndroid, "plan9.go", "", true},
{ctxtAndroid, "plan9_test.go", "", true},
{ctxtAndroid, "arm.s", "", true},
{ctxtAndroid, "amd64.s", "", true},
}
Expand Down
Loading

0 comments on commit 829b286

Please sign in to comment.