From 91395ae68945ffcf6383954cb5b1377c3ac10d50 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 29 May 2009 18:12:04 -0700 Subject: [PATCH] make gobuild failures more readable. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1. ar reports names of objects with duplicate text symbols. 2. gobuild only shows first line of error output for each failed command. 3. gobuild ignores files that begin with ascii non-alphanumeric non _. ; gobuild $ 6g -I _obj gobuild.go gobuild.go:150: PackageImports: undefined $ 6g -I _obj makefile.go makefile.go:102: ShellString: undefined $ 6g -I _obj util.go util.go:114: syntax error near zzz gobuild: stalemate ; ; gobuild $ 6ar grc _obj/gobuild.a util.6 util1.6 duplicate text symbol: util1.6 and util.6: gobuild·Build $ 6g -I _obj gobuild.go gobuild.go:150: PackageImports: undefined $ 6g -I _obj makefile.go makefile.go:102: ShellString: undefined gobuild: stalemate ; R=r DELTA=95 (49 added, 9 deleted, 37 changed) OCL=29625 CL=29640 --- src/cmd/ar/ar.c | 21 ++++++++---- src/cmd/gobuild/gobuild.go | 23 +++++++++---- src/cmd/gobuild/util.go | 68 ++++++++++++++++++++++++++------------ 3 files changed, 76 insertions(+), 36 deletions(-) diff --git a/src/cmd/ar/ar.c b/src/cmd/ar/ar.c index 733c4b5c87..35a3eeccdb 100644 --- a/src/cmd/ar/ar.c +++ b/src/cmd/ar/ar.c @@ -58,6 +58,7 @@ typedef struct Arsymref { char *name; + char *file; int type; int len; vlong offset; @@ -87,6 +88,7 @@ typedef struct Arfile /* Temp file control block - one per tempfile */ typedef struct Hashchain { char *name; + char *file; struct Hashchain *next; } Hashchain; @@ -148,7 +150,7 @@ void arread(Biobuf*, Armember*, int); void arstream(int, Arfile*); int arwrite(int, Armember*); int bamatch(char*, char*); -int duplicate(char*); +int duplicate(char*, char**); Armember *getdir(Biobuf*); void getpkgdef(char**, int*); int getspace(void); @@ -743,6 +745,7 @@ objsym(Sym *s, void *p) int n; Arsymref *as; Arfile *ap; + char *ofile; if (s->type != 'T' && s->type != 'D') return; @@ -750,9 +753,10 @@ objsym(Sym *s, void *p) as = armalloc(sizeof(Arsymref)); as->offset = ap->size; as->name = arstrdup(s->name); - if(s->type == 'T' && duplicate(as->name)) { + as->file = arstrdup(file); + if(s->type == 'T' && duplicate(as->name, &ofile)) { dupfound = 1; - fprint(2, "duplicate text symbol: %s\n", as->name); + fprint(2, "duplicate text symbol: %s and %s: %s\n", as->file, ofile, as->name); free(as->name); free(as); return; @@ -783,7 +787,7 @@ hashstr(char *name) } int -duplicate(char *name) +duplicate(char *name, char **ofile) { Hashchain *p; int h; @@ -791,12 +795,16 @@ duplicate(char *name) h = hashstr(name) % NHASH; for(p = hash[h]; p; p = p->next) - if(strcmp(p->name, name) == 0) + if(strcmp(p->name, name) == 0) { + *ofile = p->file; return 1; + } p = armalloc(sizeof(Hashchain)); p->next = hash[h]; p->name = name; + p->file = file; hash[h] = p; + *ofile = nil; return 0; } @@ -893,7 +901,7 @@ getdir(Biobuf *b) while(*--cp==' ') ; cp[1] = '\0'; - file = name; + file = arstrdup(name); bp->date = strtol(bp->hdr.date, 0, 0); bp->size = strtol(bp->hdr.size, 0, 0); return bp; @@ -1487,7 +1495,6 @@ loadpkgdata(char *data, int len) char *p, *ep, *prefix, *name, *def; Import *x; - file = arstrdup(file); p = data; ep = data + len; while(parsepkgdata(&p, ep, &export, &prefix, &name, &def) > 0) { diff --git a/src/cmd/gobuild/gobuild.go b/src/cmd/gobuild/gobuild.go index 0db9bca042..c84c7e9277 100644 --- a/src/cmd/gobuild/gobuild.go +++ b/src/cmd/gobuild/gobuild.go @@ -14,6 +14,8 @@ import ( "sort"; "strings"; "template"; + "unicode"; + "utf8"; ) type Pkg struct @@ -148,9 +150,16 @@ func ScanFiles(filenames []string) *Info { f := new(File); f.Name = filename; if path.Ext(filename) == ".go" { + rune, _ := utf8.DecodeRuneInString(filename); + if rune != '_' && !unicode.IsLetter(rune) && !unicode.IsDecimalDigit(rune) { + // Ignore files with funny leading letters, + // to avoid editor files like .foo.go and ~foo.go. + continue; + } + pkgname, imp, err := PackageImports(filename); if err != nil { - fatal("parsing", filename, err.String()); + fatal("parsing %s: %s", filename, err); } if pkgname == "main" { continue; @@ -182,7 +191,7 @@ func ScanFiles(filenames []string) *Info { // non-Go file: fill in package name. // Must only be a single package in this directory. if len(z.Pkgmap) != 1 { - fatal("cannot determine package for ", f.Name); + fatal("cannot determine package for %s", f.Name); } f.Pkg = pkg; } @@ -240,7 +249,7 @@ func (z *Info) Build() { fail = fail[0:0]; success = success[0:0]; for _, f := range pending { - if !Build(Compiler(f.Name), f.Name, false) { + if !Build(Compiler(f.Name), f.Name, 0) { PushFile(&fail, f); } else { if *verbose { @@ -252,7 +261,7 @@ func (z *Info) Build() { if len(success) == 0 { // Nothing ran; give up. for _, f := range fail { - Build(Compiler(f.Name), f.Name, true); + Build(Compiler(f.Name), f.Name, ShowErrors | ForceDisplay); } fatal("stalemate"); } @@ -310,7 +319,7 @@ func Main() { var err os.Error; filenames, err= SourceFiles("."); if err != nil { - fatal("reading .: ", err.String()); + fatal("reading .: %s", err.String()); } } @@ -319,11 +328,11 @@ func Main() { if *writeMakefile { t, err := template.Parse(makefileTemplate, makefileMap); if err != nil { - fatal("template.Parse: ", err.String()); + fatal("template.Parse: %s", err.String()); } err = t.Execute(state, os.Stdout); if err != nil { - fatal("template.Expand: ", err.String()); + fatal("template.Expand: %s", err.String()); } } } diff --git a/src/cmd/gobuild/util.go b/src/cmd/gobuild/util.go index 462d2dc953..e7b3c77890 100644 --- a/src/cmd/gobuild/util.go +++ b/src/cmd/gobuild/util.go @@ -6,8 +6,10 @@ package gobuild import ( + "bufio"; "exec"; "fmt"; + "io"; "go/ast"; "go/parser"; "os"; @@ -17,6 +19,11 @@ import ( "strings"; ) +const ( + ShowErrors = 1<