diff --git a/Cargo.toml b/Cargo.toml index f0e8a9f..1559936 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ bin = [ ] wally-compat = ["zip", "serde_json"] patches = ["git2"] +version-management = ["bin"] [[bin]] name = "pesde" diff --git a/src/cli/commands/mod.rs b/src/cli/commands/mod.rs index 38d3442..a2daea0 100644 --- a/src/cli/commands/mod.rs +++ b/src/cli/commands/mod.rs @@ -14,7 +14,9 @@ mod patch; mod patch_commit; mod publish; mod run; +#[cfg(feature = "version-management")] mod self_install; +#[cfg(feature = "version-management")] mod self_upgrade; mod update; @@ -41,6 +43,7 @@ pub enum Subcommand { Publish(publish::PublishCommand), /// Installs the pesde binary and scripts + #[cfg(feature = "version-management")] SelfInstall(self_install::SelfInstallCommand), /// Sets up a patching environment for a package @@ -52,6 +55,7 @@ pub enum Subcommand { PatchCommit(patch_commit::PatchCommitCommand), /// Installs the latest version of pesde + #[cfg(feature = "version-management")] SelfUpgrade(self_upgrade::SelfUpgradeCommand), /// Adds a dependency to the project @@ -82,11 +86,13 @@ impl Subcommand { Subcommand::Run(run) => run.run(project), Subcommand::Install(install) => install.run(project, multi, reqwest), Subcommand::Publish(publish) => publish.run(project, reqwest), + #[cfg(feature = "version-management")] Subcommand::SelfInstall(self_install) => self_install.run(), #[cfg(feature = "patches")] Subcommand::Patch(patch) => patch.run(project, reqwest), #[cfg(feature = "patches")] Subcommand::PatchCommit(patch_commit) => patch_commit.run(project), + #[cfg(feature = "version-management")] Subcommand::SelfUpgrade(self_upgrade) => self_upgrade.run(reqwest), Subcommand::Add(add) => add.run(project), Subcommand::Update(update) => update.run(project, multi, reqwest), diff --git a/src/cli/mod.rs b/src/cli/mod.rs index b6651b9..42215f9 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -24,6 +24,7 @@ pub mod commands; pub mod config; pub mod files; pub mod repos; +#[cfg(feature = "version-management")] pub mod version; pub const HOME_DIR: &str = concat!(".", env!("CARGO_PKG_NAME")); @@ -119,6 +120,7 @@ impl, E: Into, N: FromStr, F: Into anyhow::Result<(PackageNames, VersionId)> { let version_id = match self.1 { Some(version) => version, diff --git a/src/cli/version.rs b/src/cli/version.rs index fdd2f83..ddb2983 100644 --- a/src/cli/version.rs +++ b/src/cli/version.rs @@ -157,10 +157,6 @@ pub fn get_or_download_version( reqwest: &reqwest::blocking::Client, version: &Version, ) -> anyhow::Result> { - #[cfg(debug_assertions)] - // possible hard to debug issues with the versioning system overtaking the debug build - return Ok(None); - let path = home_dir()?.join("versions"); create_dir_all(&path).context("failed to create versions directory")?; @@ -196,9 +192,6 @@ pub fn get_or_download_version( } pub fn max_installed_version() -> anyhow::Result { - #[cfg(debug_assertions)] - return Ok(current_version()); - let versions_dir = home_dir()?.join("versions"); create_dir_all(&versions_dir).context("failed to create versions directory")?; diff --git a/src/lib.rs b/src/lib.rs index 4168957..c974532 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -193,8 +193,9 @@ impl Project { let dir = dir.as_ref().to_path_buf(); let manifest = std::fs::read_to_string(dir.join(MANIFEST_FILE_NAME)) .map_err(|e| errors::WorkspaceMembersError::ManifestMissing(dir.to_path_buf(), e))?; - let manifest = toml::from_str::(&manifest) - .map_err(|e| errors::WorkspaceMembersError::ManifestDeser(dir.to_path_buf(), e))?; + let manifest = toml::from_str::(&manifest).map_err(|e| { + errors::WorkspaceMembersError::ManifestDeser(dir.to_path_buf(), Box::new(e)) + })?; let members = manifest .workspace_members @@ -211,8 +212,9 @@ impl Project { .map(|path| { let manifest = std::fs::read_to_string(path.join(MANIFEST_FILE_NAME)) .map_err(|e| errors::WorkspaceMembersError::ManifestMissing(path.clone(), e))?; - let manifest = toml::from_str::(&manifest) - .map_err(|e| errors::WorkspaceMembersError::ManifestDeser(path.clone(), e))?; + let manifest = toml::from_str::(&manifest).map_err(|e| { + errors::WorkspaceMembersError::ManifestDeser(path.clone(), Box::new(e)) + })?; Ok((path, manifest)) }) .collect::>() @@ -273,7 +275,7 @@ pub mod errors { /// An error occurred deserializing the manifest file #[error("error deserializing manifest file at {0}")] - ManifestDeser(PathBuf, #[source] toml::de::Error), + ManifestDeser(PathBuf, #[source] Box), /// An error occurred interacting with the filesystem #[error("error interacting with the filesystem")] diff --git a/src/main.rs b/src/main.rs index a5e5e46..4313fac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,13 +10,12 @@ use std::{ path::{Path, PathBuf}, }; +#[cfg(feature = "version-management")] +use crate::cli::version::{ + check_for_updates, current_version, get_or_download_version, max_installed_version, +}; use crate::cli::{ - auth::get_token, - config::read_config, - home_dir, - repos::update_repo_dependencies, - version::{check_for_updates, current_version, get_or_download_version, max_installed_version}, - HOME_DIR, + auth::get_token, config::read_config, home_dir, repos::update_repo_dependencies, HOME_DIR, }; mod cli; @@ -233,35 +232,39 @@ fn run() -> anyhow::Result<()> { .build()? }; - let target_version = project - .deser_manifest() - .ok() - .and_then(|manifest| manifest.pesde_version); + #[cfg(feature = "version-management")] + { + let target_version = project + .deser_manifest() + .ok() + .and_then(|manifest| manifest.pesde_version); - // store the current version in case it needs to be used later - get_or_download_version(&reqwest, ¤t_version())?; + // store the current version in case it needs to be used later + get_or_download_version(&reqwest, ¤t_version())?; - let exe_path = if let Some(version) = target_version { - Some(get_or_download_version(&reqwest, &version)?) - } else { - None - }; - let exe_path = if let Some(exe_path) = exe_path { - exe_path - } else { - get_or_download_version(&reqwest, &max_installed_version()?)? - }; + let exe_path = if let Some(version) = target_version { + Some(get_or_download_version(&reqwest, &version)?) + } else { + None + }; + let exe_path = if let Some(exe_path) = exe_path { + exe_path + } else { + get_or_download_version(&reqwest, &max_installed_version()?)? + }; - if let Some(exe_path) = exe_path { - let status = std::process::Command::new(exe_path) - .args(std::env::args_os().skip(1)) - .status() - .expect("failed to run new version"); + if let Some(exe_path) = exe_path { + let status = std::process::Command::new(exe_path) + .args(std::env::args_os().skip(1)) + .status() + .expect("failed to run new version"); - std::process::exit(status.code().unwrap()); + std::process::exit(status.code().unwrap()); + } + + display_err(check_for_updates(&reqwest), " while checking for updates"); } - display_err(check_for_updates(&reqwest), " while checking for updates"); display_err( update_repo_dependencies(&project), " while updating repository dependencies", diff --git a/src/source/git_index.rs b/src/source/git_index.rs index c9649f7..02a820e 100644 --- a/src/source/git_index.rs +++ b/src/source/git_index.rs @@ -11,7 +11,7 @@ pub trait GitBasedSource { fn repo_url(&self) -> &gix::Url; /// Gets the tree of the repository - fn tree<'a>(&'a self, repo: &'a gix::Repository) -> Result { + fn tree<'a>(&'a self, repo: &'a gix::Repository) -> Result, errors::TreeError> { // this is a bare repo, so this is the actual path let path = repo.path().to_path_buf();