mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-26 20:00:32 +00:00
Select example if none was specified (#4024)
This commit is contained in:
parent
60248d2c2f
commit
01a01ba99e
@ -10,7 +10,7 @@ clap = { version = "4.5.20", features = ["derive", "wrap_help"] }
|
||||
console = "0.15.10"
|
||||
env_logger = { version = "0.11.5", default-features = false, features = ["auto-color", "humantime"] }
|
||||
esp-metadata = { path = "../esp-metadata", features = ["clap"] }
|
||||
inquire = "0.7.5"
|
||||
inquire = "0.7.5"
|
||||
jiff = { version = "0.2.13", default-features = false, features = ["std"] }
|
||||
kuchikiki = { version = "0.8.2", optional = true }
|
||||
log = "0.4.22"
|
||||
|
@ -131,63 +131,21 @@ pub fn build_examples(
|
||||
// Determine the appropriate build target for the given package and chip:
|
||||
let target = args.package.target_triple(&chip)?;
|
||||
|
||||
if !args.example.eq_ignore_ascii_case("all") {
|
||||
// Attempt to build only the specified example:
|
||||
let mut filtered = examples
|
||||
.iter()
|
||||
.filter(|ex| ex.matches_name(&args.example))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if filtered.is_empty() {
|
||||
log::warn!(
|
||||
"Example '{}' not found or unsupported for the given chip. Please select one of the existing examples in the desired package.",
|
||||
args.example
|
||||
);
|
||||
|
||||
let example_idx = inquire::Select::new(
|
||||
"Select the example:",
|
||||
examples.iter().map(|ex| ex.binary_name()).collect(),
|
||||
)
|
||||
.prompt()?;
|
||||
|
||||
if let Some(selected) = examples.iter().find(|ex| ex.binary_name() == example_idx) {
|
||||
filtered.push(selected);
|
||||
}
|
||||
}
|
||||
|
||||
for example in filtered {
|
||||
crate::execute_app(
|
||||
package_path,
|
||||
chip,
|
||||
&target,
|
||||
example,
|
||||
CargoAction::Build(out_path.map(|p| p.to_path_buf())),
|
||||
1,
|
||||
args.debug,
|
||||
args.toolchain.as_deref(),
|
||||
args.timings,
|
||||
&[],
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
// Attempt to build each supported example, with all required features enabled:
|
||||
examples.iter().try_for_each(|example| {
|
||||
crate::execute_app(
|
||||
package_path,
|
||||
chip,
|
||||
&target,
|
||||
example,
|
||||
CargoAction::Build(out_path.map(|p| p.to_path_buf())),
|
||||
1,
|
||||
args.debug,
|
||||
args.toolchain.as_deref(),
|
||||
args.timings,
|
||||
&[],
|
||||
)
|
||||
})
|
||||
}
|
||||
// Attempt to build each supported example, with all required features enabled:
|
||||
examples.iter().try_for_each(|example| {
|
||||
crate::execute_app(
|
||||
package_path,
|
||||
chip,
|
||||
&target,
|
||||
example,
|
||||
CargoAction::Build(out_path.map(|p| p.to_path_buf())),
|
||||
1,
|
||||
args.debug,
|
||||
args.toolchain.as_deref(),
|
||||
args.timings,
|
||||
&[],
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_package(workspace: &Path, args: BuildPackageArgs) -> Result<()> {
|
||||
|
@ -19,7 +19,7 @@ mod run;
|
||||
#[derive(Debug, Args)]
|
||||
pub struct ExamplesArgs {
|
||||
/// Example to act on ("all" will execute every example).
|
||||
pub example: String,
|
||||
pub example: Option<String>,
|
||||
/// Chip to target.
|
||||
#[arg(value_enum, long)]
|
||||
pub chip: Option<Chip>,
|
||||
@ -126,18 +126,60 @@ pub fn examples(workspace: &Path, mut args: ExamplesArgs, action: CargoAction) -
|
||||
.filter(|example| example.supports_chip(chip))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// At this point, chip can never be `None`, so we can safely unwrap it.
|
||||
let chip = args.chip.unwrap();
|
||||
|
||||
// Filter the examples down to only the binaries supported by the given chip
|
||||
examples.retain(|ex| ex.supports_chip(chip));
|
||||
|
||||
// Sort all examples by name:
|
||||
examples.sort_by_key(|a| a.binary_name());
|
||||
|
||||
let mut filtered = examples.clone();
|
||||
|
||||
if let Some(example) = args.example.as_deref() {
|
||||
if !example.eq_ignore_ascii_case("all") {
|
||||
// Only keep the example the user wants
|
||||
filtered.retain(|ex| ex.matches_name(example));
|
||||
|
||||
if examples.is_empty() {
|
||||
log::warn!(
|
||||
"Example '{example}' not found or unsupported for the given chip. Please select one of the existing examples in the desired package."
|
||||
);
|
||||
|
||||
let example_name = inquire::Select::new(
|
||||
"Select the example:",
|
||||
examples.iter().map(|ex| ex.binary_name()).collect(),
|
||||
)
|
||||
.prompt()?;
|
||||
|
||||
if let Some(selected) = examples.iter().find(|ex| ex.binary_name() == example_name)
|
||||
{
|
||||
filtered.push(selected.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let example_name = inquire::Select::new(
|
||||
"Select an example:",
|
||||
examples.iter().map(|ex| ex.binary_name()).collect(),
|
||||
)
|
||||
.prompt()?;
|
||||
|
||||
if let Some(selected) = examples.iter().find(|ex| ex.binary_name() == example_name) {
|
||||
filtered.push(selected.clone());
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the specified action:
|
||||
match action {
|
||||
CargoAction::Build(out_path) => build_examples(
|
||||
args,
|
||||
examples,
|
||||
filtered,
|
||||
&package_path,
|
||||
out_path.as_ref().map(|p| p.as_path()),
|
||||
),
|
||||
CargoAction::Run => run_examples(args, examples, &package_path),
|
||||
CargoAction::Run => run_examples(args, filtered, &package_path),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,45 +134,8 @@ pub fn run_examples(
|
||||
|
||||
// At this point, chip can never be `None`, so we can safely unwrap it.
|
||||
let chip = args.chip.unwrap();
|
||||
|
||||
// Determine the appropriate build target for the given package and chip:
|
||||
let target = args.package.target_triple(&chip)?;
|
||||
|
||||
// Filter the examples down to only the binaries supported by the given chip
|
||||
examples.retain(|ex| ex.supports_chip(chip));
|
||||
|
||||
// Handle "all" examples and specific example
|
||||
if !args.example.eq_ignore_ascii_case("all") {
|
||||
let mut filtered = examples
|
||||
.iter()
|
||||
.filter(|ex| ex.matches_name(&args.example))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if filtered.is_empty() {
|
||||
log::warn!(
|
||||
"Example '{}' not found or unsupported for {}. Please select one of the existing examples in the desired package.",
|
||||
args.example,
|
||||
chip
|
||||
);
|
||||
|
||||
let example_idx = inquire::Select::new(
|
||||
"Select the example:",
|
||||
examples.iter().map(|ex| ex.binary_name()).collect(),
|
||||
)
|
||||
.prompt()?;
|
||||
|
||||
if let Some(selected) = examples
|
||||
.into_iter()
|
||||
.find(|ex| ex.binary_name() == example_idx)
|
||||
{
|
||||
filtered.push(selected);
|
||||
}
|
||||
}
|
||||
|
||||
examples = filtered;
|
||||
}
|
||||
|
||||
examples.sort_by_key(|ex| ex.tag());
|
||||
|
||||
let console = console::Term::stdout();
|
||||
|
@ -378,7 +378,7 @@ fn run_ci_checks(workspace: &Path, args: CiArgs) -> Result<()> {
|
||||
ExamplesArgs {
|
||||
package: Package::EspLpHal,
|
||||
chip: Some(args.chip),
|
||||
example: "all".to_string(),
|
||||
example: Some("all".to_string()),
|
||||
debug: false,
|
||||
toolchain: args.toolchain.clone(),
|
||||
timings: false,
|
||||
@ -461,7 +461,7 @@ fn run_ci_checks(workspace: &Path, args: CiArgs) -> Result<()> {
|
||||
ExamplesArgs {
|
||||
package: Package::Examples,
|
||||
chip: Some(args.chip),
|
||||
example: "all".to_string(),
|
||||
example: Some("all".to_string()),
|
||||
debug: true,
|
||||
toolchain: args.toolchain.clone(),
|
||||
timings: false,
|
||||
@ -479,7 +479,7 @@ fn run_ci_checks(workspace: &Path, args: CiArgs) -> Result<()> {
|
||||
ExamplesArgs {
|
||||
package: Package::QaTest,
|
||||
chip: Some(args.chip),
|
||||
example: "all".to_string(),
|
||||
example: Some("all".to_string()),
|
||||
debug: true,
|
||||
toolchain: args.toolchain.clone(),
|
||||
timings: false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user