mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-30 06:10:37 +00:00
Merge pull request #53 from esp-rs/fix/extra-crates
Update `extra-crates` argument
This commit is contained in:
commit
42b16d6301
@ -16,7 +16,7 @@ pub struct Config {
|
||||
/// Destination of the generated export file.
|
||||
pub export_file: PathBuf,
|
||||
/// Extra crates to installed.
|
||||
pub extra_crates: HashSet<String>,
|
||||
pub extra_crates: Option<HashSet<String>>,
|
||||
/// Host triple
|
||||
pub host_triple: HostTriple,
|
||||
/// LLVM toolchain path.
|
||||
|
53
src/main.rs
53
src/main.rs
@ -18,7 +18,9 @@ use espup::{
|
||||
},
|
||||
gcc::{get_toolchain_name, install_gcc_targets},
|
||||
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};
|
||||
@ -50,7 +52,7 @@ struct Cli {
|
||||
#[derive(Parser)]
|
||||
pub enum SubCommand {
|
||||
/// Installs esp-rs environment
|
||||
Install(InstallOpts),
|
||||
Install(Box<InstallOpts>),
|
||||
/// Uninstalls esp-rs environment
|
||||
Uninstall(UninstallOpts),
|
||||
/// Updates Xtensa Rust toolchain
|
||||
@ -81,8 +83,8 @@ pub struct InstallOpts {
|
||||
#[arg(short = 'f', long)]
|
||||
pub export_file: Option<PathBuf>,
|
||||
/// Comma or space list of extra crates to install.
|
||||
#[arg(short = 'c', long, default_value = "")]
|
||||
pub extra_crates: String,
|
||||
#[arg(short = 'c', long, required = false, value_parser = Crate::parse_crates)]
|
||||
pub extra_crates: Option<HashSet<Crate>>,
|
||||
/// LLVM version.
|
||||
#[arg(short = 'x', long, default_value = "15", value_parser = ["15"])]
|
||||
pub llvm_version: String,
|
||||
@ -96,8 +98,8 @@ pub struct InstallOpts {
|
||||
#[arg(short = 'm', long)]
|
||||
pub profile_minimal: bool,
|
||||
/// Comma or space separated list of targets [esp32,esp32s2,esp32s3,esp32c2,esp32c3,all].
|
||||
#[arg(short = 't', long, default_value = "all")]
|
||||
pub targets: String,
|
||||
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
|
||||
pub targets: HashSet<Target>,
|
||||
/// Xtensa Rust toolchain version.
|
||||
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
|
||||
pub toolchain_version: Option<String>,
|
||||
@ -128,9 +130,9 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
initialize_logger(&args.log_level);
|
||||
|
||||
info!("{} Installing esp-rs", emoji::DISC);
|
||||
let targets: HashSet<Target> = parse_targets(&args.targets).unwrap();
|
||||
let targets = args.targets;
|
||||
let host_triple = get_host_triple(args.default_host)?;
|
||||
let mut extra_crates: HashSet<Crate> = args.extra_crates.split(',').map(Crate::new).collect();
|
||||
let mut extra_crates = args.extra_crates;
|
||||
let mut exports: Vec<String> = Vec::new();
|
||||
let xtensa_rust = if targets.contains(&Target::ESP32)
|
||||
|| targets.contains(&Target::ESP32S2)
|
||||
@ -192,18 +194,19 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
if let Some(espidf_version) = &args.espidf_version {
|
||||
let repo = EspIdfRepo::new(espidf_version, args.profile_minimal, &targets);
|
||||
exports.extend(repo.install()?);
|
||||
extra_crates.insert(Crate::new("ldproxy"));
|
||||
if let Some(ref mut extra_crates) = extra_crates {
|
||||
extra_crates.insert(Crate::new("ldproxy"));
|
||||
} else {
|
||||
let mut crates = HashSet::new();
|
||||
crates.insert(Crate::new("ldproxy"));
|
||||
extra_crates = Some(crates);
|
||||
};
|
||||
} else {
|
||||
exports.extend(install_gcc_targets(&targets, &host_triple)?);
|
||||
}
|
||||
|
||||
debug!(
|
||||
"{} Installing the following crates: {:#?}",
|
||||
emoji::DEBUG,
|
||||
extra_crates
|
||||
);
|
||||
for extra_crate in &extra_crates {
|
||||
extra_crate.install()?;
|
||||
if let Some(ref extra_crates) = &extra_crates {
|
||||
install_extra_crates(extra_crates)?;
|
||||
}
|
||||
|
||||
if args.profile_minimal {
|
||||
@ -216,10 +219,12 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
let config = Config {
|
||||
espidf_version: args.espidf_version,
|
||||
export_file,
|
||||
extra_crates: extra_crates
|
||||
.iter()
|
||||
.map(|x| x.name.clone())
|
||||
.collect::<HashSet<String>>(),
|
||||
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,
|
||||
nightly_version: args.nightly_version,
|
||||
@ -274,8 +279,10 @@ fn uninstall(args: UninstallOpts) -> Result<()> {
|
||||
}
|
||||
|
||||
info!("{} Uninstalling extra crates", emoji::WRENCH);
|
||||
for extra_crate in &config.extra_crates {
|
||||
cmd!("cargo", "uninstall", extra_crate).run()?;
|
||||
if let Some(extra_crates) = &config.extra_crates {
|
||||
for extra_crate in extra_crates {
|
||||
cmd!("cargo", "uninstall", extra_crate).run()?;
|
||||
}
|
||||
}
|
||||
|
||||
clear_dist_folder()?;
|
||||
@ -340,7 +347,7 @@ fn update(args: UpdateOpts) -> Result<()> {
|
||||
|
||||
fn main() -> Result<()> {
|
||||
match Cli::parse().subcommand {
|
||||
SubCommand::Install(args) => install(args),
|
||||
SubCommand::Install(args) => install(*args),
|
||||
SubCommand::Update(args) => update(args),
|
||||
SubCommand::Uninstall(args) => uninstall(args),
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use log::{debug, info, warn};
|
||||
use regex::Regex;
|
||||
use reqwest::header;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
use std::{collections::HashSet, fmt::Debug};
|
||||
use std::{env, fs::remove_dir_all, path::PathBuf, process::Stdio};
|
||||
|
||||
/// Xtensa Rust Toolchain repository
|
||||
@ -226,8 +226,24 @@ impl Crate {
|
||||
name: name.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the extra crates to be installed.
|
||||
pub fn parse_crates(arg: &str) -> Result<HashSet<Crate>> {
|
||||
Ok(arg.split(',').map(Crate::new).collect())
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
fn get_artifact_extension(host_triple: &HostTriple) -> &str {
|
||||
match host_triple {
|
||||
@ -383,7 +399,8 @@ fn install_rust_nightly(version: &str) -> Result<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::toolchain::rust::XtensaRust;
|
||||
use crate::toolchain::rust::{Crate, XtensaRust};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
fn test_xtensa_rust_parse_version() {
|
||||
@ -395,4 +412,33 @@ mod tests {
|
||||
assert!(XtensaRust::parse_version("1..1.1").is_err());
|
||||
assert!(XtensaRust::parse_version("1._.*.1").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(unused_variables)]
|
||||
fn test_parse_crates() {
|
||||
let mut crates: HashSet<Crate> = HashSet::new();
|
||||
crates.insert(Crate::new("ldproxy"));
|
||||
assert!(matches!(Crate::parse_crates("ldproxy"), Ok(crates)));
|
||||
let mut crates: HashSet<Crate> = HashSet::new();
|
||||
crates.insert(Crate::new("ldproxy"));
|
||||
crates.insert(Crate::new("espflash"));
|
||||
assert!(matches!(
|
||||
Crate::parse_crates("ldproxy, espflash"),
|
||||
Ok(crates)
|
||||
));
|
||||
let mut crates: HashSet<Crate> = HashSet::new();
|
||||
crates.insert(Crate::new("cargo-generate"));
|
||||
crates.insert(Crate::new("sccache"));
|
||||
assert!(matches!(
|
||||
Crate::parse_crates("cargo-generate sccache"),
|
||||
Ok(crates)
|
||||
));
|
||||
let mut crates: HashSet<Crate> = HashSet::new();
|
||||
crates.insert(Crate::new("cargo-binstall"));
|
||||
crates.insert(Crate::new("espmonitor"));
|
||||
assert!(matches!(
|
||||
Crate::parse_crates("cargo-binstall,espmonitor"),
|
||||
Ok(crates)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user