Skip to content

Commit

Permalink
Go linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaslyang authored and nicholaslyang committed Sep 8, 2023
1 parent c007694 commit 2bd01b6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
2 changes: 2 additions & 0 deletions cli/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude:
- "func name will be used as hash.Hash.* by other packages, and that stutters; consider calling this"
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vercel/turbo/cli

go 1.20
go 1.19

require (
capnproto.org/go/capnp/v3 v3.0.0-alpha-29
Expand Down
46 changes: 29 additions & 17 deletions cli/internal/fs/hash/capnp.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// capnp.go contains the capnp schema and hashing functions for the turbo cache
// Package hash contains the capnp schema and hashing functions for the turbo cache
//
// it depends on the generated capnp schema in ./capnp. to regenerate the schema,
// you need the capnp binary as well as capnpc-go available in your path. then run:
//
// capnp compile -I std -ogo proto.capnp
//
// in crates/turborepo-lib/src/hash or run `make turbo-capnp` in the `cli` directory.

package hash

import (
Expand Down Expand Up @@ -147,12 +146,15 @@ func HashTaskHashable(task *TaskHashable) (string, error) {
return "", err
}

assignList(task.Outputs.Exclusions, deps.SetExclusions, seg)
err = assignList(task.Outputs.Exclusions, deps.SetExclusions, seg)
if err != nil {
return "", err
}

taskMsg.SetOutputs(deps)
err = taskMsg.SetOutputs(deps)
if err != nil {
return "", err
}
}

err = assignList(task.TaskDependencyHashes, taskMsg.SetTaskDependencyHashes, seg)
Expand Down Expand Up @@ -192,17 +194,16 @@ func HashTaskHashable(task *TaskHashable) (string, error) {
//
// NOTE: This function is _explicitly_ ordered and should not be sorted.
//
// Order is important for the hash, and is as follows:
// - GlobalCacheKey
// - GlobalFileHashMap
// - RootExternalDepsHash
// - Env
// - ResolvedEnvVars
// - PassThroughEnv
// - EnvMode
// - FrameworkInference
// - DotEnv

// Order is important for the hash, and is as follows:
// - GlobalCacheKey
// - GlobalFileHashMap
// - RootExternalDepsHash
// - Env
// - ResolvedEnvVars
// - PassThroughEnv
// - EnvMode
// - FrameworkInference
// - DotEnv
func HashGlobalHashable(global *GlobalHashable) (string, error) {
arena := capnp.SingleSegment(nil)

Expand Down Expand Up @@ -291,6 +292,7 @@ func HashGlobalHashable(global *GlobalHashable) (string, error) {
return HashMessage(globalMsg.Message())
}

// HashLockfilePackages hashes lockfile packages
func HashLockfilePackages(packages []lockfile.Package) (string, error) {
arena := capnp.SingleSegment(nil)

Expand All @@ -305,6 +307,9 @@ func HashLockfilePackages(packages []lockfile.Package) (string, error) {
}

entries, err := globalMsg.NewPackages(int32(len(packages)))
if err != nil {
return "", err
}
for i, pkg := range packages {
entry := entries.At(i)

Expand All @@ -324,6 +329,7 @@ func HashLockfilePackages(packages []lockfile.Package) (string, error) {
return HashMessage(globalMsg.Message())
}

// HashFileHashes hashes files
func HashFileHashes(fileHashes map[turbopath.AnchoredUnixPath]string) (string, error) {
arena := capnp.SingleSegment(nil)

Expand Down Expand Up @@ -425,7 +431,10 @@ func assignList(list []string, fn func(capnp.TextList) error, seg *capnp.Segment
return err
}
for i, v := range list {
textList.Set(i, v)
err = textList.Set(i, v)
if err != nil {
return err
}
}
return fn(textList)
}
Expand All @@ -436,7 +445,10 @@ func assignAnchoredUnixArray(paths turbopath.AnchoredUnixPathArray, fn func(capn
return err
}
for i, v := range paths {
textList.Set(i, v.ToString())
err = textList.Set(i, v.ToString())
if err != nil {
return err
}
}
return fn(textList)
}
2 changes: 1 addition & 1 deletion cli/internal/run/real_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
gocontext "context"
"fmt"
"github.com/vercel/turbo/cli/internal/turbostate"
"io"
"log"
"os"
Expand Down Expand Up @@ -33,6 +32,7 @@ import (
"github.com/vercel/turbo/cli/internal/spinner"
"github.com/vercel/turbo/cli/internal/taskhash"
"github.com/vercel/turbo/cli/internal/turbopath"
"github.com/vercel/turbo/cli/internal/turbostate"
"github.com/vercel/turbo/cli/internal/ui"
"github.com/vercel/turbo/cli/internal/util"
)
Expand Down
1 change: 1 addition & 0 deletions cli/internal/taskhash/taskhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ func (th *Tracker) SetExpandedOutputs(taskID string, outputs []turbopath.Anchore
th.packageTaskOutputs[taskID] = outputs
}

// GetTaskHashes gets the package task hashes
func (th *Tracker) GetTaskHashes() map[string]string {
th.mu.RLock()
defer th.mu.RUnlock()
Expand Down
1 change: 1 addition & 0 deletions cli/internal/turbostate/turbostate.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type ParsedArgsFromRust struct {
Command Command `json:"command"`
}

// TaskHashTracker stores the hashes calculated in Rust
type TaskHashTracker struct {
PackageTaskHashes map[string]string `json:"package_task_hashes"`
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/task_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
};

use rayon::prelude::*;
use serde::Serialize;
use thiserror::Error;
use tracing::debug;
use turbopath::{AbsoluteSystemPath, AnchoredSystemPath, AnchoredSystemPathBuf};
Expand Down

0 comments on commit 2bd01b6

Please sign in to comment.