From 360151d4e2b3990db67555a8c61b1e581294fc44 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 18 Nov 2008 17:11:56 -0800 Subject: [PATCH] gobuild changes. * handles multiple packages per directory * scans directory for files if given no arguments * infers package name * includes test rule invoking gotest R=r DELTA=746 (444 added, 150 deleted, 152 changed) OCL=19504 CL=19521 --- src/cmd/gobuild/gobuild.c | 511 +++++++++++++++++++++++++------------- src/cmd/gotest/Makefile | 1 + src/cmd/gotest/gotest | 29 ++- src/lib/fmt/Makefile | 38 +-- src/lib/http/Makefile | 51 ++-- src/lib/math/Makefile | 46 ++-- src/lib/net/Makefile | 40 +-- src/lib/os/Makefile | 38 ++- src/lib/reflect/Makefile | 43 ++-- src/lib/strconv/Makefile | 39 +-- src/lib/syscall/Makefile | 36 ++- 11 files changed, 583 insertions(+), 289 deletions(-) diff --git a/src/cmd/gobuild/gobuild.c b/src/cmd/gobuild/gobuild.c index 3a37cfd7c5..6605b05265 100644 --- a/src/cmd/gobuild/gobuild.c +++ b/src/cmd/gobuild/gobuild.c @@ -12,7 +12,7 @@ void usage(void) { - fprint(2, "usage: gobuild [-m] packagename *.go *.c *.s\n"); + fprint(2, "usage: gobuild [-m] [packagename...]\n"); exits("usage"); } @@ -22,14 +22,47 @@ int makefile; // generate Makefile char *thechar; // object character char *goos; char *goarch; +char *goroot; +char **oargv; +int oargc; + +void writemakefile(void); +int sourcefilenames(char***); + +void* +emalloc(int n) +{ + void *v; + + v = malloc(n); + if(v == nil) + sysfatal("out of memory"); + memset(v, 0, n); + return v; +} + +void* +erealloc(void *v, int n) +{ + v = realloc(v, n); + if(v == nil) + sysfatal("out of memory"); + return v; +} // Info about when to compile a particular file. typedef struct Job Job; struct Job { char *name; + char *pkg; int pass; }; +Job *job; +int njob; + +char **pkg; +int npkg; // Run the command in argv. // Return -1 if it fails (non-zero exit status). @@ -42,6 +75,7 @@ run(char **argv, int showoutput) int pid, i; Waitmsg *w; vlong n0, n1; + char buf[100]; n0 = nsec(); pid = fork(); @@ -49,22 +83,22 @@ run(char **argv, int showoutput) sysfatal("fork: %r"); if(pid == 0){ dup(devnull, 0); - if(!showoutput){ - dup(devnull, 1); + if(!showoutput) dup(devnull, 2); - }else{ - dup(2, 1); - } + dup(2, 1); if(devnull > 2) close(devnull); exec(argv[0], argv); fprint(2, "exec %s: %r\n", argv[0]); exit(1); } - w = waitfor(pid); - n1 = nsec(); - if(w == nil) + while((w = waitfor(pid)) == nil) { + rerrstr(buf, sizeof buf); + if(strstr(buf, "interrupt")) + continue; sysfatal("waitfor %d: %r", pid); + } + n1 = nsec(); if(chatty > 1){ fprint(2, "%5.3f", (n1-n0)/1.e9); for(i=0; argv[i]; i++) @@ -94,6 +128,30 @@ buildcc(char *cc, char *file, int show) return run(argv, show); } +// Run ar to add the given files to pkg.a. +void +ar(char *pkg, char **file, int nfile) +{ + char **arg; + int i, n; + char sixar[20]; + char pkga[1000]; + + arg = emalloc((4+nfile)*sizeof arg[0]); + n = 0; + snprint(sixar, sizeof sixar, "%sar", thechar); + snprint(pkga, sizeof pkga, "%s.a", pkg); + arg[n++] = sixar; + arg[n++] = "grc"; + arg[n++] = pkga; + for(i=0; i p && (*(q-1) == ' ' || *(q-1) == '\t')) + *--q = '\0'; + for(i=0; i 60){ + Bprint(&bout, "\\\n# "); + o = Boffset(&bout); + } + Bprint(&bout, " %s", oargv[i]); + } + Bprint(&bout, " >Makefile\n"); + Bprint(&bout, preamble, thechar); + + // O2=\ + // os_file.$O\ + // os_time.$O\ + // + obj = emalloc(njob*sizeof obj[0]); + for(pass=0;; pass++) { + nobj = 0; + for(i=0; i 0) { + Bprint(&bout, "\t$(AR) grc %s.a", pkg[i]); + for(l=0; l 0; pass++){ - nnext = 0; - nar = 3; - - // Try to build. - for(i=0; i 0; pass++) { + // Run what we can. + nfail = 0; + nsuccess = 0; + for(i=0; iname), j->name, 0) < 0) + fail[nfail++] = j; + else{ if(chatty == 1) - fprint(2, "%s ", this[i]); + fprint(2, "%s ", j->name); + success[nsuccess++] = j; } } - if(nthis == nnext){ // they all failed - fprint(2, "cannot make progress\n"); - for(i=0; iname), j->name, 1); + } exits("stalemate"); } if(chatty == 1) fprint(2, "\n"); - // Add to archive. - ar[nar] = nil; - if(run(ar, 1) < 0) - sysfatal("ar: %r"); - - // Delete objects. - for(i=3; i 60){ - Bprint(&bout, "\\\n# "); - o = Boffset(&bout); + // Update archives. + for(i=0; ipkg == pkg[i]) + arfiles[narfiles++] = goobj(j->name, thechar); + j->pass = pass; } - Bprint(&bout, " %s", oargv[i]); + if(narfiles > 0) + ar(pkg[i], arfiles, narfiles); + for(k=0; kMakefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=fmt.a -PKGDIR=$(GOROOT)/pkg - -install: $(PKG) - mv $(PKG) $(PKGDIR)/$(PKG) - -nuke: clean - rm -f $(PKGDIR)/$(PKG) +default: packages clean: - rm -f *.$O *.a $(PKG) + rm -f *.$O *.a + +test: packages + gotest %.$O: %.go $(GC) $*.go @@ -31,21 +27,33 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ format.$O\ O2=\ print.$O\ -$(PKG): a1 a2 +fmt.a: a1 a2 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc fmt.a format.$O rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc fmt.a print.$O rm -f $(O2) -$(O1): nuke +newpkg: clean + $(AR) grc fmt.a + +$(O1): newpkg $(O2): a1 +nuke: clean + rm -f $(GOROOT)/pkg/fmt.a + +packages: fmt.a + +install: packages + cp fmt.a $(GOROOT)/pkg/fmt.a + diff --git a/src/lib/http/Makefile b/src/lib/http/Makefile index 1007a1bb3f..75ab68d7de 100644 --- a/src/lib/http/Makefile +++ b/src/lib/http/Makefile @@ -3,23 +3,21 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m http conn.go request.go server.go url.go +# gobuild -m >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=$(GOROOT)/pkg/http.a - -install: $(PKG) - -nuke: clean - rm -f $(PKG) +default: packages clean: rm -f *.$O *.a +test: packages + gotest + %.$O: %.go $(GC) $*.go @@ -29,7 +27,6 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ url.$O\ @@ -42,22 +39,48 @@ O3=\ O4=\ server.$O\ -$(PKG): a1 a2 a3 a4 +O5=\ + triv.$O\ + +http.a: a1 a2 a3 a4 a5 +main.a: a1 a2 a3 a4 a5 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc http.a url.$O rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc http.a request.$O rm -f $(O2) + a3: $(O3) - $(AR) grc $(PKG) $(O3) + $(AR) grc http.a conn.$O rm -f $(O3) + a4: $(O4) - $(AR) grc $(PKG) $(O4) + $(AR) grc http.a server.$O rm -f $(O4) -$(O1): nuke +a5: $(O5) + $(AR) grc main.a triv.$O + rm -f $(O5) + +newpkg: clean + $(AR) grc http.a + $(AR) grc main.a + +$(O1): newpkg $(O2): a1 $(O3): a2 $(O4): a3 +$(O5): a4 + +nuke: clean + rm -f $(GOROOT)/pkg/http.a $(GOROOT)/pkg/main.a + +packages: http.a main.a + +install: packages + cp http.a $(GOROOT)/pkg/http.a + cp main.a $(GOROOT)/pkg/main.a diff --git a/src/lib/math/Makefile b/src/lib/math/Makefile index a64d7b34a0..56cd9d0466 100644 --- a/src/lib/math/Makefile +++ b/src/lib/math/Makefile @@ -3,26 +3,20 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m math asin.go atan.go atan2.go exp.go fabs.go floor.go\ -# fmod.go hypot.go log.go pow.go pow10.go sin.go sinh.go sqrt.go\ -# tan.go tanh.go +# gobuild -m >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=math.a -PKGDIR=$(GOROOT)/pkg - -install: $(PKG) - mv $(PKG) $(PKGDIR)/$(PKG) - -nuke: clean - rm -f $(PKGDIR)/$(PKG) +default: packages clean: - rm -f *.$O *.a $(PKG) + rm -f *.$O *.a + +test: packages + gotest %.$O: %.go $(GC) $*.go @@ -33,7 +27,6 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ atan.$O\ fabs.$O\ @@ -58,22 +51,37 @@ O3=\ O4=\ tanh.$O\ -$(PKG): a1 a2 a3 a4 +math.a: a1 a2 a3 a4 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc math.a atan.$O fabs.$O floor.$O fmod.$O hypot.$O log.$O pow10.$O sin.$O sqrt.$O tan.$O rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc math.a asin.$O atan2.$O exp.$O rm -f $(O2) + a3: $(O3) - $(AR) grc $(PKG) $(O3) + $(AR) grc math.a pow.$O sinh.$O rm -f $(O3) + a4: $(O4) - $(AR) grc $(PKG) $(O4) + $(AR) grc math.a tanh.$O rm -f $(O4) -$(O1): nuke +newpkg: clean + $(AR) grc math.a + +$(O1): newpkg $(O2): a1 $(O3): a2 $(O4): a3 +nuke: clean + rm -f $(GOROOT)/pkg/math.a + +packages: math.a + +install: packages + cp math.a $(GOROOT)/pkg/math.a + diff --git a/src/lib/net/Makefile b/src/lib/net/Makefile index afbfd1ed16..52ff320e47 100644 --- a/src/lib/net/Makefile +++ b/src/lib/net/Makefile @@ -3,23 +3,21 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m net fd_darwin.go fd.go net.go net_darwin.go ip.go +# gobuild -m fd_darwin.go fd.go net.go net_darwin.go ip.go >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=$(GOROOT)/pkg/net.a - -install: $(PKG) - -nuke: clean - rm -f $(PKG) +default: packages clean: rm -f *.$O *.a +test: packages + gotest + %.$O: %.go $(GC) $*.go @@ -29,7 +27,6 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ ip.$O\ @@ -43,22 +40,37 @@ O3=\ O4=\ net.$O\ -$(PKG): a1 a2 a3 a4 +net.a: a1 a2 a3 a4 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc net.a ip.$O rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc net.a fd_$(GOOS).$O net_$(GOOS).$O rm -f $(O2) + a3: $(O3) - $(AR) grc $(PKG) $(O3) + $(AR) grc net.a fd.$O rm -f $(O3) + a4: $(O4) - $(AR) grc $(PKG) $(O4) + $(AR) grc net.a net.$O rm -f $(O4) -$(O1): nuke +newpkg: clean + $(AR) grc net.a + +$(O1): newpkg $(O2): a1 $(O3): a2 $(O4): a3 +nuke: clean + rm -f $(GOROOT)/pkg/net.a + +packages: net.a + +install: packages + cp net.a $(GOROOT)/pkg/net.a + diff --git a/src/lib/os/Makefile b/src/lib/os/Makefile index e2b741cd39..ed4a36bbbb 100644 --- a/src/lib/os/Makefile +++ b/src/lib/os/Makefile @@ -3,23 +3,21 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m os os_error.go os_file.go os_time.go os_env.go +# gobuild -m >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=$(GOROOT)/pkg/os.a - -install: $(PKG) - -nuke: clean - rm -f $(PKG) +default: packages clean: rm -f *.$O *.a +test: packages + gotest + %.$O: %.go $(GC) $*.go @@ -29,21 +27,35 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ os_error.$O\ O2=\ + os_env.$O\ os_file.$O\ os_time.$O\ - os_env.$O\ -$(PKG): a1 a2 +os.a: a1 a2 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc os.a os_error.$O + rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc os.a os_env.$O os_file.$O os_time.$O + rm -f $(O2) -$(O1): nuke +newpkg: clean + $(AR) grc os.a + +$(O1): newpkg $(O2): a1 +nuke: clean + rm -f $(GOROOT)/pkg/os.a + +packages: os.a + +install: packages + cp os.a $(GOROOT)/pkg/os.a + diff --git a/src/lib/reflect/Makefile b/src/lib/reflect/Makefile index b0927a3b89..729a819864 100644 --- a/src/lib/reflect/Makefile +++ b/src/lib/reflect/Makefile @@ -3,24 +3,21 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m reflect tostring.go type.go value.go cast_amd64.s\ -# typestring.c +# gobuild -m >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=$(GOROOT)/pkg/reflect.a - -install: $(PKG) - -nuke: clean - rm -f $(PKG) +default: packages clean: rm -f *.$O *.a +test: packages + gotest + %.$O: %.go $(GC) $*.go @@ -30,10 +27,9 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ + cast_$(GOARCH).$O\ type.$O\ - cast_amd64.$O\ typestring.$O\ O2=\ @@ -42,15 +38,32 @@ O2=\ O3=\ tostring.$O\ -$(PKG): a1 a2 a3 +reflect.a: a1 a2 a3 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc reflect.a cast_$(GOARCH).$O type.$O typestring.$O + rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc reflect.a value.$O + rm -f $(O2) + a3: $(O3) - $(AR) grc $(PKG) $(O3) + $(AR) grc reflect.a tostring.$O + rm -f $(O3) + +newpkg: clean + $(AR) grc reflect.a -$(O1): nuke +$(O1): newpkg $(O2): a1 $(O3): a2 +nuke: clean + rm -f $(GOROOT)/pkg/reflect.a + +packages: reflect.a + +install: packages + cp reflect.a $(GOROOT)/pkg/reflect.a + diff --git a/src/lib/strconv/Makefile b/src/lib/strconv/Makefile index e34a0fa92c..e5c4d1d1d9 100644 --- a/src/lib/strconv/Makefile +++ b/src/lib/strconv/Makefile @@ -3,23 +3,21 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m strconv atof.go atoi.go decimal.go ftoa.go itoa.go +# gobuild -m >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=$(GOROOT)/pkg/strconv.a - -install: $(PKG) - -nuke: clean - rm -f $(PKG) +default: packages clean: rm -f *.$O *.a +test: packages + gotest + %.$O: %.go $(GC) $*.go @@ -29,11 +27,10 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ atoi.$O\ - decimal.$O\ itoa.$O\ + decimal.$O\ O2=\ ftoa.$O\ @@ -41,18 +38,32 @@ O2=\ O3=\ atof.$O\ -$(PKG): a1 a2 a3 +strconv.a: a1 a2 a3 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc strconv.a atoi.$O itoa.$O decimal.$O rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc strconv.a ftoa.$O rm -f $(O2) + a3: $(O3) - $(AR) grc $(PKG) $(O3) + $(AR) grc strconv.a atof.$O rm -f $(O3) -$(O1): nuke +newpkg: clean + $(AR) grc strconv.a + +$(O1): newpkg $(O2): a1 $(O3): a2 +nuke: clean + rm -f $(GOROOT)/pkg/strconv.a + +packages: strconv.a + +install: packages + cp strconv.a $(GOROOT)/pkg/strconv.a + diff --git a/src/lib/syscall/Makefile b/src/lib/syscall/Makefile index 8564854f1d..58d483a9d5 100644 --- a/src/lib/syscall/Makefile +++ b/src/lib/syscall/Makefile @@ -3,25 +3,23 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m syscall errstr_darwin.go file_darwin.go socket_darwin.go\ +# gobuild -m errstr_darwin.go file_darwin.go socket_darwin.go\ # syscall_amd64_darwin.go time_amd64_darwin.go types_amd64_darwin.go\ -# asm_amd64_darwin.s cast_amd64.s syscall.go +# asm_amd64_darwin.s cast_amd64.s syscall.go >Makefile O=6 GC=$(O)g CC=$(O)c -w AS=$(O)a AR=$(O)ar -PKG=$(GOROOT)/pkg/syscall.a - -install: $(PKG) - -nuke: clean - rm -f $(PKG) +default: packages clean: rm -f *.$O *.a +test: packages + gotest + %.$O: %.go $(GC) $*.go @@ -31,7 +29,6 @@ clean: %.$O: %.s $(AS) $*.s - O1=\ errstr_$(GOOS).$O\ syscall_$(GOARCH)_$(GOOS).$O\ @@ -45,14 +42,27 @@ O2=\ socket_$(GOOS).$O\ time_$(GOARCH)_$(GOOS).$O\ -$(PKG): a1 a2 +syscall.a: a1 a2 + a1: $(O1) - $(AR) grc $(PKG) $(O1) + $(AR) grc syscall.a errstr_$(GOOS).$O syscall_$(GOARCH)_$(GOOS).$O types_$(GOARCH)_$(GOOS).$O asm_$(GOARCH)_$(GOOS).$O cast_$(GOARCH).$O syscall.$O rm -f $(O1) + a2: $(O2) - $(AR) grc $(PKG) $(O2) + $(AR) grc syscall.a file_$(GOOS).$O socket_$(GOOS).$O time_$(GOARCH)_$(GOOS).$O rm -f $(O2) -$(O1): nuke +newpkg: clean + $(AR) grc syscall.a + +$(O1): newpkg $(O2): a1 +nuke: clean + rm -f $(GOROOT)/pkg/syscall.a + +packages: syscall.a + +install: packages + cp syscall.a $(GOROOT)/pkg/syscall.a + -- 2.48.1