Skip to content

Commit 7329e4e

Browse files
committed
Currently, component_name was being repurposed for multiple functions:
- Checking whether or not the executable was published by forc - Checking whether or not the executable was in the store - Used to generate the tarball target - Used to generate the tarball URL - Used to generate the final target executable to run from the store Each of the above was breaking in subtle ways depending on which executable was being run. After separating out these functions based on the properly resolved component from the executable, and along with the previous commits, these problems above were resolved.
1 parent 003b485 commit 7329e4e

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/proxy_cli.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
toolchain_override::ToolchainOverride,
77
};
88
use anyhow::Result;
9-
use component::Components;
9+
use component::{Component, Components};
1010
use std::{
1111
env,
1212
ffi::OsString,
@@ -46,31 +46,35 @@ fn direct_proxy(proc_name: &str, args: &[OsString], toolchain: &Toolchain) -> Re
4646
// Install the entire toolchain declared in [toolchain] if it does not exist.
4747
toolchain.install_if_nonexistent(&description)?;
4848

49-
// Plugins distributed by forc have to be handled a little differently,
50-
// if one of them is called we want to check for 'forc' instead.
51-
let component_name = if Components::is_distributed_by_forc(proc_name) {
52-
component::FORC
53-
} else {
54-
proc_name
55-
};
49+
// If a specific version is declared, we want to call it from the
50+
// store and not from the toolchain directory.
51+
if let Some(version) = to.get_component_version(proc_name) {
52+
let component = match Component::resolve_from_name(proc_name) {
53+
Some(component) => component,
54+
None => {
55+
return Err(Error::new(
56+
ErrorKind::NotFound,
57+
format!("Component '{proc_name}' with version '{version}' not found"),
58+
)
59+
.into());
60+
}
61+
};
5662

57-
// If a specific version is declared, we want to call it from the store and not from the toolchain directory.
58-
if let Some(version) = to.get_component_version(component_name) {
5963
let store = Store::from_env()?;
6064

61-
if !store.has_component(component_name, version) {
65+
if !store.has_component(&component.name, version) {
6266
let download_cfg = DownloadCfg::new(
63-
component_name,
64-
TargetTriple::from_component(component_name)?,
67+
&component.name,
68+
TargetTriple::from_component(&component.name)?,
6569
Some(version.clone()),
6670
)?;
6771
// Install components within [components] that are declared but missing from the store.
6872
store.install_component(&download_cfg)?;
69-
};
73+
}
7074

7175
(
7276
store
73-
.component_dir_path(component_name, version)
77+
.component_dir_path(&component.name, version)
7478
.join(proc_name),
7579
description.to_string(),
7680
)
@@ -94,7 +98,7 @@ fn direct_proxy(proc_name: &str, args: &[OsString], toolchain: &Toolchain) -> Re
9498
ErrorKind::NotFound => Err(Error::new(
9599
ErrorKind::NotFound,
96100
format!(
97-
"component '{proc_name}' not found in currently active toolchain '{toolchain_name}'"
101+
"Component '{proc_name}' not found in currently active toolchain '{toolchain_name}'"
98102
),
99103
)),
100104
_ => Err(error),

0 commit comments

Comments
 (0)