I've been doing this by hand since Go 1.7rc2.
Updates golang/go#16333
Change-Id: Ib12c013b14210123d48d6ad78922caf1286c20cc
Reviewed-on: https://go-review.googlesource.com/29086
Reviewed-by: Alan Donovan <adonovan@google.com>
Document a risk of generating invalid code due to shadowing between
identifiers in code files and the imported package names.
This risk was present before for any package with more than 1 .go file,
but it's increased when some files have renamed imports (since they're
typically used to resolve shadowing conflicts).
Resolves TODO(adonovan): support renaming imports.
Change-Id: Ie0e702345790fd2059c229623fb99fe645d688a4
Reviewed-on: https://go-review.googlesource.com/23785
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
The responsibility of flag.Usage is to print usage to stderr:
> Usage prints to standard error a usage message documenting all
> defined command-line flags.
Calling os.Exit(2) is outside of its scope, flag package does that.
Change-Id: I3eef2b796e5ddedff6d5927dbcdbfff3a6082270
Reviewed-on: https://go-review.googlesource.com/23788
Reviewed-by: Joseph Holsten <joseph@josephholsten.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This fixes some print calls with wrong format directives. Additionally,
struct initialisers were changed to use keyed fields, purely to reduce
the amount of noise generated by go vet.
Change-Id: Ib9f6fd8f2dff7ce84826478de0ba83dda9746270
Reviewed-on: https://go-review.googlesource.com/21180
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Before, "bundle -help" printed only one not particularly useful line:
Usage of bundle:
and "bundle" printed a bit more but not a standard usage message:
bundle: Usage: bundle package dest prefix
Arguments:
package is the import path of the package to concatenate.
dest is the import path of the package in which the resulting file will reside.
prefix is the string to attach to all renamed identifiers.
And most of that output belonged in (but was missing from) the doc comment,
which leaned heavily on the reader inferring usage from one example.
While fixing all this, I ended up dropping "dest" and "prefix" as required
arguments: perfectly good defaults can be inferred in the common case
where the bundle is intended for the current directory. The defaults can be
overridden with the new -dst and -prefix option.
I corrected a TODO about not assuming the package name could be
derived from the destination import path. Like -dst and -prefix, the
default package name can be inferred from the current directory,
but there is also a new -pkg option to override the default if needed.
I added a -o option to specify the destination output file (standard output
is still the default output). One benefit of -o is that it makes the bundle
commands self-contained in the sense of not needing a shell.
That in turn makes them suitable for use with "go generate", so when -o
is specified the bundle output now includes a "//go:generate" comment
for updating the bundle mechanically.
To keep bundle working for net/http's use case, I added a -importmap
option to specify additional import rewrites (net/http needs the http2
import of golang.org/x/net/http2/hpack rewritten to begin with internal/golang.org).
The net effect of all of this is that the first two lines at the top of
net/http/h2_bundle.go will change from:
// Code generated by golang.org/x/tools/cmd/bundle command:
// $ bundle golang.org/x/net/http2 net/http http2
to
// Code generated by golang.org/x/tools/cmd/bundle.
//go:generate bundle -o h2_bundle.go -prefix http2 -import golang.org/x/net/http2/hpack=internal/golang.org/x/net/http2/hpack golang.org/x/net/http2
and net/http's copy of http2 can now be updated by "go generate"
instead of by copying and pasting commands from source code to shell.
For an experiment I am doing with cmd/dist bundling archive/zip,
the header is even shorter and makes a better demonstration of the
power of the defaults:
// Code generated by golang.org/x/tools/cmd/bundle.
//go:generate bundle -o zip.go archive/zip
New usage message, printed by "bundle -help" and "bundle":
Usage: bundle [options] <src>
-dst path
set destination import path (default taken from current directory)
-import map
rewrite import using map, of form old=new (can be repeated)
-o file
write output to file (default standard output)
-pkg name
set destination package name (default taken from current directory)
-prefix p
set bundled identifier prefix to p (default source package name + "_")
See CL for new doc comment.
Following this CL I will send a CL updating the two-line header in net/http/h2_bundle.go
to match the new usage of the bundle, whatever that ends up being.
Change-Id: I83a65b6a500897854027cefdefb8f62f1d4448b4
Reviewed-on: https://go-review.googlesource.com/19428
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
A few files have been forked and tagged "go1.5,!go1.6" to work around
minor API changes between the two types packages:
- constant.Value.String() in oracle/describe.go and its tests;
- constant.ToInt must now be called before constant.Int64Val.
- types.Config{Importer: importer.Default()} in a number of places
- go/types/typeutil/import_test.go uses lowercase names to avoid 'import "C"'.
Files in go/types/typesutil, missing from my previous CL, have been
tagged !go1.5; these files will be deleted in February.
All affected packages were tested using 1.4.1, 1.5, and ~1.6 (tip).
Change-Id: Iec7fd370e1434508149b378438fb37f65b8d2ba8
Reviewed-on: https://go-review.googlesource.com/18207
Reviewed-by: Robert Griesemer <gri@golang.org>
This change will ensure that the tree continues to work with go1.4.1.
All files continue to depend on golang.org/x/tools/go/types, but in a
follow-up change, I will switch the primary files to depend on the
standard go/types package. Another (smaller) set of files will be
forked and tagged, this time !1.6, due to API differences between the
two packages.
All tests pass using 1.4.1, 1.5, and ~1.6 (tip).
Change-Id: Ifd75a6330e120957d646be91693daaba1ce0e8c9
Reviewed-on: https://go-review.googlesource.com/18333
Reviewed-by: Robert Griesemer <gri@golang.org>
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>