project

package
v1.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2016 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Format is the supported format
	Format = "hypermake.v0"
	// RootFile is hmake filename sits on root
	RootFile = "HyperMake"
	// WorkFolder is the name of project WorkFolder
	WorkFolder = ".hmake"
	// SummaryFileName is the filename of summary
	SummaryFileName = "hmake.summary.json"
	// LogFileName is the filename of hmake debug log
	LogFileName = "hmake.debug.log"
)
View Source
const (
	// SettingExecDriver is the property name of exec-driver
	SettingExecDriver = "exec-driver"
)

Variables

View Source
var (
	// DefaultExecDriver specify the default exec-driver to use
	DefaultExecDriver string
)
View Source
var ErrUnsupportedFormat = fmt.Errorf("unsupported format")

ErrUnsupportedFormat indicates the file is not recognized

Functions

func RegisterExecDriver

func RegisterExecDriver(name string, runner Runner)

RegisterExecDriver registers a runner

Types

type Command

type Command struct {
	Shell string                 `json:"*"`
	Ext   map[string]interface{} `json:"*"`
}

Command defines a single command to execute

type EventHandler

type EventHandler func(event interface{})

EventHandler receives event notifications during execution of plan

type EvtTaskActivated

type EvtTaskActivated struct {
	Task *Task
}

EvtTaskActivated is emitted when task is queued

type EvtTaskFinish

type EvtTaskFinish struct {
	Task *Task
}

EvtTaskFinish is emitted when task finishes

type EvtTaskOutput

type EvtTaskOutput struct {
	Task   *Task
	Output []byte
}

EvtTaskOutput is emitted when output is received

type EvtTaskStart

type EvtTaskStart struct {
	Task *Task
}

EvtTaskStart is emitted before task gets run

type ExecPlan

type ExecPlan struct {
	// Project is the wrapped project
	Project *Project
	// Tasks are the tasks need execution
	Tasks map[string]*Task
	// Env is pre-defined environment variables
	Env map[string]string
	// WorkPath is full path to hmake state dir ProjectDir/.hmake
	WorkPath string
	// MaxConcurrency defines maximum number of tasks being executed in parallel
	// if it's 0, the number of CPU cores are counted
	MaxConcurrency int
	// RebuildAll force rebuild everything regardless of success mark
	RebuildAll bool
	// RebuildTargets specify targets to rebuild regardless of success mark
	RebuildTargets map[string]bool
	// SkippedTargets specify targets to be marked as Skipped
	SkippedTargets map[string]bool
	// RequiredTargets are names of targets explicitly required
	RequiredTargets []string
	// RunnerFactory specifies the custom runner factory
	RunnerFactory RunnerFactory
	// DebugLog enables logging debug info into .hmake/hmake.debug.log
	DebugLog bool
	// Dryrun will skip the actual execution of target, just return success
	DryRun bool
	// WaitingTasks are tasks in waiting state
	WaitingTasks map[string]*Task
	// QueuedTasks are tasks in Queued state
	QueuedTasks []*Task
	// RunningTasks are tasks in Running state
	RunningTasks map[string]*Task
	// FinishedTasks are tasks in finished state
	FinishedTasks []*Task
	// EventHandler handles the events during execution
	EventHandler EventHandler
	// Summary is the report of all executed targets
	Summary []map[string]interface{}
	// contains filtered or unexported fields
}

ExecPlan describes the plan for execution

func NewExecPlan

func NewExecPlan(project *Project) *ExecPlan

NewExecPlan creates an ExecPlan for a Project

func (*ExecPlan) AddTarget

func (p *ExecPlan) AddTarget(t *Target) (*Task, bool)

AddTarget adds a target into execution plan

func (*ExecPlan) Execute

func (p *ExecPlan) Execute() error

Execute start execution

func (*ExecPlan) GenerateSummary

func (p *ExecPlan) GenerateSummary() (err error)

GenerateSummary dumps summary to summary file

func (*ExecPlan) OnEvent

func (p *ExecPlan) OnEvent(handler EventHandler) *ExecPlan

OnEvent subscribes the events

func (*ExecPlan) Rebuild

func (p *ExecPlan) Rebuild(targets ...string) *ExecPlan

Rebuild specify specific targets to be rebuilt

func (*ExecPlan) Require

func (p *ExecPlan) Require(targets ...string) error

Require adds targets to be executed

func (*ExecPlan) Skip

func (p *ExecPlan) Skip(targets ...string) *ExecPlan

Skip specify the targets to be skipped

type File

