Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix component URL if bundled within the forc tarball (#654) #664

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ impl Components {
Ok(executables)
}

pub fn is_distributed_by_forc(plugin_name: &str) -> bool {
let components = Self::from_toml(COMPONENTS_TOML).expect("Failed to parse components toml");
if let Some(forc) = components.component.get(FORC) {
return forc.executables.contains(&plugin_name.to_string());
};
false
pub fn is_distributed_by_forc(component: &str) -> bool {
Component::from_name(component)
.map(|comp| {
comp.name == FORC
|| Component::from_name(FORC)
.map(|forc| comp.tarball_prefix == forc.tarball_prefix)
.unwrap_or(false)
})
.unwrap_or(false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl DownloadCfg {
.map_err(|e| anyhow!("Error getting latest tag for '{}': {}", name, e))?,
};

let (tarball_name, tarball_url) = if name == FUELUP {
let (tarball_name, tarball_url) = if component::Components::is_distributed_by_forc(name) {
let tarball_name = tarball_name(FUELUP, &version, &target);
let tarball_url = github_releases_download_url(FUELUP, &version, &tarball_name);
(tarball_name, tarball_url)
Expand Down
59 changes: 28 additions & 31 deletions src/target_triple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{bail, Result};
use component::{self, Component};
use component::{self, Components};
use std::fmt;

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
Expand Down Expand Up @@ -53,40 +53,37 @@ impl TargetTriple {
}

pub fn from_component(component: &str) -> Result<Self> {
match Component::from_name(component).map(|c| c.name)?.as_str() {
component::FORC => {
let os = match std::env::consts::OS {
"macos" => "darwin",
"linux" => "linux",
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
};
let architecture = match std::env::consts::ARCH {
"aarch64" => "arm64",
"x86_64" => "amd64",
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
};
if Components::is_distributed_by_forc(component) {
let os = match std::env::consts::OS {
"macos" => "darwin",
"linux" => "linux",
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
};
let architecture = match std::env::consts::ARCH {
"aarch64" => "arm64",
"x86_64" => "amd64",
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
};

Ok(Self(format!("{os}_{architecture}")))
}
_ => {
let architecture = match std::env::consts::ARCH {
"aarch64" | "x86_64" => std::env::consts::ARCH,
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
};
Ok(Self(format!("{os}_{architecture}")))
} else {
let architecture = match std::env::consts::ARCH {
"aarch64" | "x86_64" => std::env::consts::ARCH,
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
};

let vendor = match std::env::consts::OS {
"macos" => "apple",
_ => "unknown",
};
let vendor = match std::env::consts::OS {
"macos" => "apple",
_ => "unknown",
};

let os = match std::env::consts::OS {
"macos" => "darwin",
"linux" => "linux-gnu",
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
};
let os = match std::env::consts::OS {
"macos" => "darwin",
"linux" => "linux-gnu",
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
};

Ok(Self(format!("{architecture}-{vendor}-{os}")))
}
Ok(Self(format!("{architecture}-{vendor}-{os}")))
}
}
}
2 changes: 1 addition & 1 deletion tests/testcfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl TestCfg {
.args(args)
.current_dir(&self.home)
.env("HOME", &self.home)
.env("CARGO_HOME", &self.home.join(".cargo"))
.env("CARGO_HOME", self.home.join(".cargo"))
.env(
"PATH",
format!(
Expand Down
Loading