Documentation ¶
Overview ¶
redux is a library for redux, a top down software build tool which implements and extends the redo concept somewhat sparsely described by [DJ Bernstein](http://cr.yp.to/redo.html).
To install it, run
$ go get github.com/gyepisam/redux/redux
The command
$ redux help
provides built-in help, which is augmented by the html, man pages and the README file.
Index ¶
- Constants
- Variables
- func InitDir(dirname string) error
- func RecordRelation(dependent *File, target *File, event Event, m *Metadata) error
- func Verbose() bool
- func WithDB(arg string, f func(DB) error) error
- type Config
- type DB
- type Dependent
- type DoInfo
- type Event
- type File
- func (f *File) Abs(path string) string
- func (f *File) AllDependents() ([]*File, error)
- func (f *File) AsDependent(dir string) Dependent
- func (f *File) AsPrerequisite(dir string, m *Metadata) Prerequisite
- func (f *File) ContentHash() (Hash, error)
- func (f *File) Debug(format string, args ...interface{})
- func (f *File) Delete(key string) error
- func (f *File) DeleteAllDependencies() (err error)
- func (f *File) DeleteAllPrerequisites() error
- func (f *File) DeleteAutoPrerequisites() error
- func (f *File) DeleteDependency(event Event, hash Hash) error
- func (f *File) DeleteMetadata() error
- func (f *File) DeleteMustRebuild() error
- func (f *File) DeletePrerequisite(event Event, hash Hash) error
- func (f *File) DeleteRecords() error
- func (f *File) DependentFiles(prefix string) ([]*File, error)
- func (f *File) DoInfoCandidates() []*DoInfo
- func (f *File) ErrNotFound(m string) error
- func (f *File) ErrUninitialized() error
- func (f *File) Errorf(format string, args ...interface{}) error
- func (f *File) EventDependents(event Event) ([]*File, error)
- func (f *File) Exists() (bool, error)
- func (f *File) Fullpath() string
- func (f *File) GenerateNotifications(oldMeta, newMeta *Metadata) error
- func (f *File) Get(key string, obj interface{}) (bool, error)
- func (f *File) GetMetadata() (Metadata, bool, error)
- func (f *File) GetPrerequisite(event Event, hash Hash) (prereq Prerequisite, found bool, err error)
- func (f *File) HasDoFile() bool
- func (f *File) HasNullDb() bool
- func (f *File) IsCurrent() (bool, error)
- func (f *File) IsTask() bool
- func (f *File) Log(format string, args ...interface{})
- func (f *File) MustRebuild() bool
- func (f *File) NewMetadata() (m *Metadata, err error)
- func (f *File) NewOutput() (*Output, error)
- func (f *File) NotifyDependents(event Event) (err error)
- func (f *File) PrerequisiteFiles(events ...Event) ([]*File, error)
- func (f *File) Prerequisites(events ...Event) (out []*Prerequisite, err error)
- func (f *File) Put(key string, obj interface{}) (err error)
- func (f *File) PutDependency(event Event, hash Hash, dep Dependent) error
- func (f *File) PutMetadata(m *Metadata) error
- func (f *File) PutMustRebuild() error
- func (f *File) PutPrerequisite(event Event, hash Hash, prereq Prerequisite) error
- func (target *File) Redo() error
- func (f *File) RedoDir() string
- func (target *File) RedoIfChange(dependent *File) error
- func (target *File) RedoIfCreate(dependent *File) error
- func (f *File) Rel(path string) string
- func (target *File) RunDoFile(doInfo *DoInfo) (err error)
- func (f *File) SetTaskFlag(isTask bool)
- type FileDb
- func (db *FileDb) Close() error
- func (db *FileDb) Delete(key string) error
- func (db *FileDb) Get(key string) ([]byte, bool, error)
- func (db *FileDb) GetKeys(prefix string) ([]string, error)
- func (db *FileDb) GetRecords(prefix string) ([]Record, error)
- func (db *FileDb) GetValues(prefix string) ([][]byte, error)
- func (db *FileDb) IsNull() bool
- func (db *FileDb) Put(key string, value []byte) error
- type Hash
- type Metadata
- type NullDb
- func (db *NullDb) Close() error
- func (db *NullDb) Delete(key string) error
- func (db *NullDb) Get(key string) ([]byte, bool, error)
- func (db *NullDb) GetKeys(prefix string) ([]string, error)
- func (db *NullDb) GetRecords(prefix string) ([]Record, error)
- func (db *NullDb) GetValues(prefix string) ([][]byte, error)
- func (db *NullDb) IsNull() bool
- func (db *NullDb) Put(key string, value []byte) error
- type Output
- type Prerequisite
- type Record
- type RelPath
- type Relation
Constants ¶
const ( // TASK_PREFIX is a marker for scripts that don't produce content. TASK_PREFIX = `@` // REDO_DIR names the hidden directory used for data and configuration. REDO_DIR = ".redo" // REDO_DIR_ENV_NAME names the environment variable for the REDO_DIR hidden directory. REDO_DIR_ENV_NAME = "REDO_DIR" // KEY_SEPARATOR is used to join the parts of the database key. KEY_SEPARATOR = "/" // AUTO marks system generated event records. AUTO = "auto" // Directory creation permission mode DIR_PERM = 0755 // Extension for do scripts DO_EXT = "do" // Basename for default script DO_BASENAME = "default" // Extension separator EXT_SEP = "." DEFAULT_TARGET = "all" DEFAULT_DO = DEFAULT_TARGET + EXT_SEP + DO_EXT )
const (
// Where is data kept?
DATA_DIR = "data"
)
Variables ¶
var ( Verbosity = len(os.Getenv("REDO_VERBOSE")) Debug = len(os.Getenv("REDO_DEBUG")) > 0 ShellArgs = os.Getenv("REDO_SHELL_ARGS") )
Options default to env values, to be overriden by main() if necessary.
var NullKeyErr = errors.New("Key cannot be empty.")
var NullPrefixErr = errors.New("Prefix cannot be empty.")
Functions ¶
func RecordRelation ¶
Types ¶
type DB ¶
type DB interface { IsNull() bool // Put stores value under key Put(key string, value []byte) error // Get returns the value stored under key and a boolean indicating // whether the returned value was actually found in the database. Get(key string) ([]byte, bool, error) // Delete removes the value stored under key. // If key does not exist, the operation is a noop. Delete(key string) error // GetKeys returns a list of keys which have the specified key as a prefix. GetKeys(prefix string) ([]string, error) // GetValues returns a list of values whose keys matching the specified key prefix. GetValues(prefix string) ([][]byte, error) // GetRecords returns a list of records (keys and data) matchign the specified key prefix. GetRecords(prefix string) ([]Record, error) Close() error }
DB allows allows for multiple implementations of the redo database.
type DoInfo ¶
type DoInfo struct { Dir string Name string Arg2 string //do file arg2. Depends on target and do file names. RelDir string //relative directory to target from do script. Missing []string //more specific do scripts that were not found. }
A DoInfo represents an active do file.
type Event ¶
type Event string
Event names a change or create event
const ( IFCREATE Event = "ifcreate" IFCHANGE Event = "ifchange" AUTO_IFCREATE Event = AUTO + KEY_SEPARATOR + "ifcreate" AUTO_IFCHANGE Event = AUTO + KEY_SEPARATOR + "ifchange" )
Events of note
type File ¶
type File struct { Target string // file name argument to redo, redo-ifchange, redo-ifcreate, etc RootDir string // contains .redo directory Path string // Relative to RootDir Dir string Name string Ext string // File extension. Could be empty. Includes preceding dot. PathHash Hash // SHA1 hash of Path. Used as database key. FullPathHash Hash //SHA1 hash of RootDir/Path. Used for loop detection. DoFile string // Do script used to generate target output. Config Config // contains filtered or unexported fields }
File represents a source or target file..
func NewFile ¶
NewFile creates and returns a File instance for the given path. If the path is not fully qualified, it is made relative to dir. The newly created instance is initialized with the database specified by the configuration file found in its root directory or the default database. If a file does not have a root directory, it is initialized with a NullDb and HasNullDb will return true.
func (*File) AllDependents ¶
func (*File) AsDependent ¶
func (*File) AsPrerequisite ¶
func (f *File) AsPrerequisite(dir string, m *Metadata) Prerequisite
func (*File) ContentHash ¶
ContentHash returns a cryptographic hash of the file contents.
func (*File) DeleteAllDependencies ¶
func (*File) DeleteAllPrerequisites ¶
DeleteAllPrerequisites removed all of the file's prerequisites.
func (*File) DeleteAutoPrerequisites ¶
DeleteAutoPrerequisites removes all of the file's system generated prerequisites.
func (*File) DeleteMetadata ¶
DeleteMetadata removes the metadata record, if any, from the database.
func (*File) DeleteMustRebuild ¶
DeleteMustRebuild removed the database record.
func (*File) DeletePrerequisite ¶
DeletePrerequisite removes a single prerequisite.
func (*File) DeleteRecords ¶
Delete removes a target's database records
func (*File) DoInfoCandidates ¶
DoInfoCandidates generates a list of possible do filenames for this file
func (*File) ErrNotFound ¶
ErrNotFound is used when the current file is expected to exists and does not.
func (*File) ErrUninitialized ¶
ErrUninitialized denotes an uninitialized directory.
func (*File) GenerateNotifications ¶
func (*File) GetMetadata ¶
GetMetadata returns a record as a metadata structure found denotes whether the record was found.
func (*File) GetPrerequisite ¶
GetPrerequisite returns the prerequisite for the event and hash. If the record does not exist, found is false and err is nil.
func (*File) IsTask ¶
IsTask denotes when the current target is a task script, either explicitly (-task argument to redo) or implicitly (name begins with @ or name is default task).
func (*File) MustRebuild ¶
MustRebuild returns a boolean denoting whether the target must be rebuilt.
func (*File) NewMetadata ¶
NewMetadata computes and returns the file metadata.
func (*File) NotifyDependents ¶
NotifyDependents flags dependents as out of date because target has been created, modified, or deleted.
func (*File) PrerequisiteFiles ¶
PrerequisiteFiles returns a slice of *File objects for the file's prerequisites for the list of events.
func (*File) Prerequisites ¶
func (f *File) Prerequisites(events ...Event) (out []*Prerequisite, err error)
Prerequisites returns a slice of prerequisites for the file.
func (*File) PutDependency ¶
func (*File) PutMetadata ¶
PutMetadata stores the file's metadata in the database.
func (*File) PutMustRebuild ¶
PutMustRebuild sets the eponymous database record value.
func (*File) PutPrerequisite ¶
func (f *File) PutPrerequisite(event Event, hash Hash, prereq Prerequisite) error
PutPrerequisite stores the given prerequisite using a key based on the event and hash.
func (*File) RedoIfChange ¶
RedoIfChange runs redo on the target if it is out of date or its current state disagrees with its dependent's version of its state.
func (*File) RedoIfCreate ¶
RedoIfCreate records a dependency record on a file that does not yet exist
func (*File) RunDoFile ¶
RunDoFile executes the do file script, records the metadata for the resulting output, then saves the resulting output to the target file, if applicable. The execution is equivalent to: sh target.ext.do target.ext target outfn > out0 A well behaved .do file writes to stdout (out0) or to the $3 file (outfn), but not both.
func (*File) SetTaskFlag ¶
type FileDb ¶
type FileDb struct {
DataDir string
}
FileDb is a file based DB for storing Redo relationships and metadata.
type Metadata ¶
File Metadata.
func NewMetadata ¶
NewMetadata returns a metadata instance for the given path. If the file is not found, nil is returned.
type NullDb ¶
type NullDb struct { }
NullDb is a blackhole database, used for source files outside the redo project directory structure.. It never fails, all writes disappear, and reads return nothing.
func (*NullDb) Delete ¶
Delete removes the value stored under key. If key does not exist, the operation is a noop.
func (*NullDb) Get ¶
Get returns the value stored under key and a boolean indicating whether the returned value was actually found in the database.
func (*NullDb) GetRecords ¶
GetRecords returns a list of records (keys and data) matchign the specified key prefix.
type Output ¶
An Output is the output of a .do scripts, either through stdout or $3 (Arg3) If the .do script invocation is equivalent to the sh command,
sh target.ext.do target.ext target tmp0 > tmp1
tmp0 and tmp1 would be outputs.
type Prerequisite ¶
type Prerequisite struct { Path string // path back to target of prerequisite. *Metadata // target's metadata upon record creation. }
Prerequisite from a source to a target.