type File struct {
	// Format indicates file format
	Format string `json:"format"`
	// Name is name of the project
	Name string `json:"name"`
	// Desc is description of the project
	Desc string `json:"description"`
	// Targets are targets defined in current file
	Targets map[string]*Target `json:"targets"`
	// Settings are properties
	Settings Settings `json:"settings"`
	// Includes are patterns for sourcing external files
	Includes []string `json:"includes"`

	// Source is the relative path to the file
	Source string `json:"-"`
}

File defines the content of HyperMake or .hmake file

func LoadFile

func LoadFile(baseDir, path string) (*File, error)

LoadFile loads from specified path

func (*File) Merge

func (f *File) Merge(s *File) error

Merge merges content from another file

type Project

type Project struct {
	// Name is name of the project
	Name string
	// BaseDir is the root directory of project
	BaseDir string
	// LaunchPath is relative path under BaseDir where hmake launches
	LaunchPath string
	// MasterFile is the file with everything merged
	MasterFile File

	// All loaded make files
	Files []*File

	// Tasks are built from resolved targets
	Targets TargetNameMap
}

Project is the world view of hmake

func LoadProject

func LoadProject() (p *Project, err error)

LoadProject locates, resolves and finalizes project

func LoadProjectFrom

func LoadProjectFrom(startDir string) (p *Project, err error)

LoadProjectFrom locates, resolves and finalizes project from startDir

func LocateProject

func LocateProject() (*Project, error)

LocateProject creates a project by locating the root file

func LocateProjectFrom

func LocateProjectFrom(startDir string) (*Project, error)

LocateProjectFrom creates a project by locating the root file from startDir

func (*Project) DebugLogFile

func (p *Project) DebugLogFile() string

DebugLogFile returns the fullpath to debug log file

func (*Project) Finalize

func (p *Project) Finalize() error

Finalize builds up the relationship between targets and settings and also verifies any cyclic dependencies

func (*Project) GetSettings

func (p *Project) GetSettings(v interface{}) error

GetSettings maps settings into provided variable

func (*Project) GetSettingsIn

func (p *Project) GetSettingsIn(name string, v interface{}) error

GetSettingsIn maps settings[name] into provided variable

func (*Project) Glob

func (p *Project) Glob(pattern string) (paths []string, err error)

Glob matches files inside project with pattern

func (*Project) Load

func (p *Project) Load(path string) (*File, error)

Load loads and merges an additional files

func (*Project) MergeSettingsFlat

func (p *Project) MergeSettingsFlat(flat map[string]interface{}) error

MergeSettingsFlat merges settings from a flat key/value map

func (*Project) Plan

func (p *Project) Plan() *ExecPlan

Plan creates an ExecPlan for this project

func (*Project) Resolve

func (p *Project) Resolve() error

Resolve loads additional includes

func (*Project) SummaryFile

func (p *Project) SummaryFile() string

SummaryFile returns the fullpath to summary file

func (*Project) TargetNames

func (p *Project) TargetNames() []string

TargetNames returns sorted target names

func (*Project) WorkPath

func (p *Project) WorkPath() string

WorkPath returns the internal state folder (.hmake) for hmake

type Runner

type Runner func(*Task) (TaskResult, error)

Runner is the handler execute a target

type RunnerFactory

type RunnerFactory func(*Task) (Runner, error)

RunnerFactory creates a runner from a task

type Settings

type Settings map[string]interface{}

Settings applies to targets

func (Settings) Merge

func (s Settings) Merge(s1 Settings) error

Merge merges settings s1 into s

func (Settings) MergeFlat

func (s Settings) MergeFlat(flat map[string]interface{}) error

MergeFlat merges settings from a flat key/value map The key in flat map can be splitted by "." for a more complicated hierarchy

type Target

type Target struct {
	Name       string                 `json:"name"`
	Desc       string                 `json:"description"`
	Before     []string               `json:"before"`
	After      []string               `json:"after"`
	ExecDriver string                 `json:"exec-driver"`
	Envs       []string               `json:"envs"`
	Cmds       []*Command             `json:"cmds"`
	Script     string                 `json:"script"`
	Watches    []string               `json:"watches"`
	Ext        map[string]interface{} `json:"*"`

	Project   *Project      `json:"-"`
	Source    string        `json:"-"`
	Depends   TargetNameMap `json:"-"`
	Activates TargetNameMap `json:"-"`
}

Target defines a build target

func (*Target) AddDep

func (t *Target) AddDep(dep *Target)

AddDep adds a dependency with corresponding activates

func (*Target) BuildWatchList

func (t *Target) BuildWatchList() (list WatchList)

BuildWatchList collects current state of all watched items

func (*Target) Errorf

func (t *Target) Errorf(format string, args ...interface{}) error

Errorf formats an error related to the target

func (*Target) GetExt

func (t *Target) GetExt(v interface{}) error

GetExt maps Ext to provided value

