diff --git a/packer/rpc/builder.go b/packer/rpc/builder.go index dd23c7dbf..52ccdac9c 100644 --- a/packer/rpc/builder.go +++ b/packer/rpc/builder.go @@ -46,10 +46,18 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact { RegisterHook(server, hook) args := &BuilderRunArgs{serveSingleConn(server)} - b.client.Call("Builder.Run", args, new(interface{})) - // TODO: artifact - return nil + var reply string + if err := b.client.Call("Builder.Run", args, &reply); err != nil { + panic(err) + } + + client, err := rpc.Dial("tcp", reply) + if err != nil { + panic(err) + } + + return Artifact(client) } func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error { @@ -61,7 +69,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error { return nil } -func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error { +func (b *BuilderServer) Run(args *BuilderRunArgs, reply *string) error { client, err := rpc.Dial("tcp", args.RPCAddress) if err != nil { return err @@ -69,8 +77,12 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error { hook := Hook(client) ui := &Ui{client} - b.builder.Run(ui, hook) + artifact := b.builder.Run(ui, hook) - *reply = nil + // Wrap the artifact + server := rpc.NewServer() + RegisterArtifact(server, artifact) + + *reply = serveSingleConn(server) return nil } diff --git a/packer/rpc/builder_test.go b/packer/rpc/builder_test.go index de12bddbb..be36b5aae 100644 --- a/packer/rpc/builder_test.go +++ b/packer/rpc/builder_test.go @@ -7,6 +7,8 @@ import ( "testing" ) +var testBuilderArtifact = &testArtifact{} + type testBuilder struct { prepareCalled bool prepareConfig interface{} @@ -25,7 +27,7 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact { b.runCalled = true b.runHook = hook b.runUi = ui - return nil + return testBuilderArtifact } func TestBuilderRPC(t *testing.T) { @@ -53,7 +55,7 @@ func TestBuilderRPC(t *testing.T) { // Test Run hook := &testHook{} ui := &testUi{} - bClient.Run(ui, hook) + artifact := bClient.Run(ui, hook) assert.True(b.runCalled, "runs hould be called") if b.runCalled { @@ -63,6 +65,8 @@ func TestBuilderRPC(t *testing.T) { b.runUi.Say("format") assert.True(ui.sayCalled, "say should be called") assert.Equal(ui.sayFormat, "format", "format should be correct") + + assert.Equal(artifact.Id(), testBuilderArtifact.Id(), "should have artifact Id") } }