From 50358bcb29cc1af7f0bbbfb58f4e258c54d620f7 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 31 Mar 2023 18:07:50 +0200 Subject: [PATCH] cmd: remove dependency on sed Fixes #266. Signed-off-by: Sebastien Binet --- cmd_build.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd_build.go b/cmd_build.go index 0722629..7b57a7e 100644 --- a/cmd_build.go +++ b/cmd_build.go @@ -5,6 +5,7 @@ package main import ( + "bytes" "fmt" "log" "os" @@ -215,11 +216,17 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error { if bind.WindowsOS { fmt.Printf("Doing windows sed hack to fix declspec for PyInit\n") - cmd = exec.Command("sed", "-i", "s/ PyInit_/ __declspec(dllexport) PyInit_/g", cfg.Name+".c") - cmdout, err = cmd.CombinedOutput() + fname := cfg.Name + ".c" + raw, err := os.ReadFile(fname) if err != nil { - fmt.Printf("cmd had error: %v output:\no%v\n", err, string(cmdout)) - return err + fmt.Printf("could not read %s: %+v", fname, err) + return fmt.Errorf("could not read %s: %w", fname, err) + } + raw = bytes.ReplaceAll(raw, []byte(" PyInit_"), []byte(" __declspec(dllexport) PyInit_")) + err = os.WriteFile(fname, raw, 0644) + if err != nil { + fmt.Printf("could not apply sed hack to fix declspec for PyInit: %+v", err) + return fmt.Errorf("could not apply sed hack to fix PyInit: %w", err) } }