1
0
mirror of https://github.com/golang/go synced 2024-11-14 20:30:35 -07:00
go/src/cmd/dist/README

46 lines
1.7 KiB
Plaintext
Raw Normal View History

cmd/dist: new command dist is short for distribution. This is the new Go distribution tool. The plan is to replace the Makefiles with what amounts to 'go tool dist bootstrap', although it cannot be invoked like that since it is in charge of getting us to the point where we can build the go command. It will also add additional commands to replace bash scripts like test/run (go tool dist testrun), eventually eliminating our dependence on not just bash but all the Unix tools and all of cygwin. This is strong enough to build (cc *.c) and run (a.out bootstrap) to build not just the C libraries and tools but also the basic Go packages up to the bootstrap form of the go command (go_bootstrap). I've run it successfully on both Linux and Windows. This means that once we've switched to this tool in the build, we can delete the buildscripts. This tool is not nearly as nice as the go tool. There are many special cases that turn into simple if statements or tables in the code. Please forgive that. C does not enjoy the benefits that we designed into Go. I was planning to wait to do this until after Go 1, but the Windows builders are both broken due to a bug in either make or bash or both involving the parsing of quoted command arguments. Make thinks it is invoking quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c but bash (quietgcc is a bash script) thinks it is being invoked as quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c which obviously does not have the desired effect. Rather than fight these clumsy ports, I accelerated the schedule for the new tool. We should be completely off cygwin (using just the mingw gcc port, which is much more standalone) before Go 1. It is big for a single CL, and for that I apologize. I can cut it into separate CLs along file boundaries if people would prefer that. R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter CC=golang-dev https://golang.org/cl/5620045
2012-02-02 17:41:39 -07:00
This program, dist, is the bootstrapping tool for the Go distribution.
It takes care of building the C programs (like the Go compiler) and
the initial bootstrap copy of the go tool. It also serves as a catch-all
to replace odd jobs previously done with shell scripts.
Dist is itself written in very simple C. All interaction with C libraries,
even standard C libraries, is confined to a single system-specific file
(plan9.c, unix.c, windows.c), to aid portability. Functionality needed
by other files should be exposed via the portability layer. Functions
in the portability layer begin with an x prefix when they would otherwise
use the same name as or be confused for an existing function.
For example, xprintf is the portable printf.
By far the most common data types in dist are strings and arrays of
strings. Instead of using char* and char**, though, dist uses two named
data structures, Buf and Vec, which own all the data they point at.
The Buf operations are functions beginning with b; the Vec operations
are functions beginning with v. The basic form of any function declaring
Bufs or Vecs on the stack should be
void
myfunc(void)
{
Buf b1, b2;
Vec v1;
binit(&b1);
binit(&b2);
vinit(&v1);
... main code ...
bprintf(&b1, "hello, world");
vadd(&v1, bstr(&b1)); // v1 takes a copy of its argument
bprintf(&b2, "another string");
vadd(&v1, bstr(&b2)); // v1 now has two strings
cmd/dist: new command dist is short for distribution. This is the new Go distribution tool. The plan is to replace the Makefiles with what amounts to 'go tool dist bootstrap', although it cannot be invoked like that since it is in charge of getting us to the point where we can build the go command. It will also add additional commands to replace bash scripts like test/run (go tool dist testrun), eventually eliminating our dependence on not just bash but all the Unix tools and all of cygwin. This is strong enough to build (cc *.c) and run (a.out bootstrap) to build not just the C libraries and tools but also the basic Go packages up to the bootstrap form of the go command (go_bootstrap). I've run it successfully on both Linux and Windows. This means that once we've switched to this tool in the build, we can delete the buildscripts. This tool is not nearly as nice as the go tool. There are many special cases that turn into simple if statements or tables in the code. Please forgive that. C does not enjoy the benefits that we designed into Go. I was planning to wait to do this until after Go 1, but the Windows builders are both broken due to a bug in either make or bash or both involving the parsing of quoted command arguments. Make thinks it is invoking quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c but bash (quietgcc is a bash script) thinks it is being invoked as quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c which obviously does not have the desired effect. Rather than fight these clumsy ports, I accelerated the schedule for the new tool. We should be completely off cygwin (using just the mingw gcc port, which is much more standalone) before Go 1. It is big for a single CL, and for that I apologize. I can cut it into separate CLs along file boundaries if people would prefer that. R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter CC=golang-dev https://golang.org/cl/5620045
2012-02-02 17:41:39 -07:00
bfree(&b1);
bfree(&b2);
vfree(&v1);
}
The binit/vinit calls prepare a buffer or vector for use, initializing the
data structures, and the bfree/vfree calls free any memory they are still
holding onto. Use of this idiom gives us lexically scoped allocations.