Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75a9b66a authored by Martin Geisler's avatar Martin Geisler
Browse files

pdl: ensure we use ‘target/debug/pdl’ when running test with Cargo

The environment variable is documented here: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates.

Test: m bluetooth_packetgen && rm -f out/host/linux-x86/bin/pdl && cargo test
Change-Id: I4c9a6bee25dd6d54a812513e60eeadaf394cd92f
parent 08485ace
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -17,13 +17,18 @@ fn strip_blank_lines(text: &str) -> String {
///
/// # Panics
///
/// Panics if `pdl` cannot be found on `$PATH` or if it returns a
/// non-zero exit code.
/// Panics if `pdl` cannot be found or if it fails.
fn pdl(code: &str) -> String {
    let tempdir = tempfile::tempdir().unwrap();
    let input = tempdir.path().join("input.pdl");
    fs::write(&input, code.as_bytes()).unwrap();
    let pdl_path = find_binary("pdl").unwrap();

    // Cargo will set `CARGO_BIN_EXE_pdl` when compiling the crate. If
    // we're not using Cargo, we search for `pdl` using find_binary.
    let pdl_path = match std::option_env!("CARGO_BIN_EXE_pdl") {
        Some(pdl_path) => std::path::PathBuf::from(pdl_path),
        None => find_binary("pdl").unwrap(),
    };
    let output = Command::new(&pdl_path)
        .arg("--output-format")
        .arg("rust")