func (*Target) GetSettings

func (t *Target) GetSettings(name string, v interface{}) error

GetSettings extracts the value from settings stack

func (*Target) GetSettingsWithExt

func (t *Target) GetSettingsWithExt(name string, v interface{}) (err error)

GetSettingsWithExt extracts the value from Ext and settings stack

func (*Target) Initialize

func (t *Target) Initialize(name string, project *Project)

Initialize prepare fields in target

type TargetNameMap

type TargetNameMap map[string]*Target

TargetNameMap is targets mapping by name

func (TargetNameMap) Add

func (m TargetNameMap) Add(t *Target) error

Add adds a target to name map

func (TargetNameMap) BuildDeps

func (m TargetNameMap) BuildDeps() error

BuildDeps builds direct depends and activates

func (TargetNameMap) CheckCyclicDeps

func (m TargetNameMap) CheckCyclicDeps() error

CheckCyclicDeps detects cycles in depenencies

type Task

type Task struct {
	// Plan is ExecPlan owns the task
	Plan *ExecPlan
	// Target is wrapped target
	Target *Target
	// Depends is the tasks being depended on
	// The task is activated when depends is empty
	Depends map[string]*Task
	// State indicates task state
	State TaskState
	// Result indicates the result of the task
	Result TaskResult
	// Error represents any error happened during execution
	Error error
	// StartTime
	StartTime time.Time
	// FinishTime
	FinishTime time.Time
	// contains filtered or unexported fields
}

Task is the execution state of a target

func NewTask

func NewTask(p *ExecPlan, t *Target) *Task

NewTask creates a task for a target

func (*Task) BuildScript

func (t *Task) BuildScript() string

BuildScript generates script file according to cmds/script in target

func (*Task) BuildScriptFile

func (t *Task) BuildScriptFile() (string, error)

BuildScriptFile generates the script file using default generated script

func (*Task) BuildSuccessMark

func (t *Task) BuildSuccessMark() error

BuildSuccessMark checks if the task can be skipped

func (*Task) CalcSuccessMark

func (t *Task) CalcSuccessMark() bool

CalcSuccessMark calculates the watchlist digest and checks if the task can be skipped

func (*Task) ClearSuccessMark

func (t *Task) ClearSuccessMark() error

ClearSuccessMark removes the success mark

func (*Task) Duration

func (t *Task) Duration() time.Duration

Duration is how long the task executed

func (*Task) Exec

func (t *Task) Exec(command string, args ...string) error

Exec executes an external command for a task

func (*Task) ExecScript

func (t *Task) ExecScript() error

ExecScript executes generated script

func (*Task) IsActivated

func (t *Task) IsActivated() bool

IsActivated indicates the task is ready to run

func (*Task) LogFile

func (t *Task) LogFile() string

LogFile returns the fullpath to log filename

func (*Task) Name

func (t *Task) Name() string

Name returns the name of wrapped target

func (*Task) Project

func (t *Task) Project() *Project

Project returns the associated project

func (*Task) Runner

func (t *Task) Runner() (Runner, error)

Runner gets runner according to exec-driver

func (*Task) ScriptFile

func (t *Task) ScriptFile() string

ScriptFile returns the filename of script

func (*Task) SuccessMarkFile

func (t *Task) SuccessMarkFile() string

SuccessMarkFile returns the filename of success mark

func (*Task) Summary

func (t *Task) Summary() map[string]interface{}

Summary generates summary info of the task

func (*Task) Write

func (t *Task) Write(p []byte) (int, error)

Write implements io.Writer to receive execution output

func (*Task) WriteScriptFile

func (t *Task) WriteScriptFile(script string) error

WriteScriptFile builds the script file with provided script

type TaskResult

type TaskResult int

TaskResult indicates the result of task execution

const (
	Unknown TaskResult = iota
	Success
	Failure
	Skipped
)

Task results

func (TaskResult) String

func (r TaskResult) String() string

type TaskState

type TaskState int

TaskState indicates the state of task

const (
	Waiting TaskState = iota
	Queued
	Running
	Finished
)

Task states

func (TaskState) String

func (r TaskState) String() string

type WatchItem

type WatchItem struct {
	// Path is relative path to the project root
	Path string
	// ModTime is the modification time of the item
	ModTime time.Time
}

WatchItem contains information the target watches

type WatchList

type WatchList []*WatchItem

WatchList is list of watched items

func (WatchList) Digest

func (w WatchList) Digest() string

Digest calculates the digest based watched items

func (WatchList) IsEmpty

func (w WatchList) IsEmpty() bool

IsEmpty indicates the watch list is empty

func (WatchList) String

func (w WatchList) String() string

String formats the watch list as a string

Jump to

Keyboard shortcuts

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