Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulkar committed Sep 6, 2022
1 parent 9c2eb01 commit 760787a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,15 +1024,21 @@ func (e *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTask

func (g *completeGraph) getPackageTaskVisitor(ctx gocontext.Context, visitor func(ctx gocontext.Context, packageTask *nodes.PackageTask) error) func(taskID string) error {
return func(taskID string) error {

fmt.Printf("getPackageTaskVisitor()\n")
name, task := util.GetPackageTaskFromId(taskID)

pkg, ok := g.PackageInfos[name]
if !ok {
return fmt.Errorf("cannot find package %v for task %v", name, taskID)
}

// first check for package-tasks
taskDefinition, ok := g.Pipeline[fmt.Sprintf("%v", taskID)]

fmt.Printf("\t taskID: %#v\n", taskID)
fmt.Printf("\t task: %#v\n", task)
fmt.Printf("\t Pipeline:\n\t\t%#v\n", g.Pipeline)
fmt.Printf("\t taskDefintion (looked up with taskID):\n\t\t%#v\n", taskDefinition)
if !ok {
// then check for regular tasks
fallbackTaskDefinition, notcool := g.Pipeline[task]
Expand All @@ -1041,6 +1047,7 @@ func (g *completeGraph) getPackageTaskVisitor(ctx gocontext.Context, visitor fun
return nil
}
// override if we need to...
fmt.Printf("\t fallbackTaskDefinition (looked up with task) %#v\n", fallbackTaskDefinition)
taskDefinition = fallbackTaskDefinition
}
return visitor(ctx, &nodes.PackageTask{
Expand Down
32 changes: 30 additions & 2 deletions cli/internal/taskhash/taskhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type packageFileHashKey string
// hashes the inputs for a packageTask
func (pfs packageFileSpec) ToKey() packageFileHashKey {
sort.Strings(pfs.inputs)
return packageFileHashKey(fmt.Sprintf("%v#%v", pfs.pkg, strings.Join(pfs.inputs, "!")))
xx := fmt.Sprintf("%v#%v", pfs.pkg, strings.Join(pfs.inputs, "!"))
return packageFileHashKey(xx)
}

func safeCompileIgnoreFile(filepath string) (*gitignore.GitIgnore, error) {
Expand Down Expand Up @@ -157,9 +158,11 @@ type packageFileHashes map[packageFileHashKey]string
// CalculateFileHashes hashes each unique package-inputs combination that is present
// in the task graph. Must be called before calculating task hashes.
func (th *Tracker) CalculateFileHashes(allTasks []dag.Vertex, workerCount int, repoRoot turbopath.AbsolutePath) error {
fmt.Printf("CalculateFileHashes()\n")
hashTasks := make(util.Set)

for _, v := range allTasks {
for i, v := range allTasks {
fmt.Printf("\ttask %d: %v\n", i, v)
taskID, ok := v.(string)
if !ok {
return fmt.Errorf("unknown task %v", taskID)
Expand All @@ -169,6 +172,7 @@ func (th *Tracker) CalculateFileHashes(allTasks []dag.Vertex, workerCount int, r
}
pkgName, _ := util.GetPackageTaskFromId(taskID)
if pkgName == th.rootNode {
fmt.Printf("\tContinue\n")
continue
}

Expand All @@ -177,11 +181,16 @@ func (th *Tracker) CalculateFileHashes(allTasks []dag.Vertex, workerCount int, r
return fmt.Errorf("missing pipeline entry %v", taskID)
}

taskDefinition.Inputs = append(taskDefinition.Inputs, "./package.json")

pfs := &packageFileSpec{
pkg: pkgName,
inputs: taskDefinition.Inputs,
}

fmt.Printf("\ttaskDefinition.Inputs: %v\n", taskDefinition.Inputs)
fmt.Printf("\tpfs.inputs: %v\n", pfs.inputs)

hashTasks.Add(pfs)
}

Expand All @@ -202,6 +211,8 @@ func (th *Tracker) CalculateFileHashes(allTasks []dag.Vertex, workerCount int, r
}
th.mu.Lock()
pfsKey := packageFileSpec.ToKey()
fmt.Printf("\tadding to hashes\n")
fmt.Printf("\t\t\"%v\": %v\n", pfsKey, hash)
hashes[pfsKey] = hash
th.mu.Unlock()
}
Expand All @@ -217,6 +228,8 @@ func (th *Tracker) CalculateFileHashes(allTasks []dag.Vertex, workerCount int, r
return err
}
th.packageInputsHashes = hashes

fmt.Printf("\tth.packageInputsHashes: %v\n", th.packageInputsHashes)
return nil
}

Expand Down Expand Up @@ -263,9 +276,24 @@ func (th *Tracker) calculateDependencyHashes(dependencySet dag.Set) ([]string, e
// that it has previously been called on its task-graph dependencies. File hashes must be calculated
// first.
func (th *Tracker) CalculateTaskHash(packageTask *nodes.PackageTask, dependencySet dag.Set, args []string) (string, error) {
fmt.Printf("CalculateTaskHash(): taskID: %v\n", packageTask.TaskID)

fmt.Printf("\ttaskDefinition.Inputs: %v\n", packageTask.TaskDefinition.Inputs)
pfs := specFromPackageTask(packageTask)
fmt.Printf("\tpfs.inputs: %v\n", pfs.inputs)
pkgFileHashKey := pfs.ToKey()

fmt.Printf("\tpkgFileHashKey: %s\n", pkgFileHashKey)

fmt.Printf("\tScripts\n")
for scriptName, script := range packageTask.Pkg.Scripts {
fmt.Printf("\t\t%s: %s\n", scriptName, script)
}

for _, x := range th.packageInputsHashes {
fmt.Printf("\tpackage input hashes: %s\n", x)
}

hashOfFiles, ok := th.packageInputsHashes[pkgFileHashKey]
if !ok {
return "", fmt.Errorf("cannot find package-file hash for %v", pkgFileHashKey)
Expand Down

0 comments on commit 760787a

Please sign in to comment.