mirror of
https://github.com/golang/go
synced 2024-11-25 02:57:57 -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:
parent
380e5a3709
commit
c562fbc44e
@ -697,7 +697,7 @@ func (p *Package) gccMachine() []string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const gccTmp = "_obj/_cgo_.o"
|
var gccTmp = objDir + "_cgo_.o"
|
||||||
|
|
||||||
// gccCmd returns the gcc command line to use for compiling
|
// gccCmd returns the gcc command line to use for compiling
|
||||||
// the input.
|
// the input.
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -228,7 +229,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
pkg := f.Package
|
pkg := f.Package
|
||||||
if dir := os.Getenv("CGOPKGPATH"); dir != "" {
|
if dir := os.Getenv("CGOPKGPATH"); dir != "" {
|
||||||
pkg = dir + "/" + pkg
|
pkg = filepath.Join(dir, pkg)
|
||||||
}
|
}
|
||||||
p.PackagePath = pkg
|
p.PackagePath = pkg
|
||||||
p.writeOutput(f, input)
|
p.writeOutput(f, input)
|
||||||
|
@ -14,17 +14,20 @@ import (
|
|||||||
"go/printer"
|
"go/printer"
|
||||||
"go/token"
|
"go/token"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var objDir = "_obj" + string(filepath.Separator)
|
||||||
|
|
||||||
// writeDefs creates output files to be compiled by 6g, 6c, and gcc.
|
// 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.)
|
// (The comments here say 6g and 6c but the code applies to the 8 and 5 tools too.)
|
||||||
func (p *Package) writeDefs() {
|
func (p *Package) writeDefs() {
|
||||||
fgo2 := creat("_obj/_cgo_gotypes.go")
|
fgo2 := creat(objDir + "_cgo_gotypes.go")
|
||||||
fc := creat("_obj/_cgo_defun.c")
|
fc := creat(objDir + "_cgo_defun.c")
|
||||||
fm := creat("_obj/_cgo_main.c")
|
fm := creat(objDir + "_cgo_main.c")
|
||||||
|
|
||||||
fflg := creat("_obj/_cgo_flags")
|
fflg := creat(objDir + "_cgo_flags")
|
||||||
for k, v := range p.CgoFlags {
|
for k, v := range p.CgoFlags {
|
||||||
fmt.Fprintf(fflg, "_CGO_%s=%s\n", k, v)
|
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 = base[0 : len(base)-3]
|
||||||
}
|
}
|
||||||
base = strings.Map(slashToUnderscore, base)
|
base = strings.Map(slashToUnderscore, base)
|
||||||
fgo1 := creat("_obj/" + base + ".cgo1.go")
|
fgo1 := creat(objDir + base + ".cgo1.go")
|
||||||
fgcc := creat("_obj/" + base + ".cgo2.c")
|
fgcc := creat(objDir + base + ".cgo2.c")
|
||||||
|
|
||||||
p.GoFiles = append(p.GoFiles, base+".cgo1.go")
|
p.GoFiles = append(p.GoFiles, base+".cgo1.go")
|
||||||
p.GccFiles = append(p.GccFiles, base+".cgo2.c")
|
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
|
// Write out the various stubs we need to support functions exported
|
||||||
// from Go so that they are callable from C.
|
// from Go so that they are callable from C.
|
||||||
func (p *Package) writeExports(fgo2, fc, fm *os.File) {
|
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")
|
fgcch := creat("_cgo_export.h")
|
||||||
|
|
||||||
fmt.Fprintf(fgcch, "/* Created by cgo - DO NOT EDIT. */\n")
|
fmt.Fprintf(fgcch, "/* Created by cgo - DO NOT EDIT. */\n")
|
||||||
|
@ -103,7 +103,7 @@ func creat(name string) *os.File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func slashToUnderscore(c int) int {
|
func slashToUnderscore(c int) int {
|
||||||
if c == '/' {
|
if c == '/' || c == '\\' || c == ':' {
|
||||||
c = '_'
|
c = '_'
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
Loading…
Reference in New Issue
Block a user