Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix turbo engine task builder #2981

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/internal/core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (e *Engine) AddDep(fromTaskID string, toTaskID string) error {
return fmt.Errorf("found reference to unknown package: %v in task %v", fromPkg, fromTaskID)
}

if _, ok := e.PackageTaskDeps[fromTaskID]; !ok {
if _, ok := e.PackageTaskDeps[toTaskID]; !ok {
e.PackageTaskDeps[toTaskID] = []string{}
}

Expand Down
47 changes: 47 additions & 0 deletions cli/internal/core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,53 @@ func TestDependOnMissingRootTask(t *testing.T) {
}
}

func TestDependOnMultiplePackageTasks(t *testing.T) {
graph := &dag.AcyclicGraph{}
graph.Add("app1")
graph.Add("libA")
graph.Connect(dag.BasicEdge("app1", "libA"))

p := NewEngine(graph)
dependOnBuild := make(util.Set)
dependOnBuild.Add("build")

p.AddTask(&Task{
Name: "build",
TopoDeps: dependOnBuild,
Deps: make(util.Set),
})
p.AddTask(&Task{
Name: "compile",
TopoDeps: dependOnBuild,
Deps: make(util.Set),
})
err := p.AddDep("app1#build", "libA#build")
assert.NilError(t, err, "AddDep")

err = p.AddDep("app1#compile", "libA#build")
assert.NilError(t, err, "AddDep")

err = p.Prepare(&EngineBuildingOptions{
Packages: []string{"app1"},
TaskNames: []string{"build"},
})
assert.NilError(t, err, "Prepare")

actual := strings.TrimSpace(p.TaskGraph.String())
expected := strings.TrimSpace(`
app1#build
libA#build
app1#compile
libA#build
libA#build
app1#build
app1#compile`)
expected = strings.TrimSpace(expected)
if actual != expected {
t.Errorf("task graph got:\n%v\nwant:\n%v", actual, expected)
}
}

func TestDependOnUnenabledRootTask(t *testing.T) {
graph := &dag.AcyclicGraph{}
graph.Add("app1")
Expand Down