42 lines
777 B
Go
42 lines
777 B
Go
package build
|
|
|
|
import (
|
|
"path/filepath"
|
|
)
|
|
|
|
// Build describes a compiler build.
|
|
type Build struct {
|
|
Directory string
|
|
WriteExecutable bool
|
|
}
|
|
|
|
// New creates a new build.
|
|
func New(directory string) *Build {
|
|
return &Build{
|
|
Directory: directory,
|
|
WriteExecutable: true,
|
|
}
|
|
}
|
|
|
|
// Run parses the input files and generates an executable file.
|
|
func (build *Build) Run() error {
|
|
functions, err := Compile(build.Directory)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !build.WriteExecutable {
|
|
return nil
|
|
}
|
|
|
|
path := build.Executable()
|
|
code, data := Finalize(functions)
|
|
return Write(path, code, data)
|
|
}
|
|
|
|
// Executable returns the path to the executable.
|
|
func (build *Build) Executable() string {
|
|
return filepath.Join(build.Directory, filepath.Base(build.Directory))
|
|
}
|