cmd/bundle: add blank line before package declaration

so that the bundled package doesn't clobber the package declaration
of the host package.

Also: minor comment tweaks.

Change-Id: I28ab3aca2b02213edc95c6b12c0d1a2514453cfe
Reviewed-on: https://go-review.googlesource.com/18040
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Alan Donovan 2015-12-17 23:35:19 -05:00 committed by Alan Donovan
parent 4a5fb9938b
commit 99c318c742
2 changed files with 6 additions and 5 deletions

View File

@ -17,8 +17,8 @@
// - no file in the package imports "C", that is, uses cgo. // - no file in the package imports "C", that is, uses cgo.
// - no file in the package has GOOS or GOARCH build tags or file names. // - no file in the package has GOOS or GOARCH build tags or file names.
// - comments associated with the package or import declarations, // - comments associated with the package or import declarations,
// or associated with no top-level declaration at all, // may be discarded, as may comments associated with no top-level
// may be discarded. // declaration at all.
// - neither the original package nor the destination package contains // - neither the original package nor the destination package contains
// any identifiers starting with the designated prefix. // any identifiers starting with the designated prefix.
// (This allows us to avoid various conflict checks.) // (This allows us to avoid various conflict checks.)
@ -31,8 +31,6 @@
// and embedded fields of renamed types. No methods are renamed, so we // and embedded fields of renamed types. No methods are renamed, so we
// needn't worry about preserving interface satisfaction. // needn't worry about preserving interface satisfaction.
// //
// TODO(adonovan): gofmt the result.
//
package main package main
import ( import (
@ -125,7 +123,7 @@ func bundle(w io.Writer, initialPkg, dest, prefix string) error {
fmt.Fprintf(&out, "// Code generated by golang.org/x/tools/cmd/bundle command:\n") fmt.Fprintf(&out, "// Code generated by golang.org/x/tools/cmd/bundle command:\n")
fmt.Fprintf(&out, "// $ bundle %s %s %s\n\n", initialPkg, dest, prefix) fmt.Fprintf(&out, "// $ bundle %s %s %s\n\n", initialPkg, dest, prefix)
// Concatenate package comments from of all files. // Concatenate package comments from all files...
for _, f := range info.Files { for _, f := range info.Files {
if doc := f.Doc.Text(); strings.TrimSpace(doc) != "" { if doc := f.Doc.Text(); strings.TrimSpace(doc) != "" {
for _, line := range strings.Split(doc, "\n") { for _, line := range strings.Split(doc, "\n") {
@ -133,6 +131,8 @@ func bundle(w io.Writer, initialPkg, dest, prefix string) error {
} }
} }
} }
// ...but don't let them become the actual package comment.
fmt.Fprintln(&out)
// TODO(adonovan): don't assume pkg.name == basename(pkg.path). // TODO(adonovan): don't assume pkg.name == basename(pkg.path).
fmt.Fprintf(&out, "package %s\n\n", filepath.Base(dest)) fmt.Fprintf(&out, "package %s\n\n", filepath.Base(dest))

View File

@ -3,6 +3,7 @@
// The package doc comment // The package doc comment
// //
package dest package dest
import ( import (