From 0063209488b3fd7eaec01198dd8994afdfa8325a Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 19 Sep 2023 21:35:59 -0700 Subject: [PATCH 1/9] Add new crate. --- Cargo.lock | 8 +++ nextgen/config/src/lib.rs | 2 +- nextgen/platform-runtime/Cargo.toml | 9 ++++ nextgen/platform-runtime/src/lib.rs | 78 +++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 nextgen/platform-runtime/Cargo.toml create mode 100644 nextgen/platform-runtime/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e2640c34d29..6c54d4a279c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3643,6 +3643,14 @@ dependencies = [ "serde", ] +[[package]] +name = "moon_platform_runtime2" +version = "0.1.0" +dependencies = [ + "moon_config", + "serde", +] + [[package]] name = "moon_process" version = "0.1.0" 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/nextgen/platform-runtime/Cargo.toml b/nextgen/platform-runtime/Cargo.toml new file mode 100644 index 00000000000..6fcf6406332 --- /dev/null +++ b/nextgen/platform-runtime/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "moon_platform_runtime2" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +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..e2d87c5c438 --- /dev/null +++ b/nextgen/platform-runtime/src/lib.rs @@ -0,0 +1,78 @@ +use moon_config::{PlatformType, UnresolvedVersionSpec}; +use serde::Serialize; +use std::fmt; + +#[derive(Clone, Debug, Serialize)] +pub enum RuntimeRequirement { + // Use tool available on PATH + Global, + // Install tool into toolchain + Toolchain(UnresolvedVersionSpec), + // Use toolchain but override the version + ToolchainOverride(UnresolvedVersionSpec), +} + +impl RuntimeRequirement { + pub fn is_latest(&self) -> bool { + match self { + Self::Toolchain(UnresolvedVersionSpec::Alias(alias)) => alias == "latest", + Self::ToolchainOverride(UnresolvedVersionSpec::Alias(alias)) => alias == "latest", + _ => false, + } + } +} + +impl fmt::Display for RuntimeRequirement { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::Global => write!(f, "global"), + Self::Toolchain(spec) => write!(f, "{}", spec), + Self::ToolchainOverride(spec) => write!(f, "{}", spec), + } + } +} + +impl AsRef for RuntimeRequirement { + fn as_ref(&self) -> &RuntimeRequirement { + self + } +} + +impl From<&Runtime> for RuntimeRequirement { + fn from(value: &Runtime) -> Self { + value.requirement.clone() + } +} + +#[derive(Clone, Debug, Serialize)] +pub struct Runtime { + pub platform: PlatformType, + pub requirement: RuntimeRequirement, +} + +impl Runtime { + 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 + } +} From 1ce9f6e2e2a29aec943193594aa1e295c152ac44 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 19 Sep 2023 21:43:32 -0700 Subject: [PATCH 2/9] Update tool. --- Cargo.lock | 2 +- crates/core/tool/Cargo.toml | 2 +- crates/core/tool/src/errors.rs | 2 +- crates/core/tool/src/manager.rs | 42 ++++++++++++++--------------- nextgen/platform-runtime/src/lib.rs | 32 ++++++++++++---------- 5 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c54d4a279c..1d93ff20e54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4000,7 +4000,7 @@ dependencies = [ "async-trait", "miette", "moon_lang", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_process", "proto_core", "rustc-hash", diff --git a/crates/core/tool/Cargo.toml b/crates/core/tool/Cargo.toml index dd9a525be5a..26c5bbcecb6 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_runtime2 = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } async-trait = { workspace = true } miette = { workspace = true } diff --git a/crates/core/tool/src/errors.rs b/crates/core/tool/src/errors.rs index e1b88ebaf82..71834129e71 100644 --- a/crates/core/tool/src/errors.rs +++ b/crates/core/tool/src/errors.rs @@ -1,5 +1,5 @@ use miette::Diagnostic; -use moon_platform_runtime::Runtime; +use moon_platform_runtime2::Runtime; use starbase_styles::{Style, Stylize}; use thiserror::Error; diff --git a/crates/core/tool/src/manager.rs b/crates/core/tool/src/manager.rs index 9179e28a165..763efb7c200 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 moon_platform_runtime2::{Runtime, RuntimeReq}; use proto_core::Version as SemVersion; 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, + 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/nextgen/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs index e2d87c5c438..b836f12a886 100644 --- a/nextgen/platform-runtime/src/lib.rs +++ b/nextgen/platform-runtime/src/lib.rs @@ -1,28 +1,32 @@ -use moon_config::{PlatformType, UnresolvedVersionSpec}; +use moon_config::{PlatformType, VersionSpec}; use serde::Serialize; use std::fmt; -#[derive(Clone, Debug, Serialize)] -pub enum RuntimeRequirement { +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)] +pub enum RuntimeReq { // Use tool available on PATH Global, // Install tool into toolchain - Toolchain(UnresolvedVersionSpec), + Toolchain(VersionSpec), // Use toolchain but override the version - ToolchainOverride(UnresolvedVersionSpec), + ToolchainOverride(VersionSpec), } -impl RuntimeRequirement { +impl RuntimeReq { + pub fn is_global(&self) -> bool { + matches!(self, Self::Global) + } + pub fn is_latest(&self) -> bool { match self { - Self::Toolchain(UnresolvedVersionSpec::Alias(alias)) => alias == "latest", - Self::ToolchainOverride(UnresolvedVersionSpec::Alias(alias)) => alias == "latest", + Self::Toolchain(VersionSpec::Alias(alias)) => alias == "latest", + Self::ToolchainOverride(VersionSpec::Alias(alias)) => alias == "latest", _ => false, } } } -impl fmt::Display for RuntimeRequirement { +impl fmt::Display for RuntimeReq { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Self::Global => write!(f, "global"), @@ -32,22 +36,22 @@ impl fmt::Display for RuntimeRequirement { } } -impl AsRef for RuntimeRequirement { - fn as_ref(&self) -> &RuntimeRequirement { +impl AsRef for RuntimeReq { + fn as_ref(&self) -> &RuntimeReq { self } } -impl From<&Runtime> for RuntimeRequirement { +impl From<&Runtime> for RuntimeReq { fn from(value: &Runtime) -> Self { value.requirement.clone() } } -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize)] pub struct Runtime { pub platform: PlatformType, - pub requirement: RuntimeRequirement, + pub requirement: RuntimeReq, } impl Runtime { From 4fb3801eabd32378521c6fdb63c5d218cd5fcf2c Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 19 Sep 2023 21:48:53 -0700 Subject: [PATCH 3/9] Update actions. --- Cargo.lock | 5 ++-- crates/core/action/Cargo.toml | 2 +- crates/core/action/src/node.rs | 39 ++++++++++++++-------------- crates/core/platform/Cargo.toml | 3 +-- crates/core/platform/src/lib.rs | 2 +- crates/core/platform/src/platform.rs | 9 +++---- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d93ff20e54..04e505ff4d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3014,7 +3014,7 @@ version = "0.1.0" dependencies = [ "miette", "moon_common", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_target", "moon_utils", "serde", @@ -3607,12 +3607,11 @@ dependencies = [ "moon_common", "moon_config", "moon_hash", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_process", "moon_project", "moon_task", "moon_tool", - "proto_core", "rustc-hash", "serde", ] diff --git a/crates/core/action/Cargo.toml b/crates/core/action/Cargo.toml index 5b1fa5f8671..1acf7da1538 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_runtime2 = { 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..b2332c45186 100644 --- a/crates/core/action/src/node.rs +++ b/crates/core/action/src/node.rs @@ -1,5 +1,5 @@ use moon_common::Id; -use moon_platform_runtime::Runtime; +use moon_platform_runtime2::Runtime; use moon_target::Target; use serde::Serialize; use std::hash::{Hash, Hasher}; @@ -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_latest() { + format!("Install{}Deps", runtime.platform) } else { - format!("Install{platform}Deps({version})") + format!("Install{}Deps({})", runtime.platform, 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_latest() { + format!("Install{}DepsInProject({id})", runtime.platform) } else { - format!("Install{platform}DepsInProject({version}, {id})") + format!( + "Install{}DepsInProject({}, {id})", + runtime.platform, 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_latest() { + format!("Setup{}Tool", runtime.platform) } else { - format!("Setup{platform}Tool({version})") + format!("Setup{}Tool({})", runtime.platform, runtime.requirement) } } - ActionNode::SyncProject(platform, id) => format!("Sync{platform}Project({id})"), + ActionNode::SyncProject(runtime, id) => { + format!("Sync{}Project({id})", runtime.platform) + } ActionNode::SyncWorkspace => "SyncWorkspace".into(), } } diff --git a/crates/core/platform/Cargo.toml b/crates/core/platform/Cargo.toml index 054fea3ec28..af605d9b2a6 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_runtime2 = { 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/lib.rs b/crates/core/platform/src/lib.rs index 5447a49c0a7..ad1a8aa17a9 100644 --- a/crates/core/platform/src/lib.rs +++ b/crates/core/platform/src/lib.rs @@ -5,5 +5,5 @@ mod platform; pub use manager::*; pub use moon_config::PlatformType; -pub use moon_platform_runtime::*; +pub use moon_platform_runtime2::*; pub use platform::*; diff --git a/crates/core/platform/src/platform.rs b/crates/core/platform/src/platform.rs index 8b90bf5702f..9efebaa142f 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_runtime2::{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) } From 7071c1ff24246e5656bc5f27850e6a6dc11cddf0 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:07:15 -0700 Subject: [PATCH 4/9] Update deno and rust. --- Cargo.lock | 8 ++-- crates/core/dep-graph/src/dep_builder.rs | 4 +- crates/core/emitter/Cargo.toml | 2 +- crates/core/emitter/src/event.rs | 2 +- crates/core/runner/Cargo.toml | 2 +- crates/core/runner/src/runner.rs | 2 +- crates/deno/platform/src/platform.rs | 38 +++++++++---------- crates/deno/tool/Cargo.toml | 2 +- crates/deno/tool/src/deno_tool.rs | 6 +-- crates/rust/platform/src/rust_platform.rs | 46 ++++++++++++----------- crates/rust/tool/Cargo.toml | 2 +- crates/rust/tool/src/rust_tool.rs | 8 ++-- nextgen/platform-runtime/src/lib.rs | 32 +++++++++++++--- 13 files changed, 88 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04e505ff4d6..9820132b506 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3366,7 +3366,7 @@ version = "0.1.0" dependencies = [ "miette", "moon_config", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_tool", "proto_core", "rustc-hash", @@ -3408,7 +3408,7 @@ dependencies = [ "miette", "moon_action", "moon_action_context", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_project", "moon_target", "moon_task", @@ -3804,7 +3804,7 @@ dependencies = [ "moon_hash", "moon_logger", "moon_platform", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_process", "moon_project", "moon_target", @@ -3881,7 +3881,7 @@ dependencies = [ "miette", "moon_config", "moon_logger", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_process", "moon_terminal", "moon_tool", 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..78fc6cca335 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_runtime2 = { path = "../../../nextgen/platform-runtime" } moon_project = { path = "../../../nextgen/project" } moon_target = { path = "../../../nextgen/target" } moon_task = { path = "../../../nextgen/task" } diff --git a/crates/core/emitter/src/event.rs b/crates/core/emitter/src/event.rs index 7552a2cbfc6..0481ac5ab47 100644 --- a/crates/core/emitter/src/event.rs +++ b/crates/core/emitter/src/event.rs @@ -1,6 +1,6 @@ use moon_action::{Action, ActionNode}; use moon_action_context::ActionContext; -use moon_platform_runtime::Runtime; +use moon_platform_runtime2::Runtime; use moon_project::Project; use moon_target::Target; use moon_task::Task; diff --git a/crates/core/runner/Cargo.toml b/crates/core/runner/Cargo.toml index 53644eab41e..37248787ec7 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_runtime2 = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_project = { path = "../../../nextgen/project" } moon_target = { path = "../../../nextgen/target" } diff --git a/crates/core/runner/src/runner.rs b/crates/core/runner/src/runner.rs index 04bde98059a..2a237059ac8 100644 --- a/crates/core/runner/src/runner.rs +++ b/crates/core/runner/src/runner.rs @@ -11,7 +11,7 @@ use moon_emitter::{Emitter, Event, EventFlow}; use moon_hash::ContentHasher; use moon_logger::{debug, warn}; use moon_platform::PlatformManager; -use moon_platform_runtime::Runtime; +use moon_platform_runtime2::Runtime; use moon_process::{args, output_to_error, output_to_string, Command, Output}; use moon_project::Project; use moon_target::{TargetError, TargetScope}; diff --git a/crates/deno/platform/src/platform.rs b/crates/deno/platform/src/platform.rs index 1f62c3ed1a5..8e08f64c974 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; @@ -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(()) } @@ -152,16 +150,14 @@ impl Platform for DenoPlatform { runtime: &Runtime, 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..5abd668c0d2 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_runtime2 = { 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..c1e2c35c93c 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_runtime2::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/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index 431af14499d..2c9655432c9 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::{ @@ -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( + PlatformType::Rust, + RuntimeReq::ToolchainOverride(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)) } @@ -167,8 +173,8 @@ 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(), + Some(v) => RuntimeReq::Toolchain(VersionSpec::Version(v.to_owned())), + None => RuntimeReq::Global, }; let mut last_versions = FxHashMap::default(); @@ -199,16 +205,16 @@ impl Platform for RustPlatform { runtime: &Runtime, 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.requirement.is_override() { + args.push(format!("+{}", runtime.requirement)); } } // Binary may be installed to ~/.cargo/bin diff --git a/crates/rust/tool/Cargo.toml b/crates/rust/tool/Cargo.toml index 26cbee46cfd..9b79ef54c03 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_runtime2 = { 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..c8335fcafe1 100644 --- a/crates/rust/tool/src/rust_tool.rs +++ b/crates/rust/tool/src/rust_tool.rs @@ -1,6 +1,6 @@ use moon_config::RustConfig; use moon_logger::debug; -use moon_platform_runtime::Version; +use moon_platform_runtime2::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, load_tool_plugin, Tool}; @@ -25,7 +25,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 +34,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) diff --git a/nextgen/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs index b836f12a886..7c152458675 100644 --- a/nextgen/platform-runtime/src/lib.rs +++ b/nextgen/platform-runtime/src/lib.rs @@ -1,4 +1,4 @@ -use moon_config::{PlatformType, VersionSpec}; +use moon_config::{PlatformType, Version, VersionSpec}; use serde::Serialize; use std::fmt; @@ -19,19 +19,30 @@ impl RuntimeReq { pub fn is_latest(&self) -> bool { match self { - Self::Toolchain(VersionSpec::Alias(alias)) => alias == "latest", - Self::ToolchainOverride(VersionSpec::Alias(alias)) => alias == "latest", + Self::Toolchain(VersionSpec::Alias(alias)) + | Self::ToolchainOverride(VersionSpec::Alias(alias)) => alias == "latest", _ => false, } } + + pub fn is_override(&self) -> bool { + matches!(self, Self::ToolchainOverride(_)) + } + + pub fn to_version(&self) -> Option { + match self { + Self::Toolchain(VersionSpec::Version(version)) + | Self::ToolchainOverride(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), - Self::ToolchainOverride(spec) => write!(f, "{}", spec), + Self::Toolchain(spec) | Self::ToolchainOverride(spec) => write!(f, "{}", spec), } } } @@ -55,6 +66,17 @@ pub struct Runtime { } impl Runtime { + pub fn new(platform: PlatformType, requirement: RuntimeReq) -> Self { + Self { + platform, + requirement, + } + } + + pub fn system() -> Self { + Self::new(PlatformType::System, RuntimeReq::Global) + } + pub fn label(&self) -> String { match self.platform { PlatformType::System => "system".into(), From c2e6b2fb51c8897bbabc454f1e49f491cfb21252 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:17:17 -0700 Subject: [PATCH 5/9] Update node and system. --- Cargo.lock | 2 +- crates/core/tool/src/manager.rs | 4 +- crates/deno/platform/src/platform.rs | 4 +- crates/node/platform/src/platform.rs | 62 ++++++++++++----------- crates/node/tool/Cargo.toml | 2 +- crates/node/tool/src/node_tool.rs | 14 +++-- crates/node/tool/src/npm_tool.rs | 6 +-- crates/node/tool/src/pnpm_tool.rs | 5 +- crates/node/tool/src/yarn_tool.rs | 6 +-- crates/rust/platform/src/rust_platform.rs | 14 ++--- crates/rust/tool/src/rust_tool.rs | 6 +-- crates/system/platform/src/platform.rs | 8 +-- nextgen/platform-runtime/src/lib.rs | 2 +- 13 files changed, 64 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9820132b506..16ff504971a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3542,7 +3542,7 @@ dependencies = [ "moon_config", "moon_logger", "moon_node_lang", - "moon_platform_runtime", + "moon_platform_runtime2", "moon_process", "moon_terminal", "moon_tool", diff --git a/crates/core/tool/src/manager.rs b/crates/core/tool/src/manager.rs index 763efb7c200..81dcb82d523 100644 --- a/crates/core/tool/src/manager.rs +++ b/crates/core/tool/src/manager.rs @@ -1,7 +1,7 @@ use crate::errors::ToolError; use crate::tool::Tool; use moon_platform_runtime2::{Runtime, RuntimeReq}; -use proto_core::Version as SemVersion; +use proto_core::Version; use rustc_hash::FxHashMap; pub struct ToolManager { @@ -50,7 +50,7 @@ impl ToolManager { pub async fn setup( &mut self, req: &RuntimeReq, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { match self.cache.get_mut(&req) { Some(cache) => Ok(cache.setup(last_versions).await?), diff --git a/crates/deno/platform/src/platform.rs b/crates/deno/platform/src/platform.rs index 8e08f64c974..25e6da3703e 100644 --- a/crates/deno/platform/src/platform.rs +++ b/crates/deno/platform/src/platform.rs @@ -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::{ @@ -148,7 +148,7 @@ impl Platform for DenoPlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let req = &runtime.requirement; diff --git a/crates/node/platform/src/platform.rs b/crates/node/platform/src/platform.rs index 2c389c8ea0f..7c359f58221 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( + PlatformType::Node, + RuntimeReq::ToolchainOverride(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..952ff172eec 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_runtime2 = { 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..2ff1f4c0a51 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_runtime2::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 2c9655432c9..e19719004f4 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -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}; @@ -172,21 +172,21 @@ impl Platform for RustPlatform { } async fn setup_toolchain(&mut self) -> miette::Result<()> { - let version = match &self.config.version { + 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(()) } @@ -203,7 +203,7 @@ impl Platform for RustPlatform { &mut self, _context: &ActionContext, runtime: &Runtime, - last_versions: &mut FxHashMap, + last_versions: &mut FxHashMap, ) -> miette::Result { let req = &runtime.requirement; diff --git a/crates/rust/tool/src/rust_tool.rs b/crates/rust/tool/src/rust_tool.rs index c8335fcafe1..76ffc7e7b73 100644 --- a/crates/rust/tool/src/rust_tool.rs +++ b/crates/rust/tool/src/rust_tool.rs @@ -4,9 +4,7 @@ use moon_platform_runtime2::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, @@ -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/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs index 7c152458675..dcad36fafcd 100644 --- a/nextgen/platform-runtime/src/lib.rs +++ b/nextgen/platform-runtime/src/lib.rs @@ -1,4 +1,4 @@ -use moon_config::{PlatformType, Version, VersionSpec}; +pub use moon_config::{PlatformType, Version, VersionSpec}; use serde::Serialize; use std::fmt; From 4b4b840f2a2b18bd7f6e10ea247eaac4472dd667 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:29:53 -0700 Subject: [PATCH 6/9] 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 From 87bdd539e48fbf2be6be35986c14391ec5f841c2 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:56:16 -0700 Subject: [PATCH 7/9] Delete old code. --- Cargo.lock | 8 --- crates/core/platform-runtime/Cargo.toml | 9 --- crates/core/platform-runtime/src/lib.rs | 5 -- crates/core/platform-runtime/src/runtime.rs | 56 --------------- crates/core/platform-runtime/src/version.rs | 76 --------------------- rust-toolchain.toml | 2 +- 6 files changed, 1 insertion(+), 155 deletions(-) delete mode 100644 crates/core/platform-runtime/Cargo.toml delete mode 100644 crates/core/platform-runtime/src/lib.rs delete mode 100644 crates/core/platform-runtime/src/runtime.rs delete mode 100644 crates/core/platform-runtime/src/version.rs diff --git a/Cargo.lock b/Cargo.lock index 16ff504971a..ed4124fa644 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3634,14 +3634,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "moon_platform_runtime" -version = "0.1.0" -dependencies = [ - "moon_config", - "serde", -] - [[package]] name = "moon_platform_runtime2" version = "0.1.0" diff --git a/crates/core/platform-runtime/Cargo.toml b/crates/core/platform-runtime/Cargo.toml deleted file mode 100644 index 46fb02e27d1..00000000000 --- a/crates/core/platform-runtime/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "moon_platform_runtime" -version = "0.1.0" -edition = "2021" -publish = false - -[dependencies] -moon_config = { path = "../../../nextgen/config" } -serde = { workspace = true } 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/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" From 204e57198dd14eb5ac2c27655e42e2218e4dc782 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 11:27:43 -0700 Subject: [PATCH 8/9] Redo override. --- crates/core/action/src/node.rs | 6 ++--- crates/node/platform/src/platform.rs | 4 +-- crates/rust/platform/src/rust_platform.rs | 6 ++--- .../rust/platform/tests/rust_platform_test.rs | 4 +-- nextgen/platform-runtime/src/lib.rs | 27 +++++++------------ 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/crates/core/action/src/node.rs b/crates/core/action/src/node.rs index 5637fa7c258..49fcafc43a1 100644 --- a/crates/core/action/src/node.rs +++ b/crates/core/action/src/node.rs @@ -36,14 +36,14 @@ impl ActionNode { pub fn label(&self) -> String { match self { ActionNode::InstallDeps(runtime) => { - if runtime.requirement.is_latest() { + if runtime.requirement.is_global() { format!("Install{}Deps", runtime) } else { format!("Install{}Deps({})", runtime, runtime.requirement) } } ActionNode::InstallProjectDeps(runtime, id) => { - if runtime.requirement.is_latest() { + if runtime.requirement.is_global() { format!("Install{}DepsInProject({id})", runtime) } else { format!( @@ -56,7 +56,7 @@ impl ActionNode { ActionNode::RunInteractiveTarget(_, id) => format!("RunInteractiveTarget({id})"), ActionNode::RunPersistentTarget(_, id) => format!("RunPersistentTarget({id})"), ActionNode::SetupTool(runtime) => { - if runtime.requirement.is_latest() { + if runtime.requirement.is_global() { format!("Setup{}Tool", runtime) } else { format!("Setup{}Tool({})", runtime, runtime.requirement) diff --git a/crates/node/platform/src/platform.rs b/crates/node/platform/src/platform.rs index 7c359f58221..0dad61a2a32 100644 --- a/crates/node/platform/src/platform.rs +++ b/crates/node/platform/src/platform.rs @@ -71,9 +71,9 @@ 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::new( + return Runtime::new_override( PlatformType::Node, - RuntimeReq::ToolchainOverride(VersionSpec::Version(version.to_owned())), + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), ); } } diff --git a/crates/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index e19719004f4..254dca6534a 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -71,9 +71,9 @@ 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::new( + return Runtime::new_override( PlatformType::Rust, - RuntimeReq::ToolchainOverride(VersionSpec::Version(version.to_owned())), + RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())), ); } } @@ -472,7 +472,7 @@ impl Platform for RustPlatform { | "rustdoc" | "rustfmt" | "rustup" => {} // Handle toolchains for cargo commands "cargo" => { - if runtime.requirement.is_override() { + if runtime.overridden { args.push(format!("+{}", runtime.requirement)); } } diff --git a/crates/rust/platform/tests/rust_platform_test.rs b/crates/rust/platform/tests/rust_platform_test.rs index dd71854b360..67a5bfb131d 100644 --- a/crates/rust/platform/tests/rust_platform_test.rs +++ b/crates/rust/platform/tests/rust_platform_test.rs @@ -271,9 +271,9 @@ mod target_command { &ActionContext::default(), &Project::default(), &task, - &Runtime::new( + &Runtime::new_override( PlatformType::Rust, - RuntimeReq::ToolchainOverride(VersionSpec::parse("1.60.0").unwrap()), + RuntimeReq::Toolchain(VersionSpec::parse("1.60.0").unwrap()), ), &PathBuf::from("cwd"), ) diff --git a/nextgen/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs index dcad36fafcd..36b3cca46aa 100644 --- a/nextgen/platform-runtime/src/lib.rs +++ b/nextgen/platform-runtime/src/lib.rs @@ -8,8 +8,6 @@ pub enum RuntimeReq { Global, // Install tool into toolchain Toolchain(VersionSpec), - // Use toolchain but override the version - ToolchainOverride(VersionSpec), } impl RuntimeReq { @@ -17,22 +15,9 @@ impl RuntimeReq { matches!(self, Self::Global) } - pub fn is_latest(&self) -> bool { - match self { - Self::Toolchain(VersionSpec::Alias(alias)) - | Self::ToolchainOverride(VersionSpec::Alias(alias)) => alias == "latest", - _ => false, - } - } - - pub fn is_override(&self) -> bool { - matches!(self, Self::ToolchainOverride(_)) - } - pub fn to_version(&self) -> Option { match self { - Self::Toolchain(VersionSpec::Version(version)) - | Self::ToolchainOverride(VersionSpec::Version(version)) => Some(version.to_owned()), + Self::Toolchain(VersionSpec::Version(version)) => Some(version.to_owned()), _ => None, } } @@ -42,7 +27,7 @@ impl fmt::Display for RuntimeReq { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Self::Global => write!(f, "global"), - Self::Toolchain(spec) | Self::ToolchainOverride(spec) => write!(f, "{}", spec), + Self::Toolchain(spec) => write!(f, "{}", spec), } } } @@ -63,6 +48,7 @@ impl From<&Runtime> for RuntimeReq { pub struct Runtime { pub platform: PlatformType, pub requirement: RuntimeReq, + pub overridden: bool, } impl Runtime { @@ -70,9 +56,16 @@ impl Runtime { 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) } From 12fc141cf898fd928a7ccc678e87f08a43bb0ada Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 11:42:40 -0700 Subject: [PATCH 9/9] Rename. --- Cargo.lock | 18 +++++++++--------- crates/core/action/Cargo.toml | 2 +- crates/core/action/src/node.rs | 2 +- crates/core/emitter/Cargo.toml | 2 +- crates/core/emitter/src/event.rs | 2 +- crates/core/platform/Cargo.toml | 2 +- crates/core/platform/src/lib.rs | 2 +- crates/core/platform/src/platform.rs | 2 +- crates/core/runner/Cargo.toml | 2 +- crates/core/runner/src/runner.rs | 2 +- crates/core/tool/Cargo.toml | 2 +- crates/core/tool/src/errors.rs | 2 +- crates/core/tool/src/manager.rs | 2 +- crates/deno/tool/Cargo.toml | 2 +- crates/deno/tool/src/deno_tool.rs | 2 +- crates/node/tool/Cargo.toml | 2 +- crates/node/tool/src/node_tool.rs | 2 +- crates/rust/tool/Cargo.toml | 2 +- crates/rust/tool/src/rust_tool.rs | 2 +- nextgen/platform-runtime/Cargo.toml | 2 +- 20 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed4124fa644..b05506058e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3014,7 +3014,7 @@ version = "0.1.0" dependencies = [ "miette", "moon_common", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_target", "moon_utils", "serde", @@ -3366,7 +3366,7 @@ version = "0.1.0" dependencies = [ "miette", "moon_config", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_tool", "proto_core", "rustc-hash", @@ -3408,7 +3408,7 @@ dependencies = [ "miette", "moon_action", "moon_action_context", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_project", "moon_target", "moon_task", @@ -3542,7 +3542,7 @@ dependencies = [ "moon_config", "moon_logger", "moon_node_lang", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_process", "moon_terminal", "moon_tool", @@ -3607,7 +3607,7 @@ dependencies = [ "moon_common", "moon_config", "moon_hash", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_process", "moon_project", "moon_task", @@ -3635,7 +3635,7 @@ dependencies = [ ] [[package]] -name = "moon_platform_runtime2" +name = "moon_platform_runtime" version = "0.1.0" dependencies = [ "moon_config", @@ -3796,7 +3796,7 @@ dependencies = [ "moon_hash", "moon_logger", "moon_platform", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_process", "moon_project", "moon_target", @@ -3873,7 +3873,7 @@ dependencies = [ "miette", "moon_config", "moon_logger", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_process", "moon_terminal", "moon_tool", @@ -3991,7 +3991,7 @@ dependencies = [ "async-trait", "miette", "moon_lang", - "moon_platform_runtime2", + "moon_platform_runtime", "moon_process", "proto_core", "rustc-hash", diff --git a/crates/core/action/Cargo.toml b/crates/core/action/Cargo.toml index 1acf7da1538..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_runtime2 = { path = "../../../nextgen/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 49fcafc43a1..f79e2a63f54 100644 --- a/crates/core/action/src/node.rs +++ b/crates/core/action/src/node.rs @@ -1,5 +1,5 @@ use moon_common::Id; -use moon_platform_runtime2::Runtime; +use moon_platform_runtime::Runtime; use moon_target::Target; use serde::Serialize; use std::hash::{Hash, Hasher}; diff --git a/crates/core/emitter/Cargo.toml b/crates/core/emitter/Cargo.toml index 78fc6cca335..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_runtime2 = { path = "../../../nextgen/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/emitter/src/event.rs b/crates/core/emitter/src/event.rs index 0481ac5ab47..7552a2cbfc6 100644 --- a/crates/core/emitter/src/event.rs +++ b/crates/core/emitter/src/event.rs @@ -1,6 +1,6 @@ use moon_action::{Action, ActionNode}; use moon_action_context::ActionContext; -use moon_platform_runtime2::Runtime; +use moon_platform_runtime::Runtime; use moon_project::Project; use moon_target::Target; use moon_task::Task; diff --git a/crates/core/platform/Cargo.toml b/crates/core/platform/Cargo.toml index af605d9b2a6..8703ed1207c 100644 --- a/crates/core/platform/Cargo.toml +++ b/crates/core/platform/Cargo.toml @@ -9,7 +9,7 @@ moon_action_context = { path = "../action-context" } moon_common = { path = "../../../nextgen/common" } moon_config = { path = "../../../nextgen/config" } moon_hash = { path = "../../../nextgen/hash" } -moon_platform_runtime2 = { path = "../../../nextgen/platform-runtime" } +moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } moon_process = { path = "../../../nextgen/process" } moon_project = { path = "../../../nextgen/project" } moon_task = { path = "../../../nextgen/task" } diff --git a/crates/core/platform/src/lib.rs b/crates/core/platform/src/lib.rs index ad1a8aa17a9..5447a49c0a7 100644 --- a/crates/core/platform/src/lib.rs +++ b/crates/core/platform/src/lib.rs @@ -5,5 +5,5 @@ mod platform; pub use manager::*; pub use moon_config::PlatformType; -pub use moon_platform_runtime2::*; +pub use moon_platform_runtime::*; pub use platform::*; diff --git a/crates/core/platform/src/platform.rs b/crates/core/platform/src/platform.rs index 9efebaa142f..ac9cd2b98e0 100644 --- a/crates/core/platform/src/platform.rs +++ b/crates/core/platform/src/platform.rs @@ -6,7 +6,7 @@ use moon_config::{ ProjectsSourcesMap, TasksConfigsMap, Version, }; use moon_hash::ContentHasher; -use moon_platform_runtime2::{Runtime, RuntimeReq}; +use moon_platform_runtime::{Runtime, RuntimeReq}; use moon_process::Command; use moon_project::Project; use moon_task::Task; diff --git a/crates/core/runner/Cargo.toml b/crates/core/runner/Cargo.toml index 37248787ec7..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_runtime2 = { path = "../../../nextgen/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/runner/src/runner.rs b/crates/core/runner/src/runner.rs index 2a237059ac8..04bde98059a 100644 --- a/crates/core/runner/src/runner.rs +++ b/crates/core/runner/src/runner.rs @@ -11,7 +11,7 @@ use moon_emitter::{Emitter, Event, EventFlow}; use moon_hash::ContentHasher; use moon_logger::{debug, warn}; use moon_platform::PlatformManager; -use moon_platform_runtime2::Runtime; +use moon_platform_runtime::Runtime; use moon_process::{args, output_to_error, output_to_string, Command, Output}; use moon_project::Project; use moon_target::{TargetError, TargetScope}; diff --git a/crates/core/tool/Cargo.toml b/crates/core/tool/Cargo.toml index 26c5bbcecb6..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_runtime2 = { path = "../../../nextgen/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/errors.rs b/crates/core/tool/src/errors.rs index 71834129e71..e1b88ebaf82 100644 --- a/crates/core/tool/src/errors.rs +++ b/crates/core/tool/src/errors.rs @@ -1,5 +1,5 @@ use miette::Diagnostic; -use moon_platform_runtime2::Runtime; +use moon_platform_runtime::Runtime; use starbase_styles::{Style, Stylize}; use thiserror::Error; diff --git a/crates/core/tool/src/manager.rs b/crates/core/tool/src/manager.rs index c88c0ac768f..e4b438cc642 100644 --- a/crates/core/tool/src/manager.rs +++ b/crates/core/tool/src/manager.rs @@ -1,6 +1,6 @@ use crate::errors::ToolError; use crate::tool::Tool; -use moon_platform_runtime2::{Runtime, RuntimeReq}; +use moon_platform_runtime::{Runtime, RuntimeReq}; use proto_core::Version; use rustc_hash::FxHashMap; diff --git a/crates/deno/tool/Cargo.toml b/crates/deno/tool/Cargo.toml index 5abd668c0d2..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_runtime2 = { path = "../../../nextgen/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 c1e2c35c93c..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_runtime2::RuntimeReq; +use moon_platform_runtime::RuntimeReq; use moon_tool::{async_trait, Tool}; use proto_core::ProtoEnvironment; use std::path::PathBuf; diff --git a/crates/node/tool/Cargo.toml b/crates/node/tool/Cargo.toml index 952ff172eec..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_runtime2 = { path = "../../../nextgen/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 2ff1f4c0a51..cb62c451b5f 100644 --- a/crates/node/tool/src/node_tool.rs +++ b/crates/node/tool/src/node_tool.rs @@ -4,7 +4,7 @@ use crate::yarn_tool::YarnTool; use moon_config::{NodeConfig, NodePackageManager}; use moon_logger::debug; use moon_node_lang::node; -use moon_platform_runtime2::RuntimeReq; +use moon_platform_runtime::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{ diff --git a/crates/rust/tool/Cargo.toml b/crates/rust/tool/Cargo.toml index 9b79ef54c03..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_runtime2 = { path = "../../../nextgen/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 76ffc7e7b73..ef6a683e2ce 100644 --- a/crates/rust/tool/src/rust_tool.rs +++ b/crates/rust/tool/src/rust_tool.rs @@ -1,6 +1,6 @@ use moon_config::RustConfig; use moon_logger::debug; -use moon_platform_runtime2::RuntimeReq; +use moon_platform_runtime::RuntimeReq; use moon_process::Command; use moon_terminal::{print_checkpoint, Checkpoint}; use moon_tool::{async_trait, load_tool_plugin, Tool}; diff --git a/nextgen/platform-runtime/Cargo.toml b/nextgen/platform-runtime/Cargo.toml index 6fcf6406332..40859f911c4 100644 --- a/nextgen/platform-runtime/Cargo.toml +++ b/nextgen/platform-runtime/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "moon_platform_runtime2" +name = "moon_platform_runtime" version = "0.1.0" edition = "2021" publish = false