Skip to content

Commit 5271841

Browse files
authored
Merge pull request #321 from go-python/issue-266
cmd: remove dependency on sed
2 parents 042b254 + 50358bc commit 5271841

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cmd_build.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package main
66

77
import (
8+
"bytes"
89
"fmt"
910
"log"
1011
"os"
@@ -215,11 +216,17 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error {
215216

216217
if bind.WindowsOS {
217218
fmt.Printf("Doing windows sed hack to fix declspec for PyInit\n")
218-
cmd = exec.Command("sed", "-i", "s/ PyInit_/ __declspec(dllexport) PyInit_/g", cfg.Name+".c")
219-
cmdout, err = cmd.CombinedOutput()
219+
fname := cfg.Name + ".c"
220+
raw, err := os.ReadFile(fname)
220221
if err != nil {
221-
fmt.Printf("cmd had error: %v output:\no%v\n", err, string(cmdout))
222-
return err
222+
fmt.Printf("could not read %s: %+v", fname, err)
223+
return fmt.Errorf("could not read %s: %w", fname, err)
224+
}
225+
raw = bytes.ReplaceAll(raw, []byte(" PyInit_"), []byte(" __declspec(dllexport) PyInit_"))
226+
err = os.WriteFile(fname, raw, 0644)
227+
if err != nil {
228+
fmt.Printf("could not apply sed hack to fix declspec for PyInit: %+v", err)
229+
return fmt.Errorf("could not apply sed hack to fix PyInit: %w", err)
223230
}
224231
}
225232

0 commit comments

Comments
 (0)