diff --git a/Cargo.lock b/Cargo.lock index e2640c34d29..b05506058e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3612,7 +3612,6 @@ dependencies = [ "moon_project", "moon_task", "moon_tool", - "proto_core", "rustc-hash", "serde", ] 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/Cargo.toml b/crates/core/action/Cargo.toml index 5b1fa5f8671..7d8a6a0046b 100644 --- a/crates/core/action/Cargo.toml +++ b/crates/core/action/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] moon_common = { path = "../../../nextgen/common" } -moon_platform_runtime = { path = "../platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_target = { path = "../../../nextgen/target" } moon_utils = { path = "../utils" } miette = { workspace = true } diff --git a/crates/core/action/src/node.rs b/crates/core/action/src/node.rs index 01b6184dfb2..f79e2a63f54 100644 --- a/crates/core/action/src/node.rs +++ b/crates/core/action/src/node.rs @@ -35,37 +35,36 @@ pub enum ActionNode { impl ActionNode { pub fn label(&self) -> String { match self { - ActionNode::InstallDeps(platform) => { - let version = platform.version(); - - if version.is_latest() { - format!("Install{platform}Deps") + ActionNode::InstallDeps(runtime) => { + if runtime.requirement.is_global() { + format!("Install{}Deps", runtime) } else { - format!("Install{platform}Deps({version})") + format!("Install{}Deps({})", runtime, runtime.requirement) } } - ActionNode::InstallProjectDeps(platform, id) => { - let version = platform.version(); - - if version.is_latest() { - format!("Install{platform}DepsInProject({id})") + ActionNode::InstallProjectDeps(runtime, id) => { + if runtime.requirement.is_global() { + format!("Install{}DepsInProject({id})", runtime) } else { - format!("Install{platform}DepsInProject({version}, {id})") + format!( + "Install{}DepsInProject({}, {id})", + runtime, runtime.requirement + ) } } ActionNode::RunTarget(_, id) => format!("RunTarget({id})"), ActionNode::RunInteractiveTarget(_, id) => format!("RunInteractiveTarget({id})"), ActionNode::RunPersistentTarget(_, id) => format!("RunPersistentTarget({id})"), - ActionNode::SetupTool(platform) => { - let version = platform.version(); - - if version.is_latest() { - format!("Setup{platform}Tool") + ActionNode::SetupTool(runtime) => { + if runtime.requirement.is_global() { + format!("Setup{}Tool", runtime) } else { - format!("Setup{platform}Tool({version})") + format!("Setup{}Tool({})", runtime, runtime.requirement) } } - ActionNode::SyncProject(platform, id) => format!("Sync{platform}Project({id})"), + ActionNode::SyncProject(runtime, id) => { + format!("Sync{}Project({id})", runtime) + } ActionNode::SyncWorkspace => "SyncWorkspace".into(), } } diff --git a/crates/core/dep-graph/src/dep_builder.rs b/crates/core/dep-graph/src/dep_builder.rs index dde14612ae9..8ff6e77fa58 100644 --- a/crates/core/dep-graph/src/dep_builder.rs +++ b/crates/core/dep-graph/src/dep_builder.rs @@ -89,8 +89,8 @@ impl<'ws> DepGraphBuilder<'ws> { return pair.clone(); } - let mut project_runtime = Runtime::System; - let mut workspace_runtime = Runtime::System; + let mut project_runtime = Runtime::system(); + let mut workspace_runtime = Runtime::system(); if let Some(platform) = PlatformManager::read().find(|p| match task { Some(task) => p.matches(&task.platform, None), diff --git a/crates/core/emitter/Cargo.toml b/crates/core/emitter/Cargo.toml index 91bac32de62..d2de0a23737 100644 --- a/crates/core/emitter/Cargo.toml +++ b/crates/core/emitter/Cargo.toml @@ -14,7 +14,7 @@ harness = false [dependencies] moon_action = { path = "../action" } moon_action_context = { path = "../action-context" } -moon_platform_runtime = { path = "../platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_project = { path = "../../../nextgen/project" } moon_target = { path = "../../../nextgen/target" } moon_task = { path = "../../../nextgen/task" } diff --git a/crates/core/platform-runtime/src/lib.rs b/crates/core/platform-runtime/src/lib.rs deleted file mode 100644 index 04e5dfa5a8c..00000000000 --- a/crates/core/platform-runtime/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod runtime; -mod version; - -pub use runtime::*; -pub use version::*; diff --git a/crates/core/platform-runtime/src/runtime.rs b/crates/core/platform-runtime/src/runtime.rs deleted file mode 100644 index d3e38140f1c..00000000000 --- a/crates/core/platform-runtime/src/runtime.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::version::Version; -use moon_config::PlatformType; -use serde::Serialize; -use std::fmt::{self, Debug}; - -#[derive(Clone, Debug, Eq, PartialEq, Serialize)] -#[serde(tag = "platform", content = "version")] -pub enum Runtime { - Deno(Version), - Node(Version), - Rust(Version), - System, -} - -impl Runtime { - pub fn label(&self) -> String { - match self { - Runtime::Deno(version) => format!("Deno {version}"), - Runtime::Node(version) => format!("Node.js {version}"), - Runtime::Rust(version) => format!("Rust {version}"), - Runtime::System => "system".into(), - } - } - - pub fn version(&self) -> Version { - match self { - Runtime::Deno(version) | Runtime::Node(version) | Runtime::Rust(version) => { - version.to_owned() - } - Runtime::System => Version::new("latest"), - } - } -} - -impl fmt::Display for Runtime { - // Primarily used in action graph node labels - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Runtime::Deno(_) => write!(f, "Deno"), - Runtime::Node(_) => write!(f, "Node"), - Runtime::Rust(_) => write!(f, "Rust"), - Runtime::System => write!(f, "System"), - } - } -} - -impl From<&Runtime> for PlatformType { - fn from(value: &Runtime) -> Self { - match value { - Runtime::Deno(_) => PlatformType::Deno, - Runtime::Node(_) => PlatformType::Node, - Runtime::Rust(_) => PlatformType::Rust, - Runtime::System => PlatformType::System, - } - } -} diff --git a/crates/core/platform-runtime/src/version.rs b/crates/core/platform-runtime/src/version.rs deleted file mode 100644 index 9cb47a663bd..00000000000 --- a/crates/core/platform-runtime/src/version.rs +++ /dev/null @@ -1,76 +0,0 @@ -use crate::runtime::Runtime; -use serde::Serialize; -use std::fmt::{self, Debug}; - -#[derive(Clone, Debug, Eq, PartialEq, Serialize)] -pub struct Version { - pub number: String, - - // Use version available on PATH - pub path_executable: bool, - - // Is overriding the workspace version in a project - pub project_override: bool, -} - -impl Version { - pub fn new>(version: V) -> Self { - Version { - number: version.as_ref().to_owned(), - path_executable: false, - project_override: false, - } - } - - pub fn new_global() -> Self { - Version { - number: "global".into(), - path_executable: true, - project_override: false, - } - } - - pub fn new_override>(version: V) -> Self { - Version { - number: version.as_ref().to_owned(), - path_executable: false, - project_override: true, - } - } - - pub fn is_global(&self) -> bool { - self.number == "global" && self.path_executable - } - - pub fn is_latest(&self) -> bool { - self.number == "latest" - } - - pub fn is_override(&self) -> bool { - self.project_override - } -} - -impl fmt::Display for Version { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.number) - } -} - -impl From<&str> for Version { - fn from(value: &str) -> Self { - Version::new(value) - } -} - -impl From<&Runtime> for Version { - fn from(value: &Runtime) -> Self { - value.version() - } -} - -impl AsRef for Version { - fn as_ref(&self) -> &Version { - self - } -} diff --git a/crates/core/platform/Cargo.toml b/crates/core/platform/Cargo.toml index 054fea3ec28..8703ed1207c 100644 --- a/crates/core/platform/Cargo.toml +++ b/crates/core/platform/Cargo.toml @@ -9,13 +9,12 @@ moon_action_context = { path = "../action-context" } moon_common = { path = "../../../nextgen/common" } moon_config = { path = "../../../nextgen/config" } moon_hash = { path = "../../../nextgen/hash" } -moon_platform_runtime = { path = "../platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_project = { path = "../../../nextgen/project" } moon_task = { path = "../../../nextgen/task" } moon_tool = { path = "../tool" } async-trait = { workspace = true } miette = { workspace = true } -proto_core = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true } diff --git a/crates/core/platform/src/platform.rs b/crates/core/platform/src/platform.rs index 8b90bf5702f..ac9cd2b98e0 100644 --- a/crates/core/platform/src/platform.rs +++ b/crates/core/platform/src/platform.rs @@ -3,15 +3,14 @@ use moon_action_context::ActionContext; use moon_common::Id; use moon_config::{ DependencyConfig, HasherConfig, PlatformType, ProjectConfig, ProjectsAliasesMap, - ProjectsSourcesMap, TasksConfigsMap, + ProjectsSourcesMap, TasksConfigsMap, Version, }; use moon_hash::ContentHasher; -use moon_platform_runtime::{Runtime, Version}; +use moon_platform_runtime::{Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; use moon_tool::Tool; -use proto_core::Version as SemVersion; use rustc_hash::FxHashMap; use std::collections::BTreeMap; use std::path::Path; @@ -76,7 +75,7 @@ pub trait Platform: Send + Sync { /// Return a tool instance from the internal toolchain for the provided version. /// If the version does not exist in the toolchain, return an error. - fn get_tool_for_version(&self, version: Version) -> miette::Result>; + fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result>; /// Return the filename of the lockfile and manifest (in this order) /// for the language's dependency manager, if applicable. @@ -104,7 +103,7 @@ pub trait Platform: Send + Sync { &mut self, context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { Ok(0) } diff --git a/crates/core/runner/Cargo.toml b/crates/core/runner/Cargo.toml index 53644eab41e..80f4bd82792 100644 --- a/crates/core/runner/Cargo.toml +++ b/crates/core/runner/Cargo.toml @@ -14,7 +14,7 @@ moon_emitter = { path = "../emitter" } moon_hash = { path = "../../../nextgen/hash" } moon_logger = { path = "../logger" } moon_platform = { path = "../platform" } -moon_platform_runtime = { path = "../platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_project = { path = "../../../nextgen/project" } moon_target = { path = "../../../nextgen/target" } diff --git a/crates/core/tool/Cargo.toml b/crates/core/tool/Cargo.toml index dd9a525be5a..b901c2f0298 100644 --- a/crates/core/tool/Cargo.toml +++ b/crates/core/tool/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] moon_lang = { path = "../lang" } -moon_platform_runtime = { path = "../platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } async-trait = { workspace = true } miette = { workspace = true } diff --git a/crates/core/tool/src/manager.rs b/crates/core/tool/src/manager.rs index 9179e28a165..e4b438cc642 100644 --- a/crates/core/tool/src/manager.rs +++ b/crates/core/tool/src/manager.rs @@ -1,12 +1,12 @@ use crate::errors::ToolError; use crate::tool::Tool; -use moon_platform_runtime::{Runtime, Version}; -use proto_core::Version as SemVersion; +use moon_platform_runtime::{Runtime, RuntimeReq}; +use proto_core::Version; use rustc_hash::FxHashMap; pub struct ToolManager { - cache: FxHashMap, - default_version: Version, + cache: FxHashMap, + default_req: RuntimeReq, runtime: Runtime, } @@ -14,54 +14,52 @@ impl ToolManager { pub fn new(runtime: Runtime) -> Self { ToolManager { cache: FxHashMap::default(), - default_version: runtime.version(), + default_req: runtime.requirement.clone(), runtime, } } pub fn get(&self) -> miette::Result<&T> { - self.get_for_version(&self.default_version) + self.get_for_version(&self.default_req) } - pub fn get_for_version>(&self, version: V) -> miette::Result<&T> { - let version = version.as_ref(); + pub fn get_for_version>(&self, req: V) -> miette::Result<&T> { + let req = req.as_ref(); - if !self.has(version) { - return Err( - ToolError::UnknownTool(format!("{} {}", self.runtime, version.number)).into(), - ); + if !self.has(req) { + return Err(ToolError::UnknownTool(format!("{} {}", self.runtime, req)).into()); } - Ok(self.cache.get(&version.number).unwrap()) + Ok(self.cache.get(req).unwrap()) } - pub fn has(&self, version: &Version) -> bool { - self.cache.contains_key(&version.number) + pub fn has(&self, req: &RuntimeReq) -> bool { + self.cache.contains_key(req) } - pub fn register(&mut self, version: &Version, tool: T) { + pub fn register(&mut self, req: &RuntimeReq, tool: T) { // Nothing exists in the cache yet, so this tool must be the top-level // workspace tool. If so, update the default version within the platform. - if self.default_version.is_global() && !version.is_global() { - self.default_version = version.to_owned(); + if self.default_req.is_global() && !req.is_global() { + self.default_req = req.to_owned(); } - self.cache.insert(version.number.to_owned(), tool); + self.cache.insert(req.to_owned(), tool); } pub async fn setup( &mut self, - version: &Version, - last_versions: &mut FxHashMap, + req: &RuntimeReq, + last_versions: &mut FxHashMap, ) -> miette::Result { - match self.cache.get_mut(&version.number) { + 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, version: &Version) -> miette::Result<()> { - if let Some(mut tool) = self.cache.remove(&version.number) { + pub async fn teardown(&mut self, req: &RuntimeReq) -> miette::Result<()> { + if let Some(mut tool) = self.cache.remove(req) { tool.teardown().await?; } diff --git a/crates/deno/platform/src/platform.rs b/crates/deno/platform/src/platform.rs index 1f62c3ed1a5..25e6da3703e 100644 --- a/crates/deno/platform/src/platform.rs +++ b/crates/deno/platform/src/platform.rs @@ -11,7 +11,7 @@ use moon_deno_lang::{load_lockfile_dependencies, DenoJson, DENO_DEPS}; use moon_deno_tool::DenoTool; use moon_hash::ContentHasher; use moon_logger::{debug, map_list}; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; @@ -19,7 +19,7 @@ use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{Tool, ToolManager}; use moon_typescript_platform::TypeScriptTargetHash; use moon_utils::async_trait; -use proto_core::{hash_file_contents, ProtoEnvironment, Version as SemVersion}; +use proto_core::{hash_file_contents, ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use std::sync::Arc; use std::{ @@ -51,7 +51,7 @@ impl DenoPlatform { DenoPlatform { config: config.to_owned(), proto_env, - toolchain: ToolManager::new(Runtime::Deno(Version::new_global())), + toolchain: ToolManager::new(Runtime::new(PlatformType::Deno, RuntimeReq::Global)), typescript_config: typescript_config.to_owned(), workspace_root: workspace_root.to_path_buf(), } @@ -65,7 +65,7 @@ impl Platform for DenoPlatform { } fn get_runtime_from_config(&self, _project_config: Option<&ProjectConfig>) -> Runtime { - Runtime::Deno(Version::new_global()) + Runtime::new(PlatformType::Deno, RuntimeReq::Global) } fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool { @@ -74,7 +74,7 @@ impl Platform for DenoPlatform { } if let Some(runtime) = &runtime { - return matches!(runtime, Runtime::Deno(_)); + return matches!(runtime.platform, PlatformType::Deno); } false @@ -104,8 +104,8 @@ impl Platform for DenoPlatform { Ok(Box::new(tool)) } - fn get_tool_for_version(&self, version: Version) -> miette::Result> { - let tool = self.toolchain.get_for_version(&version)?; + fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result> { + let tool = self.toolchain.get_for_version(&req)?; Ok(Box::new(tool)) } @@ -123,17 +123,15 @@ impl Platform for DenoPlatform { // None => Version::new_global(), // }; - let version = Version::new_global(); + let req = RuntimeReq::Global; let mut last_versions = FxHashMap::default(); - if !self.toolchain.has(&version) { - self.toolchain.register( - &version, - DenoTool::new(&self.proto_env, &self.config, &version)?, - ); + if !self.toolchain.has(&req) { + self.toolchain + .register(&req, DenoTool::new(&self.proto_env, &self.config, &req)?); } - self.toolchain.setup(&version, &mut last_versions).await?; + self.toolchain.setup(&req, &mut last_versions).await?; Ok(()) } @@ -150,18 +148,16 @@ impl Platform for DenoPlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { - let version = runtime.version(); + let req = &runtime.requirement; - if !self.toolchain.has(&version) { - self.toolchain.register( - &version, - DenoTool::new(&self.proto_env, &self.config, &version)?, - ); + if !self.toolchain.has(req) { + self.toolchain + .register(req, DenoTool::new(&self.proto_env, &self.config, req)?); } - Ok(self.toolchain.setup(&version, last_versions).await?) + Ok(self.toolchain.setup(req, last_versions).await?) } async fn install_deps( @@ -174,7 +170,7 @@ impl Platform for DenoPlatform { return Ok(()); } - let tool = self.toolchain.get_for_version(runtime.version())?; + let tool = self.toolchain.get_for_version(&runtime.requirement)?; debug!(target: LOG_TARGET, "Installing dependencies"); diff --git a/crates/deno/tool/Cargo.toml b/crates/deno/tool/Cargo.toml index 4b0dfe49815..ab95af131ef 100644 --- a/crates/deno/tool/Cargo.toml +++ b/crates/deno/tool/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] moon_config = { path = "../../../nextgen/config" } -moon_platform_runtime = { path = "../../core/platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_tool = { path = "../../core/tool" } miette = { workspace = true } proto_core = { workspace = true } diff --git a/crates/deno/tool/src/deno_tool.rs b/crates/deno/tool/src/deno_tool.rs index d1c8e96e494..a014cd8948f 100644 --- a/crates/deno/tool/src/deno_tool.rs +++ b/crates/deno/tool/src/deno_tool.rs @@ -1,5 +1,5 @@ use moon_config::DenoConfig; -use moon_platform_runtime::Version; +use moon_platform_runtime::RuntimeReq; use moon_tool::{async_trait, Tool}; use proto_core::ProtoEnvironment; use std::path::PathBuf; @@ -15,14 +15,14 @@ impl DenoTool { pub fn new( _proto: &ProtoEnvironment, config: &DenoConfig, - version: &Version, + req: &RuntimeReq, ) -> miette::Result { let mut deno = DenoTool { config: config.to_owned(), global: true, }; - if version.is_global() { + if req.is_global() { deno.global = true; // node.config.version = None; } else { diff --git a/crates/node/platform/src/platform.rs b/crates/node/platform/src/platform.rs index 2c389c8ea0f..0dad61a2a32 100644 --- a/crates/node/platform/src/platform.rs +++ b/crates/node/platform/src/platform.rs @@ -12,14 +12,14 @@ use moon_logger::{debug, warn}; use moon_node_lang::node::get_package_manager_workspaces; use moon_node_lang::{PackageJson, NPM}; use moon_node_tool::NodeTool; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq, VersionSpec}; use moon_process::Command; use moon_project::Project; use moon_task::Task; use moon_tool::{Tool, ToolManager}; use moon_typescript_platform::TypeScriptTargetHash; use moon_utils::async_trait; -use proto_core::{ProtoEnvironment, Version as SemVersion}; +use proto_core::{ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use starbase_styles::color; use starbase_utils::glob::GlobSet; @@ -54,7 +54,7 @@ impl NodePlatform { config: config.to_owned(), package_names: FxHashMap::default(), proto_env, - toolchain: ToolManager::new(Runtime::Node(Version::new_global())), + toolchain: ToolManager::new(Runtime::new(PlatformType::Node, RuntimeReq::Global)), typescript_config: typescript_config.to_owned(), workspace_root: workspace_root.to_path_buf(), } @@ -71,17 +71,23 @@ impl Platform for NodePlatform { if let Some(config) = &project_config { if let Some(node_config) = &config.toolchain.node { if let Some(version) = &node_config.version { - return Runtime::Node(Version::new_override(version.to_string())); + return Runtime::new_override( + PlatformType::Node, + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), + ); } } } if let Some(version) = &self.config.version { - return Runtime::Node(Version::new(version.to_string())); + return Runtime::new( + PlatformType::Node, + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), + ); } // Global - Runtime::Node(Version::new_global()) + Runtime::new(PlatformType::Node, RuntimeReq::Global) } fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool { @@ -90,7 +96,7 @@ impl Platform for NodePlatform { } if let Some(runtime) = &runtime { - return matches!(runtime, Runtime::Node(_)); + return matches!(runtime.platform, PlatformType::Node); } false @@ -251,8 +257,8 @@ impl Platform for NodePlatform { Ok(Box::new(tool)) } - fn get_tool_for_version(&self, version: Version) -> miette::Result> { - let tool = self.toolchain.get_for_version(&version)?; + fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result> { + let tool = self.toolchain.get_for_version(&req)?; Ok(Box::new(tool)) } @@ -268,21 +274,21 @@ impl Platform for NodePlatform { } async fn setup_toolchain(&mut self) -> miette::Result<()> { - let version = match &self.config.version { - Some(v) => Version::new(v.to_string()), - None => Version::new_global(), + let req = match &self.config.version { + Some(v) => RuntimeReq::Toolchain(VersionSpec::Version(v.to_owned())), + None => RuntimeReq::Global, }; let mut last_versions = FxHashMap::default(); - if !self.toolchain.has(&version) { + if !self.toolchain.has(&req) { self.toolchain.register( - &version, - NodeTool::new(&self.proto_env, &self.config, &version).await?, + &req, + NodeTool::new(&self.proto_env, &self.config, &req).await?, ); } - self.toolchain.setup(&version, &mut last_versions).await?; + self.toolchain.setup(&req, &mut last_versions).await?; Ok(()) } @@ -299,24 +305,20 @@ impl Platform for NodePlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { - let version = runtime.version(); + let req = &runtime.requirement; - if !self.toolchain.has(&version) { + if !self.toolchain.has(req) { self.toolchain.register( - &version, - NodeTool::new(&self.proto_env, &self.config, &version).await?, + req, + NodeTool::new(&self.proto_env, &self.config, req).await?, ); } - let installed = self.toolchain.setup(&version, last_versions).await?; + let installed = self.toolchain.setup(req, last_versions).await?; - actions::setup_tool( - self.toolchain.get_for_version(runtime.version())?, - &self.workspace_root, - ) - .await?; + actions::setup_tool(self.toolchain.get_for_version(req)?, &self.workspace_root).await?; Ok(installed) } @@ -328,7 +330,7 @@ impl Platform for NodePlatform { working_dir: &Path, ) -> miette::Result<()> { actions::install_deps( - self.toolchain.get_for_version(runtime.version())?, + self.toolchain.get_for_version(&runtime.requirement)?, working_dir, ) .await?; @@ -390,7 +392,7 @@ impl Platform for NodePlatform { hasher_config: &HasherConfig, ) -> miette::Result<()> { let node_hash = actions::create_target_hasher( - self.toolchain.get_for_version(runtime.version()).ok(), + self.toolchain.get_for_version(&runtime.requirement).ok(), project, &self.workspace_root, hasher_config, @@ -422,7 +424,7 @@ impl Platform for NodePlatform { ) -> miette::Result { let command = if self.is_toolchain_enabled()? { actions::create_target_command( - self.toolchain.get_for_version(runtime.version())?, + self.toolchain.get_for_version(&runtime.requirement)?, context, project, task, diff --git a/crates/node/tool/Cargo.toml b/crates/node/tool/Cargo.toml index 6448f180ca3..3553e06c70b 100644 --- a/crates/node/tool/Cargo.toml +++ b/crates/node/tool/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] moon_config = { path = "../../../nextgen/config" } moon_logger = { path = "../../core/logger" } -moon_platform_runtime = { path = "../../core/platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_node_lang = { path = "../lang" } moon_terminal = { path = "../../core/terminal" } diff --git a/crates/node/tool/src/node_tool.rs b/crates/node/tool/src/node_tool.rs index 974479efe33..cb62c451b5f 100644 --- a/crates/node/tool/src/node_tool.rs +++ b/crates/node/tool/src/node_tool.rs @@ -4,15 +4,13 @@ use crate::yarn_tool::YarnTool; use moon_config::{NodeConfig, NodePackageManager}; use moon_logger::debug; use moon_node_lang::node; -use moon_platform_runtime::Version; +use moon_platform_runtime::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{ async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool, ToolError, }; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use std::path::{Path, PathBuf}; @@ -34,7 +32,7 @@ impl NodeTool { pub async fn new( proto: &ProtoEnvironment, config: &NodeConfig, - version: &Version, + req: &RuntimeReq, ) -> miette::Result { let mut node = NodeTool { global: false, @@ -46,11 +44,11 @@ impl NodeTool { yarn: None, }; - if version.is_global() { + if req.is_global() { node.global = true; node.config.version = None; } else { - node.config.version = SemVersion::parse(&version.number).ok(); + node.config.version = req.to_version(); }; match config.package_manager { @@ -160,7 +158,7 @@ impl Tool for NodeTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut installed = 0; diff --git a/crates/node/tool/src/npm_tool.rs b/crates/node/tool/src/npm_tool.rs index faf90430584..173749f2c75 100644 --- a/crates/node/tool/src/npm_tool.rs +++ b/crates/node/tool/src/npm_tool.rs @@ -6,9 +6,7 @@ use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool}; use moon_utils::is_ci; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use starbase_utils::fs; use std::env; @@ -52,7 +50,7 @@ impl Tool for NpmTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut count = 0; let version = self.config.version.clone(); diff --git a/crates/node/tool/src/pnpm_tool.rs b/crates/node/tool/src/pnpm_tool.rs index e5d404fff0d..c8db76f009a 100644 --- a/crates/node/tool/src/pnpm_tool.rs +++ b/crates/node/tool/src/pnpm_tool.rs @@ -7,8 +7,7 @@ use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool}; use moon_utils::is_ci; use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, - VersionReq, + Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version, VersionReq, }; use rustc_hash::FxHashMap; use starbase_utils::fs; @@ -59,7 +58,7 @@ impl Tool for PnpmTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut count = 0; let version = self.config.version.clone(); diff --git a/crates/node/tool/src/yarn_tool.rs b/crates/node/tool/src/yarn_tool.rs index 1c661443a9b..f32779a68fe 100644 --- a/crates/node/tool/src/yarn_tool.rs +++ b/crates/node/tool/src/yarn_tool.rs @@ -8,9 +8,7 @@ use moon_tool::{ async_trait, get_path_env_var, load_tool_plugin, DependencyManager, Tool, ToolError, }; use moon_utils::{get_workspace_root, is_ci}; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use starbase_styles::color; use starbase_utils::fs; @@ -108,7 +106,7 @@ impl Tool for YarnTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut count = 0; let version = self.config.version.clone(); diff --git a/crates/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index 431af14499d..254dca6534a 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -5,11 +5,11 @@ use moon_action_context::ActionContext; use moon_common::{is_ci, Id}; use moon_config::{ BinEntry, HasherConfig, PlatformType, ProjectConfig, ProjectsAliasesMap, ProjectsSourcesMap, - RustConfig, + RustConfig, VersionSpec, }; use moon_hash::ContentHasher; use moon_logger::{debug, map_list}; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_rust_lang::{ @@ -23,7 +23,7 @@ use moon_task::Task; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{Tool, ToolError, ToolManager}; use moon_utils::async_trait; -use proto_core::{ProtoEnvironment, Version as SemVersion}; +use proto_core::{ProtoEnvironment, Version}; use rustc_hash::FxHashMap; use starbase_styles::color; use starbase_utils::{fs, glob::GlobSet}; @@ -55,7 +55,7 @@ impl RustPlatform { RustPlatform { config: config.to_owned(), proto_env, - toolchain: ToolManager::new(Runtime::Rust(Version::new_global())), + toolchain: ToolManager::new(Runtime::new(PlatformType::Rust, RuntimeReq::Global)), workspace_root: workspace_root.to_path_buf(), } } @@ -71,16 +71,22 @@ impl Platform for RustPlatform { if let Some(config) = &project_config { if let Some(rust_config) = &config.toolchain.rust { if let Some(version) = &rust_config.version { - return Runtime::Rust(Version::new_override(version.to_string())); + return Runtime::new_override( + PlatformType::Rust, + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), + ); } } } if let Some(version) = &self.config.version { - return Runtime::Rust(Version::new(version.to_string())); + return Runtime::new( + PlatformType::Rust, + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), + ); } - Runtime::Rust(Version::new_global()) + Runtime::new(PlatformType::Rust, RuntimeReq::Global) } fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool { @@ -89,7 +95,7 @@ impl Platform for RustPlatform { } if let Some(runtime) = &runtime { - return matches!(runtime, Runtime::Rust(_)); + return matches!(runtime.platform, PlatformType::Rust); } false @@ -155,8 +161,8 @@ impl Platform for RustPlatform { Ok(Box::new(tool)) } - fn get_tool_for_version(&self, version: Version) -> miette::Result> { - let tool = self.toolchain.get_for_version(&version)?; + fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result> { + let tool = self.toolchain.get_for_version(&req)?; Ok(Box::new(tool)) } @@ -166,21 +172,21 @@ impl Platform for RustPlatform { } async fn setup_toolchain(&mut self) -> miette::Result<()> { - let version = match &self.config.version { - Some(v) => Version::new(v.to_string()), - None => Version::new_global(), + let req = match &self.config.version { + Some(v) => RuntimeReq::Toolchain(VersionSpec::Version(v.to_owned())), + None => RuntimeReq::Global, }; let mut last_versions = FxHashMap::default(); - if !self.toolchain.has(&version) { + if !self.toolchain.has(&req) { self.toolchain.register( - &version, - RustTool::new(&self.proto_env, &self.config, &version).await?, + &req, + RustTool::new(&self.proto_env, &self.config, &req).await?, ); } - self.toolchain.setup(&version, &mut last_versions).await?; + self.toolchain.setup(&req, &mut last_versions).await?; Ok(()) } @@ -197,18 +203,18 @@ impl Platform for RustPlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { - let version = runtime.version(); + let req = &runtime.requirement; - if !self.toolchain.has(&version) { + if !self.toolchain.has(req) { self.toolchain.register( - &version, - RustTool::new(&self.proto_env, &self.config, &version).await?, + req, + RustTool::new(&self.proto_env, &self.config, req).await?, ); } - Ok(self.toolchain.setup(&version, last_versions).await?) + Ok(self.toolchain.setup(req, last_versions).await?) } async fn install_deps( @@ -217,7 +223,7 @@ impl Platform for RustPlatform { runtime: &Runtime, working_dir: &Path, ) -> miette::Result<()> { - let tool = self.toolchain.get_for_version(runtime.version())?; + let tool = self.toolchain.get_for_version(&runtime.requirement)?; if find_cargo_lock(working_dir).is_none() { print_checkpoint("cargo generate-lockfile", Checkpoint::Setup); @@ -466,10 +472,8 @@ impl Platform for RustPlatform { | "rustdoc" | "rustfmt" | "rustup" => {} // Handle toolchains for cargo commands "cargo" => { - let version = runtime.version(); - - if version.is_override() { - args.push(format!("+{}", version.number)); + if runtime.overridden { + args.push(format!("+{}", runtime.requirement)); } } // Binary may be installed to ~/.cargo/bin diff --git a/crates/rust/platform/tests/rust_platform_test.rs b/crates/rust/platform/tests/rust_platform_test.rs index 87c0f015256..67a5bfb131d 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_override( + PlatformType::Rust, + RuntimeReq::Toolchain(VersionSpec::parse("1.60.0").unwrap()), + ), &PathBuf::from("cwd"), ) .await diff --git a/crates/rust/tool/Cargo.toml b/crates/rust/tool/Cargo.toml index 26cbee46cfd..88942878d9d 100644 --- a/crates/rust/tool/Cargo.toml +++ b/crates/rust/tool/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] moon_config = { path = "../../../nextgen/config" } moon_logger = { path = "../../core/logger" } -moon_platform_runtime = { path = "../../core/platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_terminal = { path = "../../core/terminal" } moon_tool = { path = "../../core/tool" } diff --git a/crates/rust/tool/src/rust_tool.rs b/crates/rust/tool/src/rust_tool.rs index 5103c6c207a..ef6a683e2ce 100644 --- a/crates/rust/tool/src/rust_tool.rs +++ b/crates/rust/tool/src/rust_tool.rs @@ -1,12 +1,10 @@ use moon_config::RustConfig; use moon_logger::debug; -use moon_platform_runtime::Version; +use moon_platform_runtime::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, load_tool_plugin, Tool}; -use proto_core::{ - Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version as SemVersion, -}; +use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec, Version}; use rustc_hash::FxHashMap; use std::{ ffi::OsStr, @@ -25,7 +23,7 @@ impl RustTool { pub async fn new( proto: &ProtoEnvironment, config: &RustConfig, - version: &Version, + req: &RuntimeReq, ) -> miette::Result { let mut rust = RustTool { config: config.to_owned(), @@ -34,11 +32,11 @@ impl RustTool { .await?, }; - if version.is_global() { + if req.is_global() { rust.global = true; rust.config.version = None; } else { - rust.config.version = SemVersion::parse(&version.number).ok(); + rust.config.version = req.to_version(); }; Ok(rust) @@ -72,7 +70,7 @@ impl Tool for RustTool { async fn setup( &mut self, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let mut installed = 0; diff --git a/crates/system/platform/src/platform.rs b/crates/system/platform/src/platform.rs index a1a54082588..32ab5f91d35 100644 --- a/crates/system/platform/src/platform.rs +++ b/crates/system/platform/src/platform.rs @@ -3,7 +3,7 @@ use crate::tool::SystemToolStub; use moon_action_context::ActionContext; use moon_config::{HasherConfig, PlatformType, ProjectConfig}; use moon_hash::ContentHasher; -use moon_platform::{Platform, Runtime, Version}; +use moon_platform::{Platform, Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; @@ -23,7 +23,7 @@ impl Platform for SystemPlatform { } fn get_runtime_from_config(&self, _project_config: Option<&ProjectConfig>) -> Runtime { - Runtime::System + Runtime::system() } fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool { @@ -32,7 +32,7 @@ impl Platform for SystemPlatform { } if let Some(runtime) = &runtime { - return matches!(runtime, Runtime::System); + return matches!(runtime.platform, PlatformType::System); } false @@ -48,7 +48,7 @@ impl Platform for SystemPlatform { Ok(Box::new(&self.tool)) } - fn get_tool_for_version(&self, _version: Version) -> miette::Result> { + fn get_tool_for_version(&self, _req: RuntimeReq) -> miette::Result> { Ok(Box::new(&self.tool)) } diff --git a/nextgen/config/src/lib.rs b/nextgen/config/src/lib.rs index 2da25712a80..8867e71dfe9 100644 --- a/nextgen/config/src/lib.rs +++ b/nextgen/config/src/lib.rs @@ -19,7 +19,7 @@ pub use language_platform::*; pub use portable_path::*; pub use project::*; pub use project_config::*; -pub use proto_core::{ToolsConfig, Version, VersionReq}; +pub use proto_core::{ToolsConfig, UnresolvedVersionSpec, Version, VersionReq, VersionSpec}; pub use schematic::{Config, ConfigEnum, ConfigError, PartialConfig}; pub use shapes::*; pub use template::*; diff --git a/crates/core/platform-runtime/Cargo.toml b/nextgen/platform-runtime/Cargo.toml similarity index 72% rename from crates/core/platform-runtime/Cargo.toml rename to nextgen/platform-runtime/Cargo.toml index 46fb02e27d1..40859f911c4 100644 --- a/crates/core/platform-runtime/Cargo.toml +++ b/nextgen/platform-runtime/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" publish = false [dependencies] -moon_config = { path = "../../../nextgen/config" } +moon_config = { path = "../config" } serde = { workspace = true } diff --git a/nextgen/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs new file mode 100644 index 00000000000..36b3cca46aa --- /dev/null +++ b/nextgen/platform-runtime/src/lib.rs @@ -0,0 +1,97 @@ +pub use moon_config::{PlatformType, Version, VersionSpec}; +use serde::Serialize; +use std::fmt; + +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)] +pub enum RuntimeReq { + // Use tool available on PATH + Global, + // Install tool into toolchain + Toolchain(VersionSpec), +} + +impl RuntimeReq { + pub fn is_global(&self) -> bool { + matches!(self, Self::Global) + } + + pub fn to_version(&self) -> Option { + match self { + Self::Toolchain(VersionSpec::Version(version)) => Some(version.to_owned()), + _ => None, + } + } +} + +impl fmt::Display for RuntimeReq { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::Global => write!(f, "global"), + Self::Toolchain(spec) => write!(f, "{}", spec), + } + } +} + +impl AsRef for RuntimeReq { + fn as_ref(&self) -> &RuntimeReq { + self + } +} + +impl From<&Runtime> for RuntimeReq { + fn from(value: &Runtime) -> Self { + value.requirement.clone() + } +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize)] +pub struct Runtime { + pub platform: PlatformType, + pub requirement: RuntimeReq, + pub overridden: bool, +} + +impl Runtime { + pub fn new(platform: PlatformType, requirement: RuntimeReq) -> Self { + Self { + platform, + requirement, + overridden: false, + } + } + + pub fn new_override(platform: PlatformType, requirement: RuntimeReq) -> Self { + let mut runtime = Self::new(platform, requirement); + runtime.overridden = true; + runtime + } + + pub fn system() -> Self { + Self::new(PlatformType::System, RuntimeReq::Global) + } + + pub fn label(&self) -> String { + match self.platform { + PlatformType::System => "system".into(), + platform => format!("{:?} {}", platform, self.requirement), + } + } +} + +impl fmt::Display for Runtime { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self.platform) + } +} + +impl AsRef for Runtime { + fn as_ref(&self) -> &Runtime { + self + } +} + +impl From<&Runtime> for PlatformType { + fn from(value: &Runtime) -> Self { + value.platform + } +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0134a5026fa..afe2102addd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,4 @@ # The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy. # https://rust-lang.github.io/rustup/concepts/profiles.html profile = "default" -channel = "1.72.0" +channel = "1.72.1"