From 99c318c742339e824d89d23ba3b3bff4f4ab27a8 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 17 Dec 2015 23:35:19 -0500 Subject: [PATCH] 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 --- cmd/bundle/main.go | 10 +++++----- cmd/bundle/testdata/out.golden | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/bundle/main.go b/cmd/bundle/main.go index 35b16eb5..3d85d883 100644 --- a/cmd/bundle/main.go +++ b/cmd/bundle/main.go @@ -17,8 +17,8 @@ // - 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. // - comments associated with the package or import declarations, -// or associated with no top-level declaration at all, -// may be discarded. +// may be discarded, as may comments associated with no top-level +// declaration at all. // - neither the original package nor the destination package contains // any identifiers starting with the designated prefix. // (This allows us to avoid various conflict checks.) @@ -31,8 +31,6 @@ // and embedded fields of renamed types. No methods are renamed, so we // needn't worry about preserving interface satisfaction. // -// TODO(adonovan): gofmt the result. -// package main 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, "// $ 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 { if doc := f.Doc.Text(); strings.TrimSpace(doc) != "" { 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). fmt.Fprintf(&out, "package %s\n\n", filepath.Base(dest)) diff --git a/cmd/bundle/testdata/out.golden b/cmd/bundle/testdata/out.golden index e8c439ae..5153d3fc 100644 --- a/cmd/bundle/testdata/out.golden +++ b/cmd/bundle/testdata/out.golden @@ -3,6 +3,7 @@ // The package doc comment // + package dest import (