mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 15:14:56 +00:00
refactor: ♻️ Refactor extra-crates arg
This commit is contained in:
parent
d95c275af9
commit
f370c567f9
@ -16,7 +16,7 @@ pub struct Config {
|
|||||||
/// Destination of the generated export file.
|
/// Destination of the generated export file.
|
||||||
pub export_file: PathBuf,
|
pub export_file: PathBuf,
|
||||||
/// Extra crates to installed.
|
/// Extra crates to installed.
|
||||||
pub extra_crates: 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.
|
||||||
|
37
src/main.rs
37
src/main.rs
@ -17,7 +17,9 @@ use espup::{
|
|||||||
},
|
},
|
||||||
gcc::{get_toolchain_name, install_gcc_targets},
|
gcc::{get_toolchain_name, install_gcc_targets},
|
||||||
llvm::Llvm,
|
llvm::Llvm,
|
||||||
rust::{check_rust_installation, install_riscv_target, Crate, XtensaRust},
|
rust::{
|
||||||
|
check_rust_installation, install_extra_crates, install_riscv_target, Crate, XtensaRust,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
@ -129,11 +131,7 @@ fn install(args: InstallOpts) -> Result<()> {
|
|||||||
info!("{} Installing esp-rs", emoji::DISC);
|
info!("{} Installing esp-rs", emoji::DISC);
|
||||||
let targets = args.targets;
|
let targets = args.targets;
|
||||||
let host_triple = get_host_triple(args.default_host)?;
|
let host_triple = get_host_triple(args.default_host)?;
|
||||||
let mut extra_crates = if let Some(arg_crates) = args.extra_crates {
|
let mut extra_crates = args.extra_crates;
|
||||||
arg_crates
|
|
||||||
} else {
|
|
||||||
HashSet::new()
|
|
||||||
};
|
|
||||||
let mut exports: Vec<String> = Vec::new();
|
let mut exports: Vec<String> = Vec::new();
|
||||||
let export_file = args.export_file.clone();
|
let export_file = args.export_file.clone();
|
||||||
let xtensa_rust = if targets.contains(&Target::ESP32)
|
let xtensa_rust = if targets.contains(&Target::ESP32)
|
||||||
@ -195,18 +193,19 @@ fn install(args: InstallOpts) -> Result<()> {
|
|||||||
if let Some(espidf_version) = &args.espidf_version {
|
if let Some(espidf_version) = &args.espidf_version {
|
||||||
let repo = EspIdfRepo::new(espidf_version, args.profile_minimal, &targets);
|
let repo = EspIdfRepo::new(espidf_version, args.profile_minimal, &targets);
|
||||||
exports.extend(repo.install()?);
|
exports.extend(repo.install()?);
|
||||||
|
if let Some(ref mut extra_crates) = extra_crates {
|
||||||
extra_crates.insert(Crate::new("ldproxy"));
|
extra_crates.insert(Crate::new("ldproxy"));
|
||||||
|
} else {
|
||||||
|
let mut crates = HashSet::new();
|
||||||
|
crates.insert(Crate::new("ldproxy"));
|
||||||
|
extra_crates = Some(crates);
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
exports.extend(install_gcc_targets(&targets, &host_triple)?);
|
exports.extend(install_gcc_targets(&targets, &host_triple)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(
|
if let Some(ref extra_crates) = &extra_crates {
|
||||||
"{} Installing the following crates: {:#?}",
|
install_extra_crates(&extra_crates)?;
|
||||||
emoji::DEBUG,
|
|
||||||
extra_crates
|
|
||||||
);
|
|
||||||
for extra_crate in &extra_crates {
|
|
||||||
extra_crate.install()?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.profile_minimal {
|
if args.profile_minimal {
|
||||||
@ -219,10 +218,16 @@ fn install(args: InstallOpts) -> Result<()> {
|
|||||||
let config = Config {
|
let config = Config {
|
||||||
espidf_version: args.espidf_version,
|
espidf_version: args.espidf_version,
|
||||||
export_file,
|
export_file,
|
||||||
extra_crates: extra_crates
|
extra_crates: if let Some(extra_crates) = &extra_crates {
|
||||||
|
Some(
|
||||||
|
extra_crates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.name.clone())
|
.map(|x| x.name.clone())
|
||||||
.collect::<HashSet<String>>(),
|
.collect::<HashSet<String>>(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
host_triple,
|
host_triple,
|
||||||
llvm_path: llvm.path,
|
llvm_path: llvm.path,
|
||||||
nightly_version: args.nightly_version,
|
nightly_version: args.nightly_version,
|
||||||
@ -277,9 +282,11 @@ fn uninstall(args: UninstallOpts) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("{} Uninstalling extra crates", emoji::WRENCH);
|
info!("{} Uninstalling extra crates", emoji::WRENCH);
|
||||||
for extra_crate in &config.extra_crates {
|
if let Some(extra_crates) = &config.extra_crates {
|
||||||
|
for extra_crate in extra_crates {
|
||||||
cmd!("cargo", "uninstall", extra_crate).run()?;
|
cmd!("cargo", "uninstall", extra_crate).run()?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clear_dist_folder()?;
|
clear_dist_folder()?;
|
||||||
|
|
||||||
|
@ -233,6 +233,17 @@ impl Crate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn install_extra_crates(crates: &HashSet<Crate>) -> Result<()> {
|
||||||
|
debug!(
|
||||||
|
"{} Installing the following crates: {:#?}",
|
||||||
|
emoji::DEBUG,
|
||||||
|
crates
|
||||||
|
);
|
||||||
|
for c in crates {
|
||||||
|
c.install()?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
/// Gets the artifact extension based on the host architecture.
|
/// Gets the artifact extension based on the host architecture.
|
||||||
fn get_artifact_extension(host_triple: &HostTriple) -> &str {
|
fn get_artifact_extension(host_triple: &HostTriple) -> &str {
|
||||||
match host_triple {
|
match host_triple {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user