Skip to content

Commit

Permalink
bake: build binary
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Jun 14, 2024
1 parent b90a982 commit e043210
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
8 changes: 3 additions & 5 deletions bake/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ import (
"github.com/DavidGamba/dgtools/run"
)

func buildPlugin(dir string) error {
func buildBinary(dir string) error {
files, modified, err := fsmodtime.Target(os.DirFS(dir),
[]string{"bake.so"},
[]string{"bake"},
[]string{"*.go", "go.mod", "go.sum"})
if err != nil {
return err
}
if modified {
Logger.Printf("Found modifications on %v, rebuilding...\n", files)
// Debug flags
// return run.CMD("go", "build", "-buildmode=plugin", "-o=bake.so", "-trimpath", "-gcflags", "all=-N -l").Dir(dir).Log().Run()
return run.CMD("go", "build", "-buildmode=plugin", "-o=bake.so").Dir(dir).Log().Run()
return run.CMD("go", "build").Dir(dir).Log().Run()
}
return nil
}
Expand Down
18 changes: 6 additions & 12 deletions bake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,18 @@ func program(args []string) int {
}
Dir = dir

// bakefile, plug, err := loadPlugin(ctx)
// if err != nil {
// fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
// return 1
// }

// err = loadOptFns(ctx, plug, opt, filepath.Dir(bakefile))
// if err != nil {
// fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
// return 1
// }

InputArgs = args[1:]
// TODO: Ensure we populate TM
err = LoadAst(ctx, opt, dir)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
return 1
}
err = buildBinary(dir)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
return 1
}

b := opt.NewCommand("_bake", "")

Expand Down
22 changes: 0 additions & 22 deletions bake/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"path/filepath"
"plugin"
"regexp"
"strings"
Expand All @@ -13,26 +11,6 @@ import (
"github.com/DavidGamba/go-getoptions/dag"
)

func loadPlugin(ctx context.Context) (string, *plugin.Plugin, error) {
dir, err := findBakeDir(ctx)
if err != nil {
return "", nil, err
}

err = buildPlugin(dir)
if err != nil {
return "", nil, fmt.Errorf("failed to build: %w", err)
}
bakefile := filepath.Join(dir, "bake.so")

plug, err := plugin.Open(bakefile)
if err != nil {
_ = os.Remove(bakefile)
return bakefile, nil, fmt.Errorf("failed to open plugin, try again: %w", err)
}
return bakefile, plug, nil
}

// loadOptFns - loads all TaskFn functions from the plugin and adds them as commands to opt.
// If TM task map is defined, add the tasks to the map.
func loadOptFns(ctx context.Context, plug *plugin.Plugin, opt *getoptions.GetOpt, dir string) error {
Expand Down

0 comments on commit e043210

Please sign in to comment.