Skip to content

Commit

Permalink
Redo override.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 20, 2023
1 parent 87bdd53 commit 204e571
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
6 changes: 3 additions & 3 deletions crates/core/action/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions crates/node/platform/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rust/platform/src/rust_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
);
}
}
Expand Down Expand Up @@ -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));
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rust/platform/tests/rust_platform_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down
27 changes: 10 additions & 17 deletions nextgen/platform-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,16 @@ pub enum RuntimeReq {
Global,
// Install tool into toolchain
Toolchain(VersionSpec),
// Use toolchain but override the version
ToolchainOverride(VersionSpec),
}

impl RuntimeReq {
pub fn is_global(&self) -> bool {
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<Version> {
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,
}
}
Expand All @@ -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),
}
}
}
Expand All @@ -63,16 +48,24 @@ impl From<&Runtime> for RuntimeReq {
pub struct Runtime {
pub platform: PlatformType,
pub requirement: RuntimeReq,
pub overridden: bool,
}

impl Runtime {
pub fn new(platform: PlatformType, requirement: RuntimeReq) -> Self {
Self {
platform,
requirement,
overridden: false,
}
}

pub fn new_override(platform: PlatformType, requirement: RuntimeReq) -> Self {
let mut runtime = Self::new(platform, requirement);
runtime.overridden = true;
runtime
}

pub fn system() -> Self {
Self::new(PlatformType::System, RuntimeReq::Global)
}
Expand Down

0 comments on commit 204e571

Please sign in to comment.