From 1f96c64d6c1562f01a8e2abd15d7b3a5d9a47267 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 30 Aug 2023 09:28:45 -0700 Subject: [PATCH 1/3] make task cache sendable --- crates/turborepo-lib/src/run/cache.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/turborepo-lib/src/run/cache.rs b/crates/turborepo-lib/src/run/cache.rs index e7d07c7652410..cb95547c8c1c8 100644 --- a/crates/turborepo-lib/src/run/cache.rs +++ b/crates/turborepo-lib/src/run/cache.rs @@ -1,4 +1,4 @@ -use std::{io::Write, rc::Rc}; +use std::{io::Write, sync::Arc}; use console::StyledObject; use tracing::{debug, log::warn}; @@ -49,7 +49,7 @@ impl RunCache { } pub fn task_cache( - self: &Rc, + self: &Arc, // TODO: Group these in a struct task_definition: &TaskDefinition, task_dir: &AbsoluteSystemPath, @@ -102,7 +102,7 @@ impl RunCache { pub struct TaskCache { expanded_outputs: Vec, - run_cache: Rc, + run_cache: Arc, repo_relative_globs: TaskOutputs, hash: String, task_output_mode: OutputLogsMode, From b631da34f8b11936909036fbf181ff0d7e900c26 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 30 Aug 2023 09:31:11 -0700 Subject: [PATCH 2/3] remove log file argument --- crates/turborepo-lib/src/run/cache.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/turborepo-lib/src/run/cache.rs b/crates/turborepo-lib/src/run/cache.rs index cb95547c8c1c8..8cc747594f324 100644 --- a/crates/turborepo-lib/src/run/cache.rs +++ b/crates/turborepo-lib/src/run/cache.rs @@ -52,12 +52,13 @@ impl RunCache { self: &Arc, // TODO: Group these in a struct task_definition: &TaskDefinition, - task_dir: &AbsoluteSystemPath, + workspace_dir: &AnchoredSystemPath, task_id: TaskId<'static>, - log_file: &AnchoredSystemPath, hash: &str, ) -> TaskCache { - let log_file_path = self.repo_root.resolve(log_file); + let task_dir = self.repo_root.resolve(workspace_dir); + let log_file_path = + task_dir.join_components(&[".turbo", &format!("turbo-{}.log", task_id.task())]); let hashable_outputs = task_definition.hashable_outputs(&task_id); let mut repo_relative_globs = TaskOutputs { inclusions: Vec::with_capacity(hashable_outputs.inclusions.len()), From fd6d95d0fdb047d027470071fda6fc98a80eaa9b Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 30 Aug 2023 09:32:59 -0700 Subject: [PATCH 3/3] make task cache accessible to the rest of the crate --- crates/turborepo-lib/src/run/cache.rs | 8 ++++---- crates/turborepo-lib/src/run/mod.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/turborepo-lib/src/run/cache.rs b/crates/turborepo-lib/src/run/cache.rs index 8cc747594f324..518f0247a71bd 100644 --- a/crates/turborepo-lib/src/run/cache.rs +++ b/crates/turborepo-lib/src/run/cache.rs @@ -115,7 +115,7 @@ pub struct TaskCache { } impl TaskCache { - fn replay_log_file( + pub fn replay_log_file( &self, prefixed_ui: &mut PrefixedUI, ) -> Result<(), anyhow::Error> { @@ -126,7 +126,7 @@ impl TaskCache { Ok(()) } - fn on_error(&self, prefixed_ui: &mut PrefixedUI) -> Result<(), anyhow::Error> { + pub fn on_error(&self, prefixed_ui: &mut PrefixedUI) -> Result<(), anyhow::Error> { if self.task_output_mode == OutputLogsMode::ErrorsOnly { prefixed_ui.output(format!( "cache miss, executing {}", @@ -138,7 +138,7 @@ impl TaskCache { Ok(()) } - fn output_writer( + pub fn output_writer( &self, prefix: StyledObject, writer: W, @@ -163,7 +163,7 @@ impl TaskCache { Ok(log_writer) } - async fn restore_outputs( + pub async fn restore_outputs( &mut self, team_id: &str, team_slug: Option<&str>, diff --git a/crates/turborepo-lib/src/run/mod.rs b/crates/turborepo-lib/src/run/mod.rs index 960bc8979e9c5..c798ac4d811fc 100644 --- a/crates/turborepo-lib/src/run/mod.rs +++ b/crates/turborepo-lib/src/run/mod.rs @@ -4,13 +4,13 @@ mod cache; mod global_hash; mod scope; pub mod task_id; - use std::{ io::{BufWriter, IsTerminal}, sync::Arc, }; use anyhow::{anyhow, Context as ErrorContext, Result}; +pub use cache::{RunCache, TaskCache}; use itertools::Itertools; use tracing::{debug, info}; use turbopath::AbsoluteSystemPathBuf; @@ -29,7 +29,7 @@ use crate::{ opts::{GraphOpts, Opts}, package_graph::{PackageGraph, WorkspaceName}, package_json::PackageJson, - run::{cache::RunCache, global_hash::get_global_hash_inputs}, + run::global_hash::get_global_hash_inputs, task_graph::Visitor, };