mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 15:14:56 +00:00
feat: ✨ Add logs
This commit is contained in:
parent
ef7e3e6167
commit
eda2eb3a23
32
Cargo.lock
generated
32
Cargo.lock
generated
@ -348,6 +348,16 @@ dependencies = [
|
|||||||
"clap 2.34.0",
|
"clap 2.34.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap-verbosity-flag"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0636f9c040082f8e161555a305f8cec1a1c2828b3d981c812b8c39f4ac00c42c"
|
||||||
|
dependencies = [
|
||||||
|
"clap 3.2.22",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "3.2.18"
|
version = "3.2.18"
|
||||||
@ -652,6 +662,19 @@ dependencies = [
|
|||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"humantime",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
@ -680,13 +703,16 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"clap 3.2.22",
|
"clap 3.2.22",
|
||||||
"clap-nested",
|
"clap-nested",
|
||||||
|
"clap-verbosity-flag",
|
||||||
"console",
|
"console",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"env_logger",
|
||||||
"espflash",
|
"espflash",
|
||||||
"flate2",
|
"flate2",
|
||||||
"git2",
|
"git2",
|
||||||
"guess_host_triple",
|
"guess_host_triple",
|
||||||
"json",
|
"json",
|
||||||
|
"log",
|
||||||
"md5",
|
"md5",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
@ -1073,6 +1099,12 @@ version = "0.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
|
checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.13.10"
|
version = "0.13.10"
|
||||||
|
@ -27,6 +27,9 @@ xz2 = "0.1.6"
|
|||||||
espflash = "1.6.0"
|
espflash = "1.6.0"
|
||||||
console = "0.15.1"
|
console = "0.15.1"
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
|
clap-verbosity-flag = "1.0.1"
|
||||||
|
log = "0.4.17"
|
||||||
|
env_logger = "0.9.0"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winreg = "0.10.1"
|
winreg = "0.10.1"
|
||||||
|
19
src/main.rs
19
src/main.rs
@ -7,6 +7,8 @@ use std::io::Write;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
mod toolchain;
|
mod toolchain;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
use log::{info, warn};
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
// General TODOs:
|
// General TODOs:
|
||||||
@ -42,7 +44,7 @@ pub enum SubCommand {
|
|||||||
Reinstall(InstallOpts),
|
Reinstall(InstallOpts),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct InstallOpts {
|
pub struct InstallOpts {
|
||||||
/// Comma or space separated list of targets [esp32,esp32s2,esp32s3,esp32c3,all].
|
/// Comma or space separated list of targets [esp32,esp32s2,esp32s3,esp32c3,all].
|
||||||
#[clap(short = 'b', long, default_value = "esp32,esp32s2,esp32s3")]
|
#[clap(short = 'b', long, default_value = "esp32,esp32s2,esp32s3")]
|
||||||
@ -82,6 +84,9 @@ pub struct InstallOpts {
|
|||||||
/// Removes cached distribution files.
|
/// Removes cached distribution files.
|
||||||
#[clap(short = 'x', long)]
|
#[clap(short = 'x', long)]
|
||||||
pub clear_cache: bool,
|
pub clear_cache: bool,
|
||||||
|
/// Verbosity level of the logs.
|
||||||
|
#[clap(flatten)]
|
||||||
|
verbose: clap_verbosity_flag::Verbosity,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
@ -100,6 +105,10 @@ pub struct UninstallOpts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn install(args: InstallOpts) -> Result<()> {
|
fn install(args: InstallOpts) -> Result<()> {
|
||||||
|
env_logger::Builder::new()
|
||||||
|
.filter_level(args.verbose.log_level_filter())
|
||||||
|
.init();
|
||||||
|
|
||||||
let arch = guess_host_triple::guess_host_triple().unwrap();
|
let arch = guess_host_triple::guess_host_triple().unwrap();
|
||||||
let targets: Vec<Chip> = parse_targets(&args.build_target)?;
|
let targets: Vec<Chip> = parse_targets(&args.build_target)?;
|
||||||
let llvm_version = parse_llvm_version(&args.llvm_version).unwrap();
|
let llvm_version = parse_llvm_version(&args.llvm_version).unwrap();
|
||||||
@ -135,7 +144,7 @@ fn install(args: InstallOpts) -> Result<()> {
|
|||||||
arch
|
arch
|
||||||
);
|
);
|
||||||
let mut exports: Vec<String> = Vec::new();
|
let mut exports: Vec<String> = Vec::new();
|
||||||
|
info!("{} Installing esp-rs", DISC);
|
||||||
print_arguments(&args, arch, &targets, &llvm_version);
|
print_arguments(&args, arch, &targets, &llvm_version);
|
||||||
|
|
||||||
check_rust_installation(&args.nightly_version);
|
check_rust_installation(&args.nightly_version);
|
||||||
@ -270,17 +279,13 @@ fn install(args: InstallOpts) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
install_espidf(&espidf_targets, &espidf_version)?;
|
install_espidf(&espidf_targets, &espidf_version)?;
|
||||||
exports.push(format!(
|
exports.push(format!("export IDF_TOOLS_PATH=\"{}\"", get_tools_path()));
|
||||||
"export IDF_TOOLS_PATH=\"{}\"",
|
|
||||||
get_tools_path()
|
|
||||||
));
|
|
||||||
exports.push(format!(
|
exports.push(format!(
|
||||||
"source {}/export.sh",
|
"source {}/export.sh",
|
||||||
get_espidf_path(&espidf_version)
|
get_espidf_path(&espidf_version)
|
||||||
));
|
));
|
||||||
// TODO: Install ldproxy
|
// TODO: Install ldproxy
|
||||||
install_extra_crate("ldproxy");
|
install_extra_crate("ldproxy");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
println!("No esp-idf version provided. Installing gcc for targets");
|
println!("No esp-idf version provided. Installing gcc for targets");
|
||||||
exports.extend(install_gcc_targets(targets)?.iter().cloned());
|
exports.extend(install_gcc_targets(targets)?.iter().cloned());
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use crate::utils::*;
|
use crate::utils::*;
|
||||||
|
use anyhow::{bail, Result};
|
||||||
use espflash::Chip;
|
use espflash::Chip;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use anyhow::{bail, Result};
|
|
||||||
|
|
||||||
|
pub fn check_rust_installation(nightly_version: &str) -> Result<()> {
|
||||||
pub fn check_rust_installation(nightly_version: &str) {
|
|
||||||
match std::process::Command::new("rustup")
|
match std::process::Command::new("rustup")
|
||||||
.args(["toolchain", "list"])
|
.args(["toolchain", "list"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
@ -23,9 +22,10 @@ pub fn check_rust_installation(nightly_version: &str) {
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{}Error: {}", ERROR, e);
|
println!("{}Error: {}", ERROR, e);
|
||||||
install_rustup();
|
install_rustup()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_riscv_target(version: &str) {
|
pub fn install_riscv_target(version: &str) {
|
||||||
|
@ -8,6 +8,7 @@ use std::fs::File;
|
|||||||
use std::{fs, io};
|
use std::{fs, io};
|
||||||
// use anyhow::Context;
|
// use anyhow::Context;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
use std::io::{BufReader, Cursor};
|
use std::io::{BufReader, Cursor};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
@ -396,8 +397,9 @@ async fn fetch_url(url: String, output: String) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_arguments(args: &InstallOpts, arch: &str, targets: &Vec<Chip>, llvm_version: &str) {
|
pub fn print_arguments(args: &InstallOpts, arch: &str, targets: &Vec<Chip>, llvm_version: &str) {
|
||||||
println!(
|
debug!(
|
||||||
"{} Installing esp-rs for {} with:
|
"{} Arguments:
|
||||||
|
- Arch: {}
|
||||||
- Build targets: {:?}
|
- Build targets: {:?}
|
||||||
- Cargo home: {:?}
|
- Cargo home: {:?}
|
||||||
- Clear cache: {:?}
|
- Clear cache: {:?}
|
||||||
@ -410,7 +412,7 @@ pub fn print_arguments(args: &InstallOpts, arch: &str, targets: &Vec<Chip>, llvm
|
|||||||
- Rustup home: {:?}
|
- Rustup home: {:?}
|
||||||
- Toolchain version: {:?}
|
- Toolchain version: {:?}
|
||||||
- Toolchain destination: {:?}",
|
- Toolchain destination: {:?}",
|
||||||
DISC,
|
INFO,
|
||||||
arch,
|
arch,
|
||||||
targets,
|
targets,
|
||||||
&args.cargo_home,
|
&args.cargo_home,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user