Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always resolve package_id from metadata when finding bootloader and partition table #632

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed help text for size parameter of read-flash subcommand
- [cargo-espflash]: Always resolve package_id from metadata when finding bootloader and partition table (#632)

### Changed

Expand Down
24 changes: 20 additions & 4 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
process::{exit, Command, ExitStatus, Stdio},
};

use cargo_metadata::Message;
use cargo_metadata::{Message, MetadataCommand};
use clap::{Args, CommandFactory, Parser, Subcommand};
use espflash::{
cli::{
Expand Down Expand Up @@ -375,6 +375,12 @@ fn build(
.or_else(|| cargo_config.target())
.ok_or_else(|| NoTargetError::new(Some(chip)))?;

let mut metadata_cmd = MetadataCommand::new();
if let Some(features) = &build_options.features {
metadata_cmd.features(cargo_metadata::CargoOpt::SomeFeatures(features.clone()));
}
let metadata = metadata_cmd.exec().into_diagnostic()?;

if !chip.into_target().supports_build_target(target) {
return Err(UnsupportedTargetError::new(target, chip).into());
}
Expand Down Expand Up @@ -466,9 +472,19 @@ fn build(

for message in messages {
match message.into_diagnostic()? {
Message::BuildScriptExecuted(script)
if script.package_id.repr.starts_with("esp-idf-sys") =>
{
Message::BuildScriptExecuted(script) => {
// We can't use the `Index` implementation on `Metadata` because `-Zbuild-std`
// pulls in dependencies not listed in the metadata which then causes the `Index`
// implementation to panic.
let Some(package) = metadata.packages.iter().find(|p| p.id == script.package_id)
else {
continue;
};

if package.name != "esp-idf-sys" {
continue;
}

// If the `esp-idf-sys` package is being used, attempt to use the bootloader and
// partition table compiled by `embuild` instead.
let build_path = PathBuf::from(script.out_dir).join("build");
Expand Down
Loading