Skip to content

Commit 3b181a3

Browse files
authored
Always show example description before compiling it (#3622)
1 parent 61aa33b commit 3b181a3

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

examples/src/bin/lp_core_basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Code on LP core increments a counter and continuously toggles LED. The
44
//! current value is printed by the HP core.
55
//!
6-
//! Make sure to first compile the `esp-lp-hal/examples/blinky.rs` example
6+
//! ⚠️ Make sure to first compile the `esp-lp-hal/examples/blinky.rs` example ⚠️
77
//!
88
//! The following wiring is assumed:
99
//! - LED => GPIO1

xtask/src/commands/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub fn examples(workspace: &Path, mut args: ExamplesArgs, action: CargoAction) -
8585
// Execute the specified action:
8686
match action {
8787
CargoAction::Build(out_path) => build_examples(args, examples, &package_path, &out_path),
88-
CargoAction::Run if args.example.is_some() => run_example(args, examples, &package_path),
8988
CargoAction::Run => run_examples(args, examples, &package_path),
9089
}
9190
}

xtask/src/commands/run.rs

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
process::Command,
55
};
66

7-
use anyhow::{bail, ensure, Context as _, Result};
7+
use anyhow::{Context as _, Result, bail, ensure};
88
use clap::{Args, Subcommand};
99
use esp_metadata::Chip;
1010

@@ -117,49 +117,33 @@ pub fn run_elfs(args: RunElfsArgs) -> Result<()> {
117117
Ok(())
118118
}
119119

120-
pub fn run_example(args: ExamplesArgs, examples: Vec<Metadata>, package_path: &Path) -> Result<()> {
121-
// Determine the appropriate build target for the given package and chip:
122-
let target = args.package.target_triple(&args.chip)?;
123-
124-
// Filter the examples down to only the binary we're interested in, assuming it
125-
// actually supports the specified chip:
126-
let mut found_one = false;
127-
for example in examples.iter().filter(|ex| ex.matches(&args.example)) {
128-
found_one = true;
129-
crate::execute_app(
130-
package_path,
131-
args.chip,
132-
target,
133-
example,
134-
CargoAction::Run,
135-
1,
136-
args.debug,
137-
)?;
138-
}
139-
140-
ensure!(
141-
found_one,
142-
"Example not found or unsupported for {}",
143-
args.chip
144-
);
145-
146-
Ok(())
147-
}
148-
149120
pub fn run_examples(
150121
args: ExamplesArgs,
151122
examples: Vec<Metadata>,
152123
package_path: &Path,
153124
) -> Result<()> {
125+
let mut examples = examples;
126+
154127
// Determine the appropriate build target for the given package and chip:
155128
let target = args.package.target_triple(&args.chip)?;
156129

157-
// Filter the examples down to only the binaries we're interested in
158-
let mut examples: Vec<Metadata> = examples
159-
.iter()
160-
.filter(|ex| ex.supports_chip(args.chip))
161-
.cloned()
162-
.collect();
130+
let single_example = args.example.is_some();
131+
132+
// Filter the examples down to only the binaries supported by the given chip
133+
examples.retain(|ex| ex.supports_chip(args.chip));
134+
135+
// User requested to run exactly one example
136+
if single_example {
137+
// Filter the examples down to only the binary we're interested in
138+
examples.retain(|ex| ex.matches(&args.example));
139+
140+
ensure!(
141+
examples.len() == 1,
142+
"Example not found or unsupported for {}",
143+
args.chip
144+
);
145+
}
146+
163147
examples.sort_by_key(|ex| ex.tag());
164148

165149
let console = console::Term::stdout();

0 commit comments

Comments
 (0)