mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-29 22:01:07 +00:00
Merge pull request #64 from esp-rs/fix/config-file
Fix uninstall process
This commit is contained in:
commit
1393e7e13f
@ -14,13 +14,13 @@ pub struct Config {
|
|||||||
/// ESP-IDF version
|
/// ESP-IDF version
|
||||||
pub esp_idf_version: Option<String>,
|
pub esp_idf_version: Option<String>,
|
||||||
/// Destination of the generated export file.
|
/// Destination of the generated export file.
|
||||||
pub export_file: PathBuf,
|
pub export_file: Option<PathBuf>,
|
||||||
/// Extra crates to installed.
|
/// Extra crates to installed.
|
||||||
pub extra_crates: Option<HashSet<String>>,
|
pub extra_crates: Option<HashSet<String>>,
|
||||||
/// Host triple
|
/// Host triple
|
||||||
pub host_triple: HostTriple,
|
pub host_triple: HostTriple,
|
||||||
/// LLVM toolchain path.
|
/// LLVM toolchain path.
|
||||||
pub llvm_path: PathBuf,
|
pub llvm_path: Option<PathBuf>,
|
||||||
/// Nightly Rust toolchain version.
|
/// Nightly Rust toolchain version.
|
||||||
pub nightly_version: String,
|
pub nightly_version: String,
|
||||||
/// List of targets instaled.
|
/// List of targets instaled.
|
||||||
|
46
src/main.rs
46
src/main.rs
@ -29,7 +29,7 @@ use std::{
|
|||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fs::{remove_dir_all, remove_file, File},
|
fs::{remove_dir_all, remove_file, File},
|
||||||
io::Write,
|
io::Write,
|
||||||
path::{Path, PathBuf},
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@ -220,7 +220,7 @@ fn install(args: InstallOpts) -> Result<(), Error> {
|
|||||||
info!("{} Saving configuration file", emoji::WRENCH);
|
info!("{} Saving configuration file", emoji::WRENCH);
|
||||||
let config = Config {
|
let config = Config {
|
||||||
esp_idf_version: args.esp_idf_version,
|
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: extra_crates.as_ref().map(|extra_crates| {
|
||||||
extra_crates
|
extra_crates
|
||||||
.iter()
|
.iter()
|
||||||
@ -228,7 +228,7 @@ fn install(args: InstallOpts) -> Result<(), Error> {
|
|||||||
.collect::<HashSet<String>>()
|
.collect::<HashSet<String>>()
|
||||||
}),
|
}),
|
||||||
host_triple,
|
host_triple,
|
||||||
llvm_path: llvm.path,
|
llvm_path: Some(llvm.path),
|
||||||
nightly_version: args.nightly_version,
|
nightly_version: args.nightly_version,
|
||||||
targets,
|
targets,
|
||||||
xtensa_rust,
|
xtensa_rust,
|
||||||
@ -249,7 +249,7 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
info!("{} Uninstalling esp-rs", emoji::DISC);
|
info!("{} Uninstalling esp-rs", emoji::DISC);
|
||||||
let config = Config::load().unwrap();
|
let mut config = Config::load().unwrap();
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"{} Arguments:
|
"{} Arguments:
|
||||||
@ -259,14 +259,23 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if let Some(xtensa_rust) = config.xtensa_rust {
|
if let Some(xtensa_rust) = config.xtensa_rust {
|
||||||
|
info!("{} Deleting Xtensa Rust toolchain", emoji::WRENCH);
|
||||||
|
config.xtensa_rust = None;
|
||||||
|
config.save()?;
|
||||||
xtensa_rust.uninstall()?;
|
xtensa_rust.uninstall()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} Deleting Xtensa LLVM", emoji::WRENCH);
|
if let Some(llvm_path) = config.llvm_path {
|
||||||
remove_dir_all(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 {
|
if let Some(esp_idf_version) = config.esp_idf_version {
|
||||||
info!("{} Deleting ESP-IDF {}", emoji::WRENCH, esp_idf_version);
|
info!("{} Deleting ESP-IDF {}", emoji::WRENCH, esp_idf_version);
|
||||||
|
config.esp_idf_version = None;
|
||||||
|
config.save()?;
|
||||||
let repo = EspIdfRemote {
|
let repo = EspIdfRemote {
|
||||||
git_ref: parse_esp_idf_git_ref(&esp_idf_version),
|
git_ref: parse_esp_idf_git_ref(&esp_idf_version),
|
||||||
repo_url: Some(DEFAULT_GIT_REPOSITORY.to_string()),
|
repo_url: Some(DEFAULT_GIT_REPOSITORY.to_string()),
|
||||||
@ -274,24 +283,33 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
remove_dir_all(get_install_path(repo).parent().unwrap())?;
|
remove_dir_all(get_install_path(repo).parent().unwrap())?;
|
||||||
} else {
|
} else {
|
||||||
info!("{} Deleting GCC targets", emoji::WRENCH);
|
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));
|
let gcc_path = get_tool_path(&get_toolchain_name(target));
|
||||||
remove_dir_all(gcc_path)?;
|
remove_dir_all(gcc_path)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} Uninstalling extra crates", emoji::WRENCH);
|
if config.extra_crates.is_some() {
|
||||||
if let Some(extra_crates) = &config.extra_crates {
|
info!("{} Uninstalling extra crates", emoji::WRENCH);
|
||||||
for extra_crate in extra_crates {
|
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()?;
|
cmd!("cargo", "uninstall", extra_crate).run()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()?;
|
clear_dist_folder()?;
|
||||||
|
|
||||||
info!("{} Deleting export file", emoji::WRENCH);
|
|
||||||
remove_file(Path::new(&config.export_file))?;
|
|
||||||
|
|
||||||
info!("{} Deleting config file", emoji::WRENCH);
|
info!("{} Deleting config file", emoji::WRENCH);
|
||||||
let conf_file = Config::get_config_path()?;
|
let conf_file = Config::get_config_path()?;
|
||||||
remove_file(conf_file)?;
|
remove_file(conf_file)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user