Skip to content

Commit

Permalink
Add minimum esp-idf-sys version requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
N3xed committed Jan 2, 2022
1 parent 5611ead commit 8d05531
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
11 changes: 6 additions & 5 deletions cargo-idf/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::PathBuf;
use std::process::{Command, Stdio};

use anyhow::anyhow;
use cargo_metadata::Message;
use cargo_metadata::{Message, Version};
use embuild::utils::CmdError;
use structopt::StructOpt;

Expand Down Expand Up @@ -38,7 +38,8 @@ pub struct BuildOpts {
pub struct BuildInfo {
/// The path of the built executable
pub bin_path: Option<PathBuf>,
pub esp_idf_build_info_json: PathBuf,
pub esp_idf_sys_out_dir: PathBuf,
pub esp_idf_sys_version: Version,
}

/// Run `cargo build` in the current directory.
Expand Down Expand Up @@ -123,13 +124,13 @@ pub fn run(opts: BuildOpts) -> Result<BuildInfo, BuildError> {
)
.map_err(BuildError::CargoBuildFailed)?;

let esp_idf_build_info_json = esp_idf_sys_out_dir
let esp_idf_sys_out_dir = esp_idf_sys_out_dir
.ok_or_else(|| BuildError::EspIdfSysNotFound(Some(anyhow!("Failed to get out dir"))))?
.join("esp-idf-build.json")
.into_std_path_buf();

Ok(BuildInfo {
bin_path: bin_path.map(Into::into),
esp_idf_build_info_json,
esp_idf_sys_out_dir,
esp_idf_sys_version: esp_idf_sys.version,
})
}
27 changes: 23 additions & 4 deletions cargo-idf/src/menuconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ use std::fs;
use std::path::PathBuf;

use anyhow::{anyhow, Context};
use embuild::espidf::EspIdfBuildInfo;
use cargo_metadata::Version;
use embuild::espidf::{self, EspIdfBuildInfo};
use embuild::utils::CmdError;
use embuild::{cmd, path_buf};
use structopt::StructOpt;

use crate::build::{self, BuildError};
use crate::build::{self, BuildError, BuildInfo};

const MIN_ESP_IDF_SYS_VERSION: Version = Version::new(0, 28, 3);

#[derive(Debug, thiserror::Error)]
#[error("Could not open menuconfig")]
#[error(transparent)]
pub enum MenuconfigError {
#[error("Build failed")]
Build(#[from] BuildError),
Cmd(#[from] CmdError),
Anyhow(#[from] anyhow::Error),
Io(#[from] std::io::Error),
Serde(#[from] serde_json::Error),
#[error(
"esp-idf-sys version ({0}) too old, version must be >= {}",
MIN_ESP_IDF_SYS_VERSION
)]
EspIdfSysTooOld(Version),
}

#[derive(StructOpt)]
Expand All @@ -37,7 +46,17 @@ pub fn run(opts: MenuconfigOpts) -> Result<(), MenuconfigError> {
let build_info_json = if let Some(path) = opts.idf_build_info {
path
} else {
build::run(opts.build_opts)?.esp_idf_build_info_json
let BuildInfo {
esp_idf_sys_out_dir,
esp_idf_sys_version,
..
} = build::run(opts.build_opts)?;

if esp_idf_sys_version < MIN_ESP_IDF_SYS_VERSION {
return Err(MenuconfigError::EspIdfSysTooOld(esp_idf_sys_version));
}

esp_idf_sys_out_dir.join(espidf::BUILD_INFO_FILENAME)
};

let EspIdfBuildInfo {
Expand Down

0 comments on commit 8d05531

Please sign in to comment.