Skip to content

Commit

Permalink
Rename description to descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Mar 25, 2024
1 parent c76b0cd commit 8f88550
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/description/arch.rs → lib/descriptor/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Arch {
/**
Get the architecture of the current host system.
*/
pub fn current() -> Self {
pub fn current_system() -> Self {
match CURRENT_ARCH {
"aarch64" => Self::Arm64,
"x86_64" => Self::X64,
Expand Down Expand Up @@ -96,7 +96,7 @@ mod tests {

#[test]
fn current_arch() {
let arch = Arch::current();
let arch = Arch::current_system();
if cfg!(target_arch = "aarch64") {
assert_eq!(arch, Arch::Arm64);
} else if cfg!(target_arch = "x86_64") {
Expand Down
60 changes: 30 additions & 30 deletions lib/description/mod.rs → lib/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ pub enum DescriptionParseError {
used to check for compatibility between two or more specified systems.
*/
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Description {
pub struct Descripor {
os: OS,
arch: Arch,
toolchain: Option<Toolchain>,
}

impl Description {
impl Descripor {
/**
Get the description for the current host system.
*/
pub fn current() -> Self {
pub fn current_system() -> Self {
Self {
os: OS::current(),
arch: Arch::current(),
toolchain: Toolchain::current(),
os: OS::current_system(),
arch: Arch::current_system(),
toolchain: Toolchain::current_system(),
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ impl Description {
- Windows and Linux 64-bit can run 32-bit executables
- macOS Apple Silicon can run x64 (Intel) executables
*/
pub fn is_compatible_with(&self, other: &Description) -> bool {
pub fn is_compatible_with(&self, other: &Descripor) -> bool {
// Operating system must _always_ match
(self.os == other.os)
&& (
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Description {
}
}

impl FromStr for Description {
impl FromStr for Descripor {
type Err = DescriptionParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let os = OS::detect(s).ok_or(DescriptionParseError::OS)?;
Expand All @@ -138,60 +138,60 @@ impl FromStr for Description {
mod tests {
use super::*;

fn check_desc(description: &str, expected: Description) {
fn check_desc(description: &str, expected: Descripor) {
assert_eq!(
Description::detect(description),
Descripor::detect(description),
Some(expected),
"{description}"
);
}

#[test]
fn current_description() {
let current = Description::current();
assert_eq!(current.os, OS::current());
assert_eq!(current.arch, Arch::current());
assert_eq!(current.toolchain, Toolchain::current());
let current = Descripor::current_system();
assert_eq!(current.os, OS::current_system());
assert_eq!(current.arch, Arch::current_system());
assert_eq!(current.toolchain, Toolchain::current_system());
}

#[test]
fn detect_description_valid() {
// Windows
check_desc(
"windows-x64-msvc",
Description {
Descripor {
os: OS::Windows,
arch: Arch::X64,
toolchain: Some(Toolchain::Msvc),
},
);
check_desc(
"win64",
Description {
Descripor {
os: OS::Windows,
arch: Arch::X64,
toolchain: None,
},
);
check_desc(
"windows-x86-gnu",
Description {
Descripor {
os: OS::Windows,
arch: Arch::X86,
toolchain: Some(Toolchain::Gnu),
},
);
check_desc(
"windows-x86",
Description {
Descripor {
os: OS::Windows,
arch: Arch::X86,
toolchain: None,
},
);
check_desc(
"win32",
Description {
Descripor {
os: OS::Windows,
arch: Arch::X86,
toolchain: None,
Expand All @@ -200,23 +200,23 @@ mod tests {
// macOS
check_desc(
"aarch64-macos",
Description {
Descripor {
os: OS::MacOS,
arch: Arch::Arm64,
toolchain: None,
},
);
check_desc(
"macos-x64-gnu",
Description {
Descripor {
os: OS::MacOS,
arch: Arch::X64,
toolchain: Some(Toolchain::Gnu),
},
);
check_desc(
"macos-x64",
Description {
Descripor {
os: OS::MacOS,
arch: Arch::X64,
toolchain: None,
Expand All @@ -225,23 +225,23 @@ mod tests {
// Linux
check_desc(
"linux-x86_64-gnu",
Description {
Descripor {
os: OS::Linux,
arch: Arch::X64,
toolchain: Some(Toolchain::Gnu),
},
);
check_desc(
"linux-gnu-x86",
Description {
Descripor {
os: OS::Linux,
arch: Arch::X86,
toolchain: Some(Toolchain::Gnu),
},
);
check_desc(
"armv7-linux-musl",
Description {
Descripor {
os: OS::Linux,
arch: Arch::Arm32,
toolchain: Some(Toolchain::Musl),
Expand All @@ -254,15 +254,15 @@ mod tests {
// macOS universal binaries should parse as x64 (most compatible)
check_desc(
"macos-universal",
Description {
Descripor {
os: OS::MacOS,
arch: Arch::X64,
toolchain: None,
},
);
check_desc(
"darwin-universal",
Description {
Descripor {
os: OS::MacOS,
arch: Arch::X64,
toolchain: None,
Expand All @@ -284,7 +284,7 @@ mod tests {
"unknown-armv7-musl",
];
for description in INVALID_DESCRIPTIONS {
assert_eq!(Description::detect(description), None);
assert_eq!(Descripor::detect(description), None);
}
}

Expand All @@ -304,7 +304,7 @@ mod tests {
"armv7-linux-musl",
];
for description in VALID_STRINGS {
assert!(description.parse::<Description>().is_ok());
assert!(description.parse::<Descripor>().is_ok());
}
}

Expand All @@ -318,7 +318,7 @@ mod tests {
];
for description in INVALID_OS_STRINGS {
assert_eq!(
description.parse::<Description>(),
description.parse::<Descripor>(),
Err(DescriptionParseError::OS)
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/description/os.rs → lib/descriptor/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl OS {
/**
Get the operating system of the current host system.
*/
pub fn current() -> Self {
pub fn current_system() -> Self {
match CURRENT_OS {
"windows" => Self::Windows,
"macos" => Self::MacOS,
Expand Down Expand Up @@ -68,7 +68,7 @@ mod tests {

#[test]
fn current_os() {
let os = OS::current();
let os = OS::current_system();
if cfg!(target_os = "windows") {
assert_eq!(os, OS::Windows);
} else if cfg!(target_os = "macos") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Toolchain {
/**
Get the toolchain of the current host system.
*/
pub fn current() -> Option<Self> {
pub fn current_system() -> Option<Self> {
None // TODO: Implement detection of the host toolchain
}

Expand Down
2 changes: 1 addition & 1 deletion lib/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub(crate) mod util;

pub mod description;
pub mod descriptor;
pub mod manifests;
pub mod result;
pub mod sources;
Expand Down
6 changes: 3 additions & 3 deletions lib/sources/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tokio::time::sleep;
use tracing::{debug, info, instrument};

use crate::{
description::Description,
descriptor::Descripor,
tool::{ToolId, ToolSpec},
};

Expand Down Expand Up @@ -201,13 +201,13 @@ impl GitHubSource {
&self,
tool_spec: &ToolSpec,
release: &Release,
description: &Description,
description: &Descripor,
) -> Vec<Artifact> {
let mut compatible_artifacts = release
.assets
.iter()
.filter_map(|asset| {
if let Some(asset_desc) = Description::detect(asset.name.as_str()) {
if let Some(asset_desc) = Descripor::detect(asset.name.as_str()) {
if description.is_compatible_with(&asset_desc) {
let artifact = Artifact::from_github_release_asset(asset, tool_spec);
Some((asset_desc, artifact))
Expand Down
4 changes: 2 additions & 2 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use console::style;

use rokit::{
description::Description,
descriptor::Descripor,
manifests::RokitManifest,
storage::Home,
tool::{ToolAlias, ToolId},
Expand Down Expand Up @@ -97,7 +97,7 @@ impl AddSubcommand {
manifest.save(manifest_path).await?;

// 5. Download and install the tool
let description = Description::current();
let description = Descripor::current_system();
if !tool_cache.is_installed(&spec) || self.force {
pb.set_message("Downloading");
let release = source
Expand Down
4 changes: 2 additions & 2 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;

use console::style;
use futures::{stream::FuturesUnordered, TryStreamExt};
use rokit::{description::Description, manifests::RokitManifest, storage::Home};
use rokit::{descriptor::Descripor, manifests::RokitManifest, storage::Home};

use crate::util::{
discover_rokit_manifest_dirs, finish_progress_bar, github_tool_source, new_progress_bar,
Expand All @@ -32,7 +32,7 @@ impl InstallSubcommand {

let tool_cache = home.tool_cache();
let tool_storage = home.tool_storage();
let description = Description::current();
let description = Descripor::current_system();

// 1. Gather tool specifications from all known manifests

Expand Down

0 comments on commit 8f88550

Please sign in to comment.