-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
422 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use rim::{fingerprint::InstallationRecord, toolset_manifest::ToolsetManifest, components}; | ||
use serde::Serialize; | ||
use crate::Result; | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct Toolkit { | ||
name: String, | ||
version: String, | ||
desc: Option<String>, | ||
#[serde(alias = "notes")] | ||
info: Option<String>, | ||
#[serde(rename = "manifestURL")] | ||
manifest_url: Option<String>, | ||
components: Vec<components::Component>, | ||
} | ||
|
||
impl Toolkit { | ||
/// Try getting the toolkit from installation record and the original manifest. | ||
/// | ||
/// We need the manifest because it contains the details of the toolkit along with | ||
/// what components it has. | ||
pub fn from_installed(manifest: &ToolsetManifest) -> Result<Option<Self>> { | ||
if !InstallationRecord::exists()? { | ||
// No toolkit installed, return None | ||
return Ok(None); | ||
} | ||
|
||
let mut tk = Self { | ||
name: t!("unknown_toolkit").to_string(), | ||
version: "N/A".to_string(), | ||
desc: None, | ||
info: None, | ||
manifest_url: None, | ||
components: vec![] | ||
}; | ||
let fp = InstallationRecord::load_from_install_dir()?; | ||
|
||
// The name and version should always be read from the install record, | ||
// but the components should only be load from manifest if the name and version are matched | ||
if let Some(name) = &fp.name { | ||
tk.name = name.to_owned(); | ||
} | ||
if let Some(ver) = &fp.version { | ||
tk.version = ver.to_owned(); | ||
} | ||
if matches!(&manifest.name, Some(name) if *name == tk.name) | ||
&& matches!(&manifest.version, Some(ver) if *ver == tk.version) | ||
{ | ||
tk.components = components::get_component_list_from_manifest(manifest)?; | ||
} | ||
|
||
Ok(Some(tk)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[[packages]] | ||
name = "XXX Community" | ||
version = "1.80.1" | ||
desc = "Description for community version" | ||
info = ''' | ||
# Changelog | ||
This is the initial build, includes: | ||
- Rust 1.80.1 version | ||
- blah blah blah | ||
- ... | ||
''' | ||
manifest-url = "https://example.com/path/to/manifest-1.80.1" | ||
|
||
[[packages]] | ||
name = "XXX Community" | ||
version = "1.81.0" | ||
desc = "Description for community version" | ||
info = ''' | ||
# Changelog | ||
- add new tool support: hello_world | ||
- ... | ||
''' | ||
manifest-url = "https://example.com/path/to/manifest-1.81.0" | ||
|
||
[[packages]] | ||
name = "XXX LTS" | ||
version = "1.80.1" | ||
desc = "Description for LTS version" | ||
info = ''' | ||
# Changelog | ||
This is the initial build, includes: | ||
- Rust 1.80.1 version | ||
- blah blah blah | ||
- ... | ||
''' | ||
manifest-url = "https://example.com/path/to/manifest-1.80.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::path::Path; | ||
|
||
/// Declare a statically allocated `OnceLock` path, and create that directory if it does not exists. | ||
macro_rules! get_path_and_create { | ||
($path_ident:ident, $init:expr) => {{ | ||
static $path_ident: std::sync::OnceLock<std::path::PathBuf> = std::sync::OnceLock::new(); | ||
let __path__ = $path_ident.get_or_init(|| $init); | ||
$crate::utils::ensure_dir(__path__) | ||
.expect("unable to create one of the directory under installation folder"); | ||
__path__ | ||
}}; | ||
} | ||
|
||
pub(crate) trait RimDir { | ||
fn install_dir(&self) -> &Path; | ||
|
||
fn cargo_home(&self) -> &Path { | ||
get_path_and_create!(CARGO_HOME_DIR, self.install_dir().join(".cargo")) | ||
} | ||
|
||
fn cargo_bin(&self) -> &Path { | ||
get_path_and_create!(CARGO_BIN_DIR, self.cargo_home().join("bin")) | ||
} | ||
|
||
fn rustup_home(&self) -> &Path { | ||
get_path_and_create!(RUSTUP_HOME_DIR, self.install_dir().join(".rustup")) | ||
} | ||
|
||
fn temp_root(&self) -> &Path { | ||
get_path_and_create!(TEMP_DIR, self.install_dir().join("temp")) | ||
} | ||
|
||
fn tools_dir(&self) -> &Path { | ||
get_path_and_create!(TOOLS_DIR, self.install_dir().join("tools")) | ||
} | ||
} |
Oops, something went wrong.