]> Cypherpunks repositories - gostls13.git/commitdiff
goinstall: handle .s files with gc
authorGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 7 Mar 2011 17:08:52 +0000 (12:08 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 7 Mar 2011 17:08:52 +0000 (12:08 -0500)
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

src/cmd/goinstall/make.go
src/cmd/goinstall/parse.go

index e2d99bb47796ae2e138c31771443c4adb697cce6..5e3523767a38391f7d23b7feb804e478e54d38e8 100644 (file)
@@ -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}
 
index 564ec46bc94e5957f848030d6c1b1f3d3739794d..280e9ea4f7313decf9e8c11951691b29305f99ac 100644 (file)
@@ -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