mirror of https://github.com/go-python/gopy.git
all: copy+use cpy-seq support code into wrapping package
This commit is contained in:
parent
aace95d243
commit
0063d38cf4
|
@ -26,6 +26,10 @@ const (
|
|||
#include "memoryobject.h"
|
||||
#include "bufferobject.h"
|
||||
|
||||
// cpy-seq support
|
||||
#include "cgopy_seq_cpy.h"
|
||||
#include "_cgopy_seq_export.h"
|
||||
|
||||
// header exported from 'go tool cgo'
|
||||
#include "%[3]s.h"
|
||||
|
||||
|
|
53
gen.go
53
gen.go
|
@ -14,6 +14,7 @@ import (
|
|||
"go/scanner"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -75,6 +76,43 @@ func genPkg(odir string, p *bind.Package, lang string) error {
|
|||
}
|
||||
defer o.Close()
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bindpkg, err := build.Import("github.com/go-python/gopy/bind", cwd, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, fname := range []string{
|
||||
"cgopy_seq_cpy.h",
|
||||
"cgopy_seq_cpy.c",
|
||||
"cgopy_seq_cpy.go",
|
||||
} {
|
||||
ftmpl, err := os.Open(filepath.Join(bindpkg.Dir, "_cpy", fname))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ftmpl.Close()
|
||||
|
||||
fout, err := os.Create(filepath.Join(odir, fname))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fout.Close()
|
||||
|
||||
_, err = io.Copy(fout, ftmpl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = fout.Close() // explicit to catch filesystem errors
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = bind.GenGo(o, fset, p, pyvers)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -102,6 +140,21 @@ func genPkg(odir string, p *bind.Package, lang string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
seqhdr := filepath.Join(odir, "_cgopy_seq_export.h")
|
||||
cmd = exec.Command(
|
||||
"go", "tool", "cgo",
|
||||
"-exportheader", seqhdr,
|
||||
filepath.Join(odir, "cgopy_seq_cpy.go"),
|
||||
)
|
||||
cmd.Dir = tmpdir
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown target language: %q\n", lang)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue