1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:34:42 -07:00

go/build: record all cgo intermediate files (fix build)

R=rsc
CC=golang-dev
https://golang.org/cl/4613045
This commit is contained in:
Andrew Gerrand 2011-06-15 14:29:26 +10:00
parent db5a4ffc2a
commit 4a8de67058
2 changed files with 24 additions and 12 deletions

View File

@ -48,9 +48,10 @@ func Build(tree *Tree, pkg string, info *DirInfo) (*Script, os.Error) {
if len(info.CgoFiles) > 0 { if len(info.CgoFiles) > 0 {
cgoFiles := b.abss(info.CgoFiles...) cgoFiles := b.abss(info.CgoFiles...)
s.addInput(cgoFiles...) s.addInput(cgoFiles...)
outGo, outObj := b.cgo(cgoFiles) outInter, outGo, outObj := b.cgo(cgoFiles)
gofiles = append(gofiles, outGo...) gofiles = append(gofiles, outGo...)
ofiles = append(ofiles, outObj...) ofiles = append(ofiles, outObj...)
s.addIntermediate(outInter...)
s.addIntermediate(outGo...) s.addIntermediate(outGo...)
s.addIntermediate(outObj...) s.addIntermediate(outObj...)
} }
@ -313,7 +314,7 @@ func (b *build) cc(ofile string, cfiles ...string) {
func (b *build) gccCompile(ofile, cfile string) { func (b *build) gccCompile(ofile, cfile string) {
b.add(Cmd{ b.add(Cmd{
Args: gccArgs(b.arch, "-o", ofile, "-c", cfile), Args: b.gccArgs("-o", ofile, "-c", cfile),
Input: []string{cfile}, Input: []string{cfile},
Output: []string{ofile}, Output: []string{ofile},
}) })
@ -321,42 +322,45 @@ func (b *build) gccCompile(ofile, cfile string) {
func (b *build) gccLink(ofile string, ofiles ...string) { func (b *build) gccLink(ofile string, ofiles ...string) {
b.add(Cmd{ b.add(Cmd{
Args: append(gccArgs(b.arch, "-o", ofile), ofiles...), Args: append(b.gccArgs("-o", ofile), ofiles...),
Input: ofiles, Input: ofiles,
Output: []string{ofile}, Output: []string{ofile},
}) })
} }
func gccArgs(arch string, args ...string) []string { func (b *build) gccArgs(args ...string) []string {
// TODO(adg): HOST_CC // TODO(adg): HOST_CC
m := "-m32" m := "-m32"
if arch == "6" { if b.arch == "6" {
m = "-m64" m = "-m64"
} }
return append([]string{"gcc", m, "-I", ".", "-g", "-fPIC", "-O2"}, args...) return append([]string{"gcc", m, "-I", b.path, "-g", "-fPIC", "-O2"}, args...)
} }
func (b *build) cgo(cgofiles []string) (outGo, outObj []string) { func (b *build) cgo(cgofiles []string) (outInter, outGo, outObj []string) {
// cgo // cgo
// TODO(adg): CGOPKGPATH // TODO(adg): CGOPKGPATH
// TODO(adg): CGO_FLAGS // TODO(adg): CGO_FLAGS
gofiles := []string{b.obj + "_cgo_gotypes.go"} gofiles := []string{b.obj + "_cgo_gotypes.go"}
cfiles := []string{b.obj + "_cgo_main.c", b.obj + "_cgo_export.c"} cfiles := []string{b.obj + "_cgo_main.c", b.obj + "_cgo_export.c"}
for _, fn := range cgofiles { for _, fn := range cgofiles {
fn = filepath.Base(fn) f := b.obj + strings.Replace(fn[:len(fn)-2], "/", "_", -1)
f := b.obj + fn[:len(fn)-2]
gofiles = append(gofiles, f+"cgo1.go") gofiles = append(gofiles, f+"cgo1.go")
cfiles = append(cfiles, f+"cgo2.c") cfiles = append(cfiles, f+"cgo2.c")
} }
defunC := b.obj + "_cgo_defun.c" defunC := b.obj + "_cgo_defun.c"
output := append([]string{defunC}, gofiles...) output := append([]string{defunC}, cfiles...)
output = append(output, cfiles...) output = append(output, gofiles...)
b.add(Cmd{ b.add(Cmd{
Args: append([]string{"cgo", "--"}, cgofiles...), Args: append([]string{"cgo", "--"}, cgofiles...),
Dir: b.path,
Input: cgofiles, Input: cgofiles,
Output: output, Output: output,
}) })
outGo = append(outGo, gofiles...) outGo = append(outGo, gofiles...)
exportH := filepath.Join(b.path, "_cgo_export.h")
outInter = append(outInter, exportH, defunC, b.obj+"_cgo_flags")
outInter = append(outInter, cfiles...)
// cc _cgo_defun.c // cc _cgo_defun.c
defunObj := b.obj + "_cgo_defun." + b.arch defunObj := b.obj + "_cgo_defun." + b.arch
@ -371,10 +375,13 @@ func (b *build) cgo(cgofiles []string) (outGo, outObj []string) {
linkobj = append(linkobj, ofile) linkobj = append(linkobj, ofile)
if !strings.HasSuffix(ofile, "_cgo_main.o") { if !strings.HasSuffix(ofile, "_cgo_main.o") {
outObj = append(outObj, ofile) outObj = append(outObj, ofile)
} else {
outInter = append(outInter, ofile)
} }
} }
dynObj := b.obj + "_cgo1_.o" dynObj := b.obj + "_cgo_.o"
b.gccLink(dynObj, linkobj...) b.gccLink(dynObj, linkobj...)
outInter = append(outInter, dynObj)
// cgo -dynimport // cgo -dynimport
importC := b.obj + "_cgo_import.c" importC := b.obj + "_cgo_import.c"
@ -384,6 +391,7 @@ func (b *build) cgo(cgofiles []string) (outGo, outObj []string) {
Input: []string{dynObj}, Input: []string{dynObj},
Output: []string{importC}, Output: []string{importC},
}) })
outInter = append(outInter, importC)
// cc _cgo_import.ARCH // cc _cgo_import.ARCH
importObj := b.obj + "_cgo_import." + b.arch importObj := b.obj + "_cgo_import." + b.arch

View File

@ -50,4 +50,8 @@ func testBuild(t *testing.T, tree *Tree, pkg string) {
return return
} }
} }
if err := s.Clean(); err != nil {
t.Errorf("cleaning: %v", err)
t.Logf("Intermediate: %v", s.Intermediate)
}
} }