From 84d77ece312ed504d11e7151508732a4c8c8b6ae Mon Sep 17 00:00:00 2001 From: matematik7 Date: Mon, 16 Jul 2018 15:54:33 +0000 Subject: [PATCH] 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 --- cmd/bundle/main.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/bundle/main.go b/cmd/bundle/main.go index 601da7f8..7c552683 100644 --- a/cmd/bundle/main.go +++ b/cmd/bundle/main.go @@ -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)