()
| 583 | } |
| 584 | |
| 585 | func (g *pyGen) genGoPreamble() { |
| 586 | pkgimport := "" |
| 587 | for pp, pnm := range current.imports { |
| 588 | _, psfx := filepath.Split(pp) |
| 589 | if psfx != pnm { |
| 590 | pkgimport += fmt.Sprintf("\n\t%s %q", pnm, pp) |
| 591 | } else { |
| 592 | pkgimport += fmt.Sprintf("\n\t%q", pp) |
| 593 | } |
| 594 | } |
| 595 | libcfg := func() string { |
| 596 | pycfg, err := GetPythonConfig(g.cfg.VM) |
| 597 | if err != nil { |
| 598 | panic(err) |
| 599 | } |
| 600 | var ldflags string |
| 601 | if g.mode == ModeExe || !g.dynamicLink { |
| 602 | ldflags = pycfg.LdFlags |
| 603 | } else { |
| 604 | ldflags = pycfg.LdDynamicFlags |
| 605 | } |
| 606 | // this is critical to avoid pybindgen errors: |
| 607 | exflags := " -Wno-error -Wno-implicit-function-declaration -Wno-int-conversion" |
| 608 | pkgcfg := fmt.Sprintf(` |
| 609 | #cgo CFLAGS: %s |
| 610 | #cgo LDFLAGS: %s |
| 611 | `, pycfg.CFlags+exflags, ldflags) |
| 612 | |
| 613 | return pkgcfg |
| 614 | }() |
| 615 | |
| 616 | if g.mode == ModeExe && g.cfg.Main == "" { |
| 617 | g.cfg.Main = "GoPyMainRun()" // default is just to run main |
| 618 | } |
| 619 | exeprec := "" |
| 620 | exeprego := "" |
| 621 | if g.mode == ModeExe { |
| 622 | exeprec = fmt.Sprintf(goExePreambleC, g.cfg.Name) |
| 623 | exeprego = goExePreambleGo |
| 624 | } |
| 625 | g.gofile.Printf(goPreamble, g.cfg.Name, g.cfg.Cmd, libcfg, GoHandle, CGoHandle, |
| 626 | pkgimport, g.cfg.Main, exeprec, exeprego) |
| 627 | g.gofile.Printf("\n// --- generated code for package: %[1]s below: ---\n\n", g.cfg.Name) |
| 628 | } |
| 629 | |
| 630 | func (g *pyGen) genPyBuildPreamble() { |
| 631 | g.pybuild.Printf(PyBuildPreamble, g.cfg.Name, g.cfg.Cmd) |
no test coverage detected