Commit 587d3598 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Builder.Prepare can return an error

parent d6efe3c7
......@@ -15,6 +15,8 @@ type Builder struct {
config config
}
func (*Builder) Prepare(interface{}) {}
func (*Builder) Prepare(interface{}) error {
return nil
}
func (*Builder) Run(packer.Build, packer.Ui) {}
......@@ -3,7 +3,7 @@ package packer
// A Build represents a single job within Packer that is responsible for
// building some machine image artifact. Builds are meant to be parallelized.
type Build interface {
Prepare()
Prepare() error
Run(ui Ui)
}
......@@ -29,15 +29,15 @@ type coreBuild struct {
//
// Run is where the actual build should take place. It takes a Build and a Ui.
type Builder interface {
Prepare(config interface{})
Prepare(config interface{}) error
Run(build Build, ui Ui)
}
// Prepare prepares the build by doing some initialization for the builder
// and any hooks. This _must_ be called prior to Run.
func (b *coreBuild) Prepare() {
func (b *coreBuild) Prepare() error {
b.prepareCalled = true
b.builder.Prepare(b.rawConfig)
return b.builder.Prepare(b.rawConfig)
}
// Runs the actual build. Prepare must be called prior to running this.
......
......@@ -13,9 +13,10 @@ type TestBuilder struct {
runUi Ui
}
func (tb *TestBuilder) Prepare(config interface{}) {
func (tb *TestBuilder) Prepare(config interface{}) error {
tb.prepareCalled = true
tb.prepareConfig = config
return nil
}
func (tb *TestBuilder) Run(b Build, ui Ui) {
......
......@@ -13,13 +13,13 @@ type cmdBuilder struct {
client *client
}
func (b *cmdBuilder) Prepare(config interface{}) {
func (b *cmdBuilder) Prepare(config interface{}) error {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
b.builder.Prepare(config)
return b.builder.Prepare(config)
}
func (b *cmdBuilder) Run(build packer.Build, ui packer.Ui) {
......
......@@ -9,7 +9,9 @@ import (
type helperBuilder byte
func (helperBuilder) Prepare(interface{}) {}
func (helperBuilder) Prepare(interface{}) error {
return nil
}
func (helperBuilder) Run(packer.Build, packer.Ui) {}
......
......@@ -23,8 +23,9 @@ type BuildRunArgs struct {
UiRPCAddress string
}
func (b *Build) Prepare() {
b.client.Call("Build.Prepare", new(interface{}), new(interface{}))
func (b *Build) Prepare() (err error) {
b.client.Call("Build.Prepare", new(interface{}), &err)
return
}
func (b *Build) Run(ui packer.Ui) {
......@@ -36,10 +37,8 @@ func (b *Build) Run(ui packer.Ui) {
b.client.Call("Build.Run", args, new(interface{}))
}
func (b *BuildServer) Prepare(args *BuildPrepareArgs, reply *interface{}) error {
b.build.Prepare()
*reply = nil
func (b *BuildServer) Prepare(args *BuildPrepareArgs, reply *error) error {
*reply = b.build.Prepare()
return nil
}
......
......@@ -13,8 +13,9 @@ type testBuild struct {
runUi packer.Ui
}
func (b *testBuild) Prepare() {
func (b *testBuild) Prepare() error {
b.prepareCalled = true
return nil
}
func (b *testBuild) Run(ui packer.Ui) {
......
......@@ -29,8 +29,9 @@ func Builder(client *rpc.Client) *builder {
return &builder{client}
}
func (b *builder) Prepare(config interface{}) {
b.client.Call("Builder.Prepare", &BuilderPrepareArgs{config}, new(interface{}))
func (b *builder) Prepare(config interface{}) (err error) {
b.client.Call("Builder.Prepare", &BuilderPrepareArgs{config}, &err)
return
}
func (b *builder) Run(build packer.Build, ui packer.Ui) {
......@@ -44,9 +45,8 @@ func (b *builder) Run(build packer.Build, ui packer.Ui) {
b.client.Call("Builder.Run", args, new(interface{}))
}
func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *interface{}) error {
b.builder.Prepare(args.Config)
*reply = nil
func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
*reply = b.builder.Prepare(args.Config)
return nil
}
......
......@@ -15,9 +15,10 @@ type testBuilder struct {
runUi packer.Ui
}
func (b *testBuilder) Prepare(config interface{}) {
func (b *testBuilder) Prepare(config interface{}) error {
b.prepareCalled = true
b.prepareConfig = config
return nil
}
func (b *testBuilder) Run(build packer.Build, ui packer.Ui) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment