From 4b4b840f2a2b18bd7f6e10ea247eaac4472dd667 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:29:53 -0700 Subject: [PATCH] Fix lints. --- .../src/actions/install_deps.rs | 2 +- .../action-pipeline/src/actions/setup_tool.rs | 10 ++-- .../src/subscribers/moonbase.rs | 2 +- .../action-pipeline/tests/estimator_test.rs | 48 +++++++++---------- crates/core/action/src/node.rs | 14 +++--- crates/core/tool/src/manager.rs | 6 +-- .../rust/platform/tests/rust_platform_test.rs | 17 ++++--- 7 files changed, 50 insertions(+), 49 deletions(-) diff --git a/crates/core/action-pipeline/src/actions/install_deps.rs b/crates/core/action-pipeline/src/actions/install_deps.rs index 2029ce91e27..c0b7eca3d15 100644 --- a/crates/core/action-pipeline/src/actions/install_deps.rs +++ b/crates/core/action-pipeline/src/actions/install_deps.rs @@ -46,7 +46,7 @@ pub async fn install_deps( ) -> miette::Result { env::set_var("MOON_RUNNING_ACTION", "install-deps"); - if matches!(runtime, Runtime::System) { + if runtime.platform.is_system() { return Ok(ActionStatus::Skipped); } diff --git a/crates/core/action-pipeline/src/actions/setup_tool.rs b/crates/core/action-pipeline/src/actions/setup_tool.rs index a2c64b064f2..399fbdac188 100644 --- a/crates/core/action-pipeline/src/actions/setup_tool.rs +++ b/crates/core/action-pipeline/src/actions/setup_tool.rs @@ -27,7 +27,7 @@ pub async fn setup_tool( ) -> miette::Result { env::set_var("MOON_RUNNING_ACTION", "setup-tool"); - if matches!(runtime, Runtime::System) { + if runtime.platform.is_system() { return Ok(ActionStatus::Skipped); } @@ -40,11 +40,9 @@ pub async fn setup_tool( let workspace = workspace.write().await; let context = context.read().await; - let mut state = workspace.cache_engine.cache_state::(format!( - "tool{}-{}.json", - runtime, - runtime.version() - ))?; + let mut state = workspace + .cache_engine + .cache_state::(format!("tool{}-{}.json", runtime, runtime.requirement))?; // Install and setup the specific tool + version in the toolchain! let installed_count = PlatformManager::write() diff --git a/crates/core/action-pipeline/src/subscribers/moonbase.rs b/crates/core/action-pipeline/src/subscribers/moonbase.rs index 28f1d1cd555..18e63479b4d 100644 --- a/crates/core/action-pipeline/src/subscribers/moonbase.rs +++ b/crates/core/action-pipeline/src/subscribers/moonbase.rs @@ -460,7 +460,7 @@ impl Subscriber for MoonbaseSubscriber { // Create a fake action label so that we can check the CI cache let action_label = - ActionNode::RunTarget(Runtime::System, (*target).to_owned()) + ActionNode::RunTarget(Runtime::system(), (*target).to_owned()) .label(); let job_id = self.job_ids.get(&action_label).cloned(); diff --git a/crates/core/action-pipeline/tests/estimator_test.rs b/crates/core/action-pipeline/tests/estimator_test.rs index df655aa6db1..13bea75f702 100644 --- a/crates/core/action-pipeline/tests/estimator_test.rs +++ b/crates/core/action-pipeline/tests/estimator_test.rs @@ -31,7 +31,7 @@ mod estimator { let est = Estimator::calculate( &[Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "proj:task".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "proj:task".into())), ..Action::default() }], Duration::new(5, 0), @@ -58,27 +58,27 @@ mod estimator { &[ Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "a:build".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "a:build".into())), ..Action::default() }, Action { duration: Some(Duration::new(5, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "a:lint".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "a:lint".into())), ..Action::default() }, Action { duration: Some(Duration::new(15, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "b:build".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "b:build".into())), ..Action::default() }, Action { duration: Some(Duration::new(8, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "c:test".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "c:test".into())), ..Action::default() }, Action { duration: Some(Duration::new(12, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "d:lint".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "d:lint".into())), ..Action::default() }, ], @@ -113,17 +113,17 @@ mod estimator { &[ Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::SetupTool(Runtime::System)), + node: Some(ActionNode::SetupTool(Runtime::system())), ..Action::default() }, Action { duration: Some(Duration::new(25, 0)), - node: Some(ActionNode::InstallDeps(Runtime::System)), + node: Some(ActionNode::InstallDeps(Runtime::system())), ..Action::default() }, Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "proj:task".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "proj:task".into())), ..Action::default() }, ], @@ -153,7 +153,7 @@ mod estimator { let est = Estimator::calculate( &[Action { duration: Some(Duration::new(3, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "proj:task".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "proj:task".into())), status: ActionStatus::Cached, ..Action::default() }], @@ -181,37 +181,37 @@ mod estimator { &[ Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::SetupTool(Runtime::System)), + node: Some(ActionNode::SetupTool(Runtime::system())), ..Action::default() }, Action { duration: Some(Duration::new(25, 0)), - node: Some(ActionNode::InstallDeps(Runtime::System)), + node: Some(ActionNode::InstallDeps(Runtime::system())), ..Action::default() }, Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "a:build".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "a:build".into())), ..Action::default() }, Action { duration: Some(Duration::new(5, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "a:lint".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "a:lint".into())), ..Action::default() }, Action { duration: Some(Duration::new(15, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "b:build".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "b:build".into())), ..Action::default() }, Action { duration: Some(Duration::new(8, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "c:test".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "c:test".into())), ..Action::default() }, Action { duration: Some(Duration::new(12, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "d:lint".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "d:lint".into())), ..Action::default() }, ], @@ -250,37 +250,37 @@ mod estimator { &[ Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::SetupTool(Runtime::System)), + node: Some(ActionNode::SetupTool(Runtime::system())), ..Action::default() }, Action { duration: Some(Duration::new(25, 0)), - node: Some(ActionNode::InstallDeps(Runtime::System)), + node: Some(ActionNode::InstallDeps(Runtime::system())), ..Action::default() }, Action { duration: Some(Duration::new(10, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "a:build".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "a:build".into())), ..Action::default() }, Action { duration: Some(Duration::new(5, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "a:lint".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "a:lint".into())), ..Action::default() }, Action { duration: Some(Duration::new(15, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "b:build".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "b:build".into())), ..Action::default() }, Action { duration: Some(Duration::new(8, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "c:test".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "c:test".into())), ..Action::default() }, Action { duration: Some(Duration::new(12, 0)), - node: Some(ActionNode::RunTarget(Runtime::System, "d:lint".into())), + node: Some(ActionNode::RunTarget(Runtime::system(), "d:lint".into())), ..Action::default() }, ], diff --git a/crates/core/action/src/node.rs b/crates/core/action/src/node.rs index b2332c45186..5637fa7c258 100644 --- a/crates/core/action/src/node.rs +++ b/crates/core/action/src/node.rs @@ -37,18 +37,18 @@ impl ActionNode { match self { ActionNode::InstallDeps(runtime) => { if runtime.requirement.is_latest() { - format!("Install{}Deps", runtime.platform) + format!("Install{}Deps", runtime) } else { - format!("Install{}Deps({})", runtime.platform, runtime.requirement) + format!("Install{}Deps({})", runtime, runtime.requirement) } } ActionNode::InstallProjectDeps(runtime, id) => { if runtime.requirement.is_latest() { - format!("Install{}DepsInProject({id})", runtime.platform) + format!("Install{}DepsInProject({id})", runtime) } else { format!( "Install{}DepsInProject({}, {id})", - runtime.platform, runtime.requirement + runtime, runtime.requirement ) } } @@ -57,13 +57,13 @@ impl ActionNode { ActionNode::RunPersistentTarget(_, id) => format!("RunPersistentTarget({id})"), ActionNode::SetupTool(runtime) => { if runtime.requirement.is_latest() { - format!("Setup{}Tool", runtime.platform) + format!("Setup{}Tool", runtime) } else { - format!("Setup{}Tool({})", runtime.platform, runtime.requirement) + format!("Setup{}Tool({})", runtime, runtime.requirement) } } ActionNode::SyncProject(runtime, id) => { - format!("Sync{}Project({id})", runtime.platform) + format!("Sync{}Project({id})", runtime) } ActionNode::SyncWorkspace => "SyncWorkspace".into(), } diff --git a/crates/core/tool/src/manager.rs b/crates/core/tool/src/manager.rs index 81dcb82d523..c88c0ac768f 100644 --- a/crates/core/tool/src/manager.rs +++ b/crates/core/tool/src/manager.rs @@ -34,7 +34,7 @@ impl ToolManager { } pub fn has(&self, req: &RuntimeReq) -> bool { - self.cache.contains_key(&req) + self.cache.contains_key(req) } pub fn register(&mut self, req: &RuntimeReq, tool: T) { @@ -52,14 +52,14 @@ impl ToolManager { req: &RuntimeReq, last_versions: &mut FxHashMap, ) -> miette::Result { - match self.cache.get_mut(&req) { + match self.cache.get_mut(req) { Some(cache) => Ok(cache.setup(last_versions).await?), None => Err(ToolError::UnknownTool(self.runtime.to_string()).into()), } } pub async fn teardown(&mut self, req: &RuntimeReq) -> miette::Result<()> { - if let Some(mut tool) = self.cache.remove(&req) { + if let Some(mut tool) = self.cache.remove(req) { tool.teardown().await?; } diff --git a/crates/rust/platform/tests/rust_platform_test.rs b/crates/rust/platform/tests/rust_platform_test.rs index 87c0f015256..dd71854b360 100644 --- a/crates/rust/platform/tests/rust_platform_test.rs +++ b/crates/rust/platform/tests/rust_platform_test.rs @@ -1,13 +1,13 @@ use moon_action_context::ActionContext; use moon_config::{PlatformType, RustConfig}; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq, VersionSpec}; use moon_process::Command; use moon_project::Project; use moon_rust_platform::RustPlatform; use moon_task::Task; use moon_test_utils::create_sandbox; use moon_utils::string_vec; -use proto_core::{ProtoEnvironment, Version as SemVersion}; +use proto_core::{ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use std::env; use std::fs; @@ -37,7 +37,7 @@ async fn create_target_command(task: Task) -> Command { &ActionContext::default(), &Project::default(), &task, - &Runtime::Rust(Version::new_global()), + &Runtime::new(PlatformType::Rust, RuntimeReq::Global), &PathBuf::from("cwd"), ) .await @@ -110,7 +110,7 @@ mod sync_project { let mut platform = create_platform(); platform.config = RustConfig { sync_toolchain_config: false, - version: Some(SemVersion::parse("1.70.0").unwrap()), + version: Some(Version::parse("1.70.0").unwrap()), ..RustConfig::default() }; @@ -168,7 +168,7 @@ mod sync_project { let mut platform = create_platform(); platform.config = RustConfig { sync_toolchain_config: true, - version: Some(SemVersion::parse("1.70.0").unwrap()), + version: Some(Version::parse("1.70.0").unwrap()), ..RustConfig::default() }; @@ -196,7 +196,7 @@ mod sync_project { let mut platform = create_platform(); platform.config = RustConfig { sync_toolchain_config: true, - version: Some(SemVersion::parse("1.70.0").unwrap()), + version: Some(Version::parse("1.70.0").unwrap()), ..RustConfig::default() }; @@ -271,7 +271,10 @@ mod target_command { &ActionContext::default(), &Project::default(), &task, - &Runtime::Rust(Version::new_override("1.60.0")), + &Runtime::new( + PlatformType::Rust, + RuntimeReq::ToolchainOverride(VersionSpec::parse("1.60.0").unwrap()), + ), &PathBuf::from("cwd"), ) .await