MCPcopy Index your code
hub / github.com/go-python/gopy / runBuild

Function runBuild

cmd_build.go:95–290  ·  view source on GitHub ↗

runBuild calls genPkg and then executes commands to build the resulting files exe = executable mode to build an executable instead of a library mode = gen, build, pkg, exe

(mode bind.BuildMode, cfg *BuildCfg)

Source from the content-addressed store, hash-verified

93// exe = executable mode to build an executable instead of a library
94// mode = gen, build, pkg, exe
95func runBuild(mode bind.BuildMode, cfg *BuildCfg) error {
96 var err error
97 cfg.OutputDir, err = genOutDir(cfg.OutputDir)
98 if err != nil {
99 return err
100 }
101 err = genPkg(mode, cfg)
102 if err != nil {
103 return err
104 }
105
106 fmt.Printf("\n--- building package ---\n%s\n", cfg.Cmd)
107
108 buildname := cfg.Name + "_go"
109 var cmdout []byte
110 cwd, err := os.Getwd()
111 os.Chdir(cfg.OutputDir)
112 defer os.Chdir(cwd)
113
114 os.Remove(cfg.Name + ".c") // may fail, we don't care
115
116 fmt.Printf("goimports -w %v\n", cfg.Name+".go")
117 cmd := exec.Command("goimports", "-w", cfg.Name+".go")
118 cmdout, err = cmd.CombinedOutput()
119 if err != nil {
120 fmt.Printf("cmd had error: %v output:\no%v\n", err, string(cmdout))
121 return err
122 }
123
124 pycfg, err := bind.GetPythonConfig(cfg.VM)
125
126 if mode == bind.ModeExe {
127 of, err := os.Create(buildname + ".h") // overwrite existing
128 fmt.Fprintf(of, "typedef uint8_t bool;\n")
129 of.Close()
130
131 fmt.Printf("%v build.py # will fail, but needed to generate .c file\n", cfg.VM)
132 cmd = exec.Command(cfg.VM, "build.py")
133 cmd.Run() // will fail, we don't care about errors
134
135 args := []string{"build", "-mod=mod", "-buildmode=c-shared"}
136 if cfg.BuildTags != "" {
137 args = append(args, "-tags", cfg.BuildTags)
138 }
139 args = append(args, "-o", buildname+libExt, ".")
140
141 fmt.Printf("go %v\n", strings.Join(args, " "))
142 cmd = exec.Command("go", args...)
143 cmdout, err = cmd.CombinedOutput()
144 if err != nil {
145 fmt.Printf("cmd had error: %v output:\n%v\n", err, string(cmdout))
146 return err
147 }
148
149 fmt.Printf("%v build.py # should work this time\n", cfg.VM)
150 cmd = exec.Command(cfg.VM, "build.py")
151 cmdout, err = cmd.CombinedOutput()
152 if err != nil {

Callers 3

gopyRunCmdPkgFunction · 0.85
gopyRunCmdBuildFunction · 0.85
gopyRunCmdExeFunction · 0.85

Calls 5

GetPythonConfigFunction · 0.92
genOutDirFunction · 0.85
genPkgFunction · 0.85
PrintfMethod · 0.80
PrintlnMethod · 0.80

Tested by

no test coverage detected