From 7071c1ff24246e5656bc5f27850e6a6dc11cddf0 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 20 Sep 2023 10:07:15 -0700 Subject: [PATCH] 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(),