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 uninstall process #64

Merged
merged 3 commits into from
Nov 15, 2022
Merged
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
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub struct Config {
/// ESP-IDF version
pub esp_idf_version: Option<String>,
/// Destination of the generated export file.
pub export_file: PathBuf,
pub export_file: Option<PathBuf>,
/// Extra crates to installed.
pub extra_crates: Option<HashSet<String>>,
/// Host triple
pub host_triple: HostTriple,
/// LLVM toolchain path.
pub llvm_path: PathBuf,
pub llvm_path: Option<PathBuf>,
/// Nightly Rust toolchain version.
pub nightly_version: String,
/// List of targets instaled.
Expand Down
46 changes: 32 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{
collections::HashSet,
fs::{remove_dir_all, remove_file, File},
io::Write,
path::{Path, PathBuf},
path::PathBuf,
};

#[cfg(windows)]
Expand Down Expand Up @@ -220,15 +220,15 @@ fn install(args: InstallOpts) -> Result<(), Error> {
info!("{} Saving configuration file", emoji::WRENCH);
let config = Config {
esp_idf_version: args.esp_idf_version,
export_file,
export_file: Some(export_file),
extra_crates: extra_crates.as_ref().map(|extra_crates| {
extra_crates
.iter()
.map(|x| x.name.clone())
.collect::<HashSet<String>>()
}),
host_triple,
llvm_path: llvm.path,
llvm_path: Some(llvm.path),
nightly_version: args.nightly_version,
targets,
xtensa_rust,
Expand All @@ -249,7 +249,7 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));

info!("{} Uninstalling esp-rs", emoji::DISC);
let config = Config::load().unwrap();
let mut config = Config::load().unwrap();

debug!(
"{} Arguments:
Expand All @@ -259,39 +259,57 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
);

if let Some(xtensa_rust) = config.xtensa_rust {
info!("{} Deleting Xtensa Rust toolchain", emoji::WRENCH);
config.xtensa_rust = None;
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
config.save()?;
xtensa_rust.uninstall()?;
}

info!("{} Deleting Xtensa LLVM", emoji::WRENCH);
remove_dir_all(config.llvm_path)?;
if let Some(llvm_path) = config.llvm_path {
info!("{} Deleting Xtensa LLVM", emoji::WRENCH);
config.llvm_path = None;
config.save()?;
remove_dir_all(llvm_path)?;
}

if let Some(esp_idf_version) = config.esp_idf_version {
info!("{} Deleting ESP-IDF {}", emoji::WRENCH, esp_idf_version);
config.esp_idf_version = None;
config.save()?;
let repo = EspIdfRemote {
git_ref: parse_esp_idf_git_ref(&esp_idf_version),
repo_url: Some(DEFAULT_GIT_REPOSITORY.to_string()),
};
remove_dir_all(get_install_path(repo).parent().unwrap())?;
} else {
info!("{} Deleting GCC targets", emoji::WRENCH);
for target in &config.targets {
for target in &config.targets.clone() {
config.targets.remove(target);
config.save()?;
let gcc_path = get_tool_path(&get_toolchain_name(target));
remove_dir_all(gcc_path)?;
}
}

info!("{} Uninstalling extra crates", emoji::WRENCH);
if let Some(extra_crates) = &config.extra_crates {
for extra_crate in extra_crates {
if config.extra_crates.is_some() {
info!("{} Uninstalling extra crates", emoji::WRENCH);
let mut updated_extra_crates: HashSet<String> = config.extra_crates.clone().unwrap();
for extra_crate in &config.extra_crates.clone().unwrap() {
updated_extra_crates.remove(extra_crate);
config.extra_crates = Some(updated_extra_crates.clone());
config.save()?;
cmd!("cargo", "uninstall", extra_crate).run()?;
}
}

clear_dist_folder()?;

info!("{} Deleting export file", emoji::WRENCH);
remove_file(Path::new(&config.export_file))?;
if let Some(export_file) = config.export_file {
info!("{} Deleting export file", emoji::WRENCH);
config.export_file = None;
config.save()?;
remove_file(export_file)?;
}

clear_dist_folder()?;
info!("{} Deleting config file", emoji::WRENCH);
let conf_file = Config::get_config_path()?;
remove_file(conf_file)?;
Expand Down