cmd/bundle: permit empty -prefix

This enables bundling of programs with `main` method to single file.
I used this to upload code for the new codejam.

Change-Id: I9e65ba8717c1d81d6fb9bef8f234c21fc5b91421
GitHub-Last-Rev: 5d0d623c46ff1629e7371693ddf0916df328e319
GitHub-Pull-Request: golang/tools#32
Reviewed-on: https://go-review.googlesource.com/c/105515
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
matematik7 2018-07-16 15:54:33 +00:00 committed by Alan Donovan
parent 879803d4ad
commit 84d77ece31
1 changed files with 3 additions and 4 deletions

View File

@ -105,7 +105,7 @@ var (
outputFile = flag.String("o", "", "write output to `file` (default standard output)")
dstPath = flag.String("dst", "", "set destination import `path` (default taken from current directory)")
pkgName = flag.String("pkg", "", "set destination package `name` (default taken from current directory)")
prefix = flag.String("prefix", "", "set bundled identifier prefix to `p` (default source package name + \"_\")")
prefix = flag.String("prefix", "&_", "set bundled identifier prefix to `p` (default is \"&_\", where & stands for the original name)")
underscore = flag.Bool("underscore", false, "rewrite golang.org to golang_org in imports; temporary workaround for golang.org/issue/16333")
importMap = map[string]string{}
@ -203,9 +203,8 @@ func bundle(src, dst, dstpkg, prefix string) ([]byte, error) {
// Because there was a single Import call and Load succeeded,
// InitialPackages is guaranteed to hold the sole requested package.
info := lprog.InitialPackages()[0]
if prefix == "" {
pkgName := info.Files[0].Name.Name
prefix = pkgName + "_"
if strings.Contains(prefix, "&") {
prefix = strings.Replace(prefix, "&", info.Files[0].Name.Name, -1)
}
objsToUpdate := make(map[types.Object]bool)