Commit ff40deee authored by Gustavo Niemeyer's avatar Gustavo Niemeyer Committed by Russ Cox

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
parent 3e042ebb
...@@ -67,12 +67,12 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) { ...@@ -67,12 +67,12 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) {
isCgo[file] = true isCgo[file] = true
} }
oFiles := make([]string, 0, len(dirInfo.cFiles)) cgoOFiles := make([]string, 0, len(dirInfo.cFiles))
for _, file := range dirInfo.cFiles { for _, file := range dirInfo.cFiles {
if !safeName(file) { if !safeName(file) {
return nil, os.ErrorString("unsafe name: " + 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)) goFiles := make([]string, 0, len(dirInfo.goFiles))
...@@ -85,8 +85,16 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) { ...@@ -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 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 { if err := makefileTemplate.Execute(&buf, &md); err != nil {
return nil, err return nil, err
} }
...@@ -106,10 +114,11 @@ func safeName(s string) bool { ...@@ -106,10 +114,11 @@ func safeName(s string) bool {
// makedata is the data type for the makefileTemplate. // makedata is the data type for the makefileTemplate.
type makedata struct { type makedata struct {
Pkg string // package import path Pkg string // package import path
GoFiles []string // list of non-cgo .go files GoFiles []string // list of non-cgo .go files
CgoFiles []string // list of cgo .go files OFiles []string // list of .$O files
OFiles []string // list of ofiles for cgo CgoFiles []string // list of cgo .go files
CgoOFiles []string // list of cgo .o files, without extension
} }
var makefileTemplate = template.MustParse(` var makefileTemplate = template.MustParse(`
...@@ -123,6 +132,13 @@ GOFILES=\ ...@@ -123,6 +132,13 @@ GOFILES=\
{@}\ {@}\
{.end} {.end}
{.end}
{.section OFiles}
OFILES=\
{.repeated section OFiles}
{@}\
{.end}
{.end} {.end}
{.section CgoFiles} {.section CgoFiles}
CGOFILES=\ CGOFILES=\
...@@ -131,9 +147,9 @@ CGOFILES=\ ...@@ -131,9 +147,9 @@ CGOFILES=\
{.end} {.end}
{.end} {.end}
{.section OFiles} {.section CgoOFiles}
CGO_OFILES=\ CGO_OFILES=\
{.repeated section OFiles} {.repeated section CgoOFiles}
{@}\ {@}\
{.end} {.end}
......
...@@ -22,6 +22,7 @@ type dirInfo struct { ...@@ -22,6 +22,7 @@ type dirInfo struct {
goFiles []string // .go files within dir (including cgoFiles) goFiles []string // .go files within dir (including cgoFiles)
cgoFiles []string // .go files that import "C" cgoFiles []string // .go files that import "C"
cFiles []string // .c files within dir cFiles []string // .c files within dir
sFiles []string // .s files within dir
imports []string // All packages imported by goFiles imports []string // All packages imported by goFiles
pkgName string // Name of package within dir pkgName string // Name of package within dir
} }
...@@ -51,6 +52,7 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) { ...@@ -51,6 +52,7 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) {
goFiles := make([]string, 0, len(dirs)) goFiles := make([]string, 0, len(dirs))
cgoFiles := make([]string, 0, len(dirs)) cgoFiles := make([]string, 0, len(dirs))
cFiles := make([]string, 0, len(dirs)) cFiles := make([]string, 0, len(dirs))
sFiles := make([]string, 0, len(dirs))
importsm := make(map[string]bool) importsm := make(map[string]bool)
pkgName := "" pkgName := ""
for i := range dirs { for i := range dirs {
...@@ -61,13 +63,22 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) { ...@@ -61,13 +63,22 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) {
if !goodOSArch(d.Name) { if !goodOSArch(d.Name) {
continue 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) cFiles = append(cFiles, d.Name)
continue continue
} case ".s":
if !strings.HasSuffix(d.Name, ".go") || strings.HasSuffix(d.Name, "_test.go") { sFiles = append(sFiles, d.Name)
continue
default:
continue continue
} }
filename := filepath.Join(dir, d.Name) filename := filepath.Join(dir, d.Name)
pf, err := parser.ParseFile(fset, filename, nil, parser.ImportsOnly) pf, err := parser.ParseFile(fset, filename, nil, parser.ImportsOnly)
if err != nil { if err != nil {
...@@ -110,7 +121,7 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) { ...@@ -110,7 +121,7 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) {
imports[i] = p imports[i] = p
i++ 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 // goodOSArch returns false if the filename contains a $GOOS or $GOARCH
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment