From: Gustavo Niemeyer Date: Mon, 7 Mar 2011 17:08:52 +0000 (-0500) Subject: goinstall: handle .s files with gc X-Git-Tag: weekly.2011-03-15~102 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ff40deee6234dc8ad72af0dba1a28c1047f497f6;p=gostls13.git goinstall: handle .s files with gc As a data point, with this change goinstall is able to fully build package big out of the box. R=rsc CC=golang-dev https://golang.org/cl/4264049 --- diff --git a/src/cmd/goinstall/make.go b/src/cmd/goinstall/make.go index e2d99bb477..5e3523767a 100644 --- a/src/cmd/goinstall/make.go +++ b/src/cmd/goinstall/make.go @@ -67,12 +67,12 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) { isCgo[file] = true } - oFiles := make([]string, 0, len(dirInfo.cFiles)) + cgoOFiles := make([]string, 0, len(dirInfo.cFiles)) for _, file := range dirInfo.cFiles { if !safeName(file) { return nil, os.ErrorString("unsafe name: " + file) } - oFiles = append(oFiles, file[:len(file)-2]+".o") + cgoOFiles = append(cgoOFiles, file[:len(file)-2]+".o") } goFiles := make([]string, 0, len(dirInfo.goFiles)) @@ -85,8 +85,16 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) { } } + oFiles := make([]string, 0, len(dirInfo.sFiles)) + for _, file := range dirInfo.sFiles { + if !safeName(file) { + return nil, os.ErrorString("unsafe name: " + file) + } + oFiles = append(oFiles, file[:len(file)-2]+".$O") + } + var buf bytes.Buffer - md := makedata{pkg, goFiles, cgoFiles, oFiles} + md := makedata{pkg, goFiles, oFiles, cgoFiles, cgoOFiles} if err := makefileTemplate.Execute(&buf, &md); err != nil { return nil, err } @@ -106,10 +114,11 @@ func safeName(s string) bool { // makedata is the data type for the makefileTemplate. type makedata struct { - Pkg string // package import path - GoFiles []string // list of non-cgo .go files - CgoFiles []string // list of cgo .go files - OFiles []string // list of ofiles for cgo + Pkg string // package import path + GoFiles []string // list of non-cgo .go files + OFiles []string // list of .$O files + CgoFiles []string // list of cgo .go files + CgoOFiles []string // list of cgo .o files, without extension } var makefileTemplate = template.MustParse(` @@ -123,6 +132,13 @@ GOFILES=\ {@}\ {.end} +{.end} +{.section OFiles} +OFILES=\ +{.repeated section OFiles} + {@}\ +{.end} + {.end} {.section CgoFiles} CGOFILES=\ @@ -131,9 +147,9 @@ CGOFILES=\ {.end} {.end} -{.section OFiles} +{.section CgoOFiles} CGO_OFILES=\ -{.repeated section OFiles} +{.repeated section CgoOFiles} {@}\ {.end} diff --git a/src/cmd/goinstall/parse.go b/src/cmd/goinstall/parse.go index 564ec46bc9..280e9ea4f7 100644 --- a/src/cmd/goinstall/parse.go +++ b/src/cmd/goinstall/parse.go @@ -22,6 +22,7 @@ type dirInfo struct { goFiles []string // .go files within dir (including cgoFiles) cgoFiles []string // .go files that import "C" cFiles []string // .c files within dir + sFiles []string // .s files within dir imports []string // All packages imported by goFiles pkgName string // Name of package within dir } @@ -51,6 +52,7 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) { goFiles := make([]string, 0, len(dirs)) cgoFiles := make([]string, 0, len(dirs)) cFiles := make([]string, 0, len(dirs)) + sFiles := make([]string, 0, len(dirs)) importsm := make(map[string]bool) pkgName := "" for i := range dirs { @@ -61,13 +63,22 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) { if !goodOSArch(d.Name) { continue } - if strings.HasSuffix(d.Name, ".c") { + + switch filepath.Ext(d.Name) { + case ".go": + if strings.HasSuffix(d.Name, "_test.go") { + continue + } + case ".c": cFiles = append(cFiles, d.Name) continue - } - if !strings.HasSuffix(d.Name, ".go") || strings.HasSuffix(d.Name, "_test.go") { + case ".s": + sFiles = append(sFiles, d.Name) + continue + default: continue } + filename := filepath.Join(dir, d.Name) pf, err := parser.ParseFile(fset, filename, nil, parser.ImportsOnly) if err != nil { @@ -110,7 +121,7 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) { imports[i] = p i++ } - return &dirInfo{goFiles, cgoFiles, cFiles, imports, pkgName}, nil + return &dirInfo{goFiles, cgoFiles, cFiles, sFiles, imports, pkgName}, nil } // goodOSArch returns false if the filename contains a $GOOS or $GOARCH