executor

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package executor provides recipe execution for Buildfiles. It handles shell invocation, command interpolation, and execution orchestration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveWorkerCount

func ResolveWorkerCount(cliJobs, parallelDirective int) int

ResolveWorkerCount determines the number of workers to use based on CLI -j flag and .parallel: directive value. The -j flag takes precedence when explicitly set (greater than 1), otherwise the .parallel: directive value is used.

Parameters:

  • cliJobs: value from -j flag (default is 1)
  • parallelDirective: value from .parallel: directive in Buildfile (0 if not set)

Returns the number of workers to use, minimum 1.

Types

type CommandError

type CommandError struct {
	Command  string
	ExitCode int
	Stderr   string
}

CommandError represents a command execution failure.

func (*CommandError) Error

func (e *CommandError) Error() string

type ContextFactory

type ContextFactory func(target string) *eval.CommandContext

ContextFactory creates a CommandContext for a target.

type ExecResult

type ExecResult struct {
	Command  string // The command that was executed
	Stdout   string // Standard output
	Stderr   string // Standard error
	ExitCode int    // Exit code (0 = success)
}

ExecResult holds the result of a shell command execution.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor handles shell command execution.

func NewExecutor

func NewExecutor(config *ShellConfig) *Executor

NewExecutor creates a new Executor with the given configuration.

func NewExecutorWithValidation

func NewExecutorWithValidation(config *ShellConfig) (*Executor, error)

NewExecutorWithValidation creates a new Executor and validates the shell. Returns an error if the shell is not found.

func (*Executor) ExecuteBlock

func (e *Executor) ExecuteBlock(script string) (*ExecResult, error)

ExecuteBlock executes a shell script block.

func (*Executor) ExecuteLine

func (e *Executor) ExecuteLine(cmdLine string) (*ExecResult, error)

ExecuteLine executes a single shell command line.

func (*Executor) ExecuteRecipe

func (e *Executor) ExecuteRecipe(recipe *ast.Recipe, cmdCtx *eval.CommandContext) ([]*ExecResult, error)

ExecuteRecipe executes all commands in a recipe. Returns results for each command executed and stops on first error.

func (*Executor) SetEmitter

func (e *Executor) SetEmitter(emitter *output.Emitter)

SetEmitter sets the event emitter for the output system.

func (*Executor) SetOutput

func (e *Executor) SetOutput(w io.Writer)

SetOutput sets the output writer for dry-run and verbose modes.

func (*Executor) SetTarget

func (e *Executor) SetTarget(target string)

SetTarget sets the current target for event context.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler handles parallel execution of build tasks.

func NewScheduler

func NewScheduler(executor *Executor, numWorkers int) *Scheduler

NewScheduler creates a scheduler with the given number of workers.

func (*Scheduler) Execute

func (s *Scheduler) Execute(tasks []planner.BuildTask, ctxFactory ContextFactory) []TaskResult

Execute executes all tasks respecting dependencies.

func (*Scheduler) ExecuteWithCallback

func (s *Scheduler) ExecuteWithCallback(tasks []planner.BuildTask, ctxFactory ContextFactory, callback TaskCallback) []TaskResult

ExecuteWithCallback executes tasks with a callback called at task start.

func (*Scheduler) SetKeepGoing

func (s *Scheduler) SetKeepGoing(keepGoing bool)

SetKeepGoing enables or disables keep-going mode. When enabled, the scheduler continues building independent targets after a failure. Dependent targets are still skipped.

func (*Scheduler) Workers

func (s *Scheduler) Workers() int

Workers returns the number of workers.

type ShellConfig

type ShellConfig struct {
	Shell   string // Path to shell (default: platform-specific)
	DryRun  bool   // If true, print commands without executing
	Verbose bool   // If true, print commands before executing
	Quiet   bool   // If true, suppress command output (only show errors)
}

ShellConfig holds shell configuration for command execution.

func NewShellConfig

func NewShellConfig() *ShellConfig

NewShellConfig creates a new ShellConfig with default values.

func (*ShellConfig) SetShell

func (c *ShellConfig) SetShell(shell string)

SetShell sets the shell path.

func (*ShellConfig) Validate

func (c *ShellConfig) Validate() error

Validate checks that the shell exists and is executable. It handles both absolute paths and shells found via PATH lookup.

func (*ShellConfig) WithOverride

func (c *ShellConfig) WithOverride(shell string) *ShellConfig

WithOverride returns a new config with the shell overridden. The original config is not modified.

type ShellNotFoundError

type ShellNotFoundError struct {
	Shell string
}

ShellNotFoundError represents a missing shell error.

func (*ShellNotFoundError) Error

func (e *ShellNotFoundError) Error() string

type TaskCallback

type TaskCallback func(target string)

TaskCallback is called when a task starts execution.

type TaskResult

type TaskResult struct {
	Target  string        // The target that was built
	Results []*ExecResult // Results from recipe execution
	Error   error         // Error if execution failed
	Skipped bool          // True if task was skipped due to dependency failure
}

TaskResult represents the result of executing a single build task.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL