Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaslyang authored and nicholaslyang committed Sep 12, 2023
1 parent ed6b84e commit fbd8415
Show file tree
Hide file tree
Showing 12 changed files with 1,414 additions and 51 deletions.
27 changes: 21 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions cli/internal/fs/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/vercel/turbo/cli/internal/env"
"io"
"strconv"

Expand Down Expand Up @@ -39,17 +38,6 @@ func HashTask(task *hash.TaskHashable) (string, error) {

// HashGlobal produces the global hash value to be incorporated in every task hash
func HashGlobal(global hash.GlobalHashable) (string, error) {
global.GlobalFileHashMap = map[turbopath.AnchoredUnixPath]string{}
if global.ResolvedEnvVars == nil {
global.ResolvedEnvVars = env.EnvironmentVariablePairs{}
}
if global.PassThroughEnv == nil {
global.PassThroughEnv = []string{}
}
if global.DotEnv == nil {
global.DotEnv = []turbopath.AnchoredUnixPath{}
}

b, _ := json.MarshalIndent(global, "", " ")
fmt.Println(string(b))
return hash.HashGlobalHashable(&global)
Expand Down
9 changes: 3 additions & 6 deletions cli/internal/fs/hash/capnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ package hash

import (
"encoding/hex"
"fmt"
"sort"
"strings"

capnp "capnproto.org/go/capnp/v3"
"github.com/vercel/turbo/cli/internal/env"
Expand Down Expand Up @@ -387,11 +385,10 @@ func HashMessage(msg *capnp.Message) (string, error) {
return "", err
}

bytesStr := make([]string, len(bytes))
for i, b := range bytes {
bytesStr[i] = fmt.Sprintf("%d", b)
err = turbopath.AbsoluteSystemPath("go-global-hash.capnp").WriteFile(bytes, 0644)
if err != nil {
return "", err
}
fmt.Printf("go buffer: %v\n", strings.Join(bytesStr, ", "))

digest := xxhash.New()
_, err = digest.Write(bytes)
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ uds_windows = "1.0.2"
async-io = "1.12.0"

[build-dependencies]
capnpc = "0.17.2"
capnpc = "0.18.0"
tonic-build = "0.8.4"
18 changes: 7 additions & 11 deletions crates/turborepo-lib/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
mod traits;

use std::collections::{BTreeMap, HashMap};
use std::collections::HashMap;

use capnp::message::{Builder, HeapAllocator};
use serde::Serialize;
pub use traits::TurboHash;
use turborepo_env::ResolvedEnvMode;

Expand Down Expand Up @@ -42,7 +41,6 @@ mod proto_capnp {
}
}

#[derive(Debug)]
pub struct TaskHashable<'a> {
// hashes
pub(crate) global_hash: &'a str,
Expand All @@ -64,10 +62,10 @@ pub struct TaskHashable<'a> {
pub(crate) dot_env: &'a [turbopath::RelativeUnixPathBuf],
}

#[derive(Debug, Serialize)]
#[derive(Debug, Clone)]
pub struct GlobalHashable<'a> {
pub global_cache_key: &'static str,
pub global_file_hash_map: BTreeMap<turbopath::RelativeUnixPathBuf, String>,
pub global_file_hash_map: HashMap<turbopath::RelativeUnixPathBuf, String>,
pub root_external_dependencies_hash: String,
pub env: &'a [String],
pub resolved_env_vars: Vec<String>,
Expand All @@ -80,7 +78,7 @@ pub struct GlobalHashable<'a> {
pub struct LockFilePackages(pub Vec<turborepo_lockfiles::Package>);

#[derive(Debug, Clone)]
pub struct FileHashes(pub BTreeMap<turbopath::RelativeUnixPathBuf, String>);
pub struct FileHashes(pub HashMap<turbopath::RelativeUnixPathBuf, String>);

impl From<TaskOutputs> for Builder<HeapAllocator> {
fn from(value: TaskOutputs) -> Self {
Expand Down Expand Up @@ -336,12 +334,11 @@ impl<'a> From<GlobalHashable<'a>> for Builder<HeapAllocator> {
}
}

let env_mode = match hashable.env_mode {
builder.set_env_mode(match hashable.env_mode {
EnvMode::Infer => proto_capnp::global_hashable::EnvMode::Infer,
EnvMode::Loose => proto_capnp::global_hashable::EnvMode::Loose,
EnvMode::Strict => proto_capnp::global_hashable::EnvMode::Strict,
};
builder.set_env_mode(env_mode);
});

builder.set_framework_inference(hashable.framework_inference);

Expand All @@ -363,7 +360,6 @@ impl<'a> From<GlobalHashable<'a>> for Builder<HeapAllocator> {
+ 1; // + 1 to solve an off by one error inside capnp
let mut canon_builder =
Builder::new(HeapAllocator::default().first_segment_words(size as u32));

canon_builder
.set_root_canonical(builder.reborrow_as_reader())
.expect("can't fail");
Expand Down Expand Up @@ -404,7 +400,7 @@ mod test {
dot_env: &[turbopath::RelativeUnixPathBuf::new("dotenv".to_string()).unwrap()],
};

assert_eq!(task_hashable.hash(), "87819c32d170ce59");
assert_eq!(task_hashable.hash(), "ff765ee2f83bc034");
}

#[test]
Expand Down
5 changes: 2 additions & 3 deletions crates/turborepo-lib/src/hash/proto.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ struct TaskHashable {
dotEnv @12 :List(Text);

enum EnvMode {
infer @0;
loose @1;
strict @2;
loose @0;
strict @1;
}
}

Expand Down
Loading

0 comments on commit fbd8415

Please sign in to comment.