1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:44:40 -07:00

cgo: make file path work for windows

R=golang-dev, mattn.jp, adg
CC=golang-dev
https://golang.org/cl/4634043
This commit is contained in:
Alex Brainman 2011-06-17 10:17:33 +10:00 committed by Andrew Gerrand
parent 380e5a3709
commit c562fbc44e
4 changed files with 14 additions and 10 deletions

View File

@ -697,7 +697,7 @@ func (p *Package) gccMachine() []string {
return nil
}
const gccTmp = "_obj/_cgo_.o"
var gccTmp = objDir + "_cgo_.o"
// gccCmd returns the gcc command line to use for compiling
// the input.

View File

@ -18,6 +18,7 @@ import (
"go/token"
"io"
"os"
"path/filepath"
"reflect"
"strings"
)
@ -228,7 +229,7 @@ func main() {
}
pkg := f.Package
if dir := os.Getenv("CGOPKGPATH"); dir != "" {
pkg = dir + "/" + pkg
pkg = filepath.Join(dir, pkg)
}
p.PackagePath = pkg
p.writeOutput(f, input)

View File

@ -14,17 +14,20 @@ import (
"go/printer"
"go/token"
"os"
"path/filepath"
"strings"
)
var objDir = "_obj" + string(filepath.Separator)
// writeDefs creates output files to be compiled by 6g, 6c, and gcc.
// (The comments here say 6g and 6c but the code applies to the 8 and 5 tools too.)
func (p *Package) writeDefs() {
fgo2 := creat("_obj/_cgo_gotypes.go")
fc := creat("_obj/_cgo_defun.c")
fm := creat("_obj/_cgo_main.c")
fgo2 := creat(objDir + "_cgo_gotypes.go")
fc := creat(objDir + "_cgo_defun.c")
fm := creat(objDir + "_cgo_main.c")
fflg := creat("_obj/_cgo_flags")
fflg := creat(objDir + "_cgo_flags")
for k, v := range p.CgoFlags {
fmt.Fprintf(fflg, "_CGO_%s=%s\n", k, v)
}
@ -285,8 +288,8 @@ func (p *Package) writeOutput(f *File, srcfile string) {
base = base[0 : len(base)-3]
}
base = strings.Map(slashToUnderscore, base)
fgo1 := creat("_obj/" + base + ".cgo1.go")
fgcc := creat("_obj/" + base + ".cgo2.c")
fgo1 := creat(objDir + base + ".cgo1.go")
fgcc := creat(objDir + base + ".cgo2.c")
p.GoFiles = append(p.GoFiles, base+".cgo1.go")
p.GccFiles = append(p.GccFiles, base+".cgo2.c")
@ -361,7 +364,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
// Write out the various stubs we need to support functions exported
// from Go so that they are callable from C.
func (p *Package) writeExports(fgo2, fc, fm *os.File) {
fgcc := creat("_obj/_cgo_export.c")
fgcc := creat(objDir + "_cgo_export.c")
fgcch := creat("_cgo_export.h")
fmt.Fprintf(fgcch, "/* Created by cgo - DO NOT EDIT. */\n")

View File

@ -103,7 +103,7 @@ func creat(name string) *os.File {
}
func slashToUnderscore(c int) int {
if c == '/' {
if c == '/' || c == '\\' || c == ':' {
c = '_'
}
return c