1
0
mirror of https://github.com/golang/go synced 2024-10-01 05:18:33 -06:00
Commit Graph

13 Commits

Author SHA1 Message Date
Alan Donovan
8cbea6846d cmd/bundle: revert support for Go 1.8 aliases
Change-Id: I2b3bcc7653507e392b243dbe0610adc6be6967bd
Reviewed-on: https://go-review.googlesource.com/32833
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-04 21:17:06 +00:00
Alan Donovan
4549178751 x/tools: clone some files in preparation for alias changes
This CL only copies files and updates build tags.
Substantive changes will come in follow-ups.
This is a workaround for git's lack of rename/copy tracking.

Tested with go1.6, go1.7, and tip (go1.8).

Change-Id: Id88a05273fb963586b228d5e5dfacab32133a960
Reviewed-on: https://go-review.googlesource.com/32630
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-02 16:57:37 +00:00
Brad Fitzpatrick
f1a397bba5 cmd/bundle: add flag to rewrite golang.org/ to golang_org/ in imports
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>
2016-09-13 16:37:30 +00:00
Dmitri Shuralyov
5cb1c80a83 cmd/bundle: Support renaming imports.
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>
2016-08-24 17:03:01 +00:00
Dmitri Shuralyov
5b59ce8b5f cmd/bundle: More idiomatic flag.Usage.
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>
2016-07-21 15:33:57 +00:00
Yasuhiro Matsumoto
ba484b064f cmd/bundle: move down imports of external package
imports should be ordered like

    import (
    	"fmt"

    	"golang.org/x/text"
    )

Change-Id: I000374833de370463d772c2596c7ac6ee5e9725c
Reviewed-on: https://go-review.googlesource.com/23026
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-05-26 02:53:53 +00:00
Dominik Honnef
361bcb2be3 all: address vet issues, fix print calls
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>
2016-03-27 20:36:34 +00:00
Alan Donovan
f7268ab39b cmd/bundle: fix broken test
Change-Id: I95bd6cd1b63a1d1b5bd255546fbf571010a67266
Reviewed-on: https://go-review.googlesource.com/19745
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-02-22 20:47:44 +00:00
Russ Cox
d0c9d43af1 bundle: new docs, command-line interface
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>
2016-02-17 15:40:24 +00:00
Alan Donovan
542ffc7e75 tools: switch to standard go/types at tip
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>
2016-01-06 22:15:26 +00:00
Alan Donovan
2477c0d578 x/tools/...: fork and tag !1.5 all files that use go/types et al
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>
2016-01-06 20:40:09 +00:00
Alan Donovan
99c318c742 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>
2015-12-18 13:56:53 +00:00
Alan Donovan
199b70b426 x/tools/cmd/bundle: a tool to concatenate source files, preserving reference integrity
+ Test.

For background, see "http -> http2 -> http import cycle" thread on golang-dev.

Change-Id: Idc422247e5935ef7615cd5e8b7e2c489f7f2bc31
Reviewed-on: https://go-review.googlesource.com/15850
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-10-29 19:10:01 +00:00