Commit bd6f176b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Builds use their own UI [GH-21]

parent a7a51f1d
...@@ -128,19 +128,11 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -128,19 +128,11 @@ func (c Command) Run(env packer.Environment, args []string) int {
buildUis := make(map[string]packer.Ui) buildUis := make(map[string]packer.Ui)
for i, b := range builds { for i, b := range builds {
var ui packer.Ui ui := &packer.ColoredUi{
ui = &packer.ColoredUi{
Color: colors[i%len(colors)], Color: colors[i%len(colors)],
Ui: env.Ui(), Ui: env.Ui(),
} }
ui = &packer.PrefixedUi{
fmt.Sprintf("==> %s", b.Name()),
fmt.Sprintf(" %s", b.Name()),
ui,
}
buildUis[b.Name()] = ui buildUis[b.Name()] = ui
ui.Say(fmt.Sprintf("%s output will be in this color.", b.Name())) ui.Say(fmt.Sprintf("%s output will be in this color.", b.Name()))
} }
......
...@@ -126,7 +126,7 @@ func (b *coreBuild) Prepare() (err error) { ...@@ -126,7 +126,7 @@ func (b *coreBuild) Prepare() (err error) {
} }
// Runs the actual build. Prepare must be called prior to running this. // Runs the actual build. Prepare must be called prior to running this.
func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) { func (b *coreBuild) Run(originalUi Ui, cache Cache) ([]Artifact, error) {
if !b.prepareCalled { if !b.prepareCalled {
panic("Prepare must be called first") panic("Prepare must be called first")
} }
...@@ -155,8 +155,15 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) { ...@@ -155,8 +155,15 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) {
hook := &DispatchHook{hooks} hook := &DispatchHook{hooks}
artifacts := make([]Artifact, 0, 1) artifacts := make([]Artifact, 0, 1)
// The builder just has a normal Ui, but prefixed
builderUi := &PrefixedUi{
fmt.Sprintf("==> %s", b.Name()),
fmt.Sprintf(" %s", b.Name()),
originalUi,
}
log.Printf("Running builder: %s", b.builderType) log.Printf("Running builder: %s", b.builderType)
builderArtifact, err := b.builder.Run(ui, hook, cache) builderArtifact, err := b.builder.Run(builderUi, hook, cache)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -171,12 +178,18 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) { ...@@ -171,12 +178,18 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) {
keepOriginalArtifact := len(b.postProcessors) == 0 keepOriginalArtifact := len(b.postProcessors) == 0
// Run the post-processors // Run the post-processors
PostProcessorRunSeqLoop: PostProcessorRunSeqLoop:
for _, ppSeq := range b.postProcessors { for _, ppSeq := range b.postProcessors {
priorArtifact := builderArtifact priorArtifact := builderArtifact
for i, corePP := range ppSeq { for i, corePP := range ppSeq {
ui.Say(fmt.Sprintf("Running post-processor: %s", corePP.processorType)) ppUi := &PrefixedUi{
artifact, err := corePP.processor.PostProcess(ui, priorArtifact) fmt.Sprintf("==> %s (%s)", b.Name(), corePP.processorType),
fmt.Sprintf(" %s (%s)", b.Name(), corePP.processorType),
originalUi,
}
builderUi.Say(fmt.Sprintf("Running post-processor: %s", corePP.processorType))
artifact, err := corePP.processor.PostProcess(ppUi, priorArtifact)
if err != nil { if err != nil {
errors = append(errors, fmt.Errorf("Post-processor failed: %s", err)) errors = append(errors, fmt.Errorf("Post-processor failed: %s", err))
continue PostProcessorRunSeqLoop continue PostProcessorRunSeqLoop
...@@ -235,17 +248,17 @@ PostProcessorRunSeqLoop: ...@@ -235,17 +248,17 @@ PostProcessorRunSeqLoop:
} }
return artifacts, err return artifacts, err
} }
func (b *coreBuild) SetDebug(val bool) { func (b *coreBuild) SetDebug(val bool) {
if b.prepareCalled { if b.prepareCalled {
panic("prepare has already been called") panic("prepare has already been called")
} }
b.debug = val b.debug = val
} }
// Cancels the build if it is running. // Cancels the build if it is running.
func (b *coreBuild) Cancel() { func (b *coreBuild) Cancel() {
b.builder.Cancel() b.builder.Cancel()
} }
...@@ -113,7 +113,6 @@ func TestBuild_Run(t *testing.T) { ...@@ -113,7 +113,6 @@ func TestBuild_Run(t *testing.T) {
// Verify builder was run // Verify builder was run
builder := build.builder.(*TestBuilder) builder := build.builder.(*TestBuilder)
assert.True(builder.runCalled, "run should be called") assert.True(builder.runCalled, "run should be called")
assert.Equal(builder.runUi, ui, "run should be called with ui")
// Verify hooks are disapatchable // Verify hooks are disapatchable
dispatchHook := builder.runHook dispatchHook := builder.runHook
......
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