Skip to content

Commit

Permalink
If the directory contains no Walkfile, don't execute the target, and
Browse files Browse the repository at this point in the history
don't display it.
  • Loading branch information
ejholmes committed Jan 24, 2017
1 parent 4a268f9 commit 0502d1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
23 changes: 8 additions & 15 deletions plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ const (
// targets.
const Walkfile = "Walkfile"

// NoWalkfileError can be returned when a target doesn't have a Walkfile present
// in it's directory.
type NoWalkfileError struct {
Dir string
}

func (e *NoWalkfileError) Error() string {
return fmt.Sprintf("no %s in %s", Walkfile, e.Dir)
}

// Rule defines what a target depends on, and how to execute it.
type Rule interface {
// Dependencies returns the name of the targets that this target depends
Expand Down Expand Up @@ -287,6 +277,11 @@ func (t *target) Name() string {

// Exec executes the rule with "exec" as the first argument.
func (t *target) Exec(ctx context.Context) error {
// No .walk file, meaning it's a static dependency.
if t.rulefile == "" {
return nil
}

cmd, err := t.ruleCommand(ctx, PhaseExec)
if err != nil {
return err
Expand Down Expand Up @@ -332,10 +327,6 @@ func (t *target) Dependencies(ctx context.Context) ([]string, error) {
}

func (t *target) ruleCommand(ctx context.Context, phase string) (*exec.Cmd, error) {
if t.rulefile == "" {
return nil, &NoWalkfileError{Dir: filepath.Dir(t.name)}
}

name := filepath.Base(t.path)
cmd := exec.CommandContext(ctx, t.rulefile, phase, name)
cmd.Stdout = t.stdout
Expand All @@ -362,7 +353,9 @@ func (t *verboseTarget) Exec(ctx context.Context) error {
if err != nil {
line = fmt.Sprintf("%s\t%s", line, err)
}
fmt.Fprintf(t.stdout, "%s\n", line)
if t.rulefile != "" {
fmt.Fprintf(t.stdout, "%s\n", line)
}
if err != nil {
return &targetError{t.target, err}
}
Expand Down
6 changes: 4 additions & 2 deletions plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ func TestPlan_NoWalkfile(t *testing.T) {
assert.NoError(t, err)

err = plan.Exec(ctx, NewSemaphore(0))
assert.Error(t, err)
assert.NoError(t, err)

assert.Equal(t, "error\ttest/000-no-walkfile/all\tno Walkfile in test/000-no-walkfile\n", b.String())
// If there's no Walkfile in the directory, it might just be a static
// file. We don't really need to show these in output.
assert.Equal(t, "", b.String())
}

func TestPrefixWriter(t *testing.T) {
Expand Down

0 comments on commit 0502d1f

Please sign in to comment.