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

Commit 619f5fa9 authored by Martin Geisler's avatar Martin Geisler Committed by Gerrit Code Review
Browse files

Merge "PDL: Add a ‘Cargo.toml’ for speedy local development"

parents 134c14bf bf59972d
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -10,21 +10,23 @@ package {
rust_defaults {
    name: "pdl_defaults",
    srcs: ["src/main.rs"],
    // LINT.IfChange
    rustlibs: [
        "libanyhow",
        "libcodespan_reporting",
        "libpest",
        "libproc_macro2",
        "libquote",
        "libserde",
        "libserde_json",
        "libstructopt",
        "libcodespan_reporting",
        "libquote",
        "libsyn",
        "libproc_macro2",
        "libanyhow",
        "libtempfile",
    ],
    proc_macros: [
        "libpest_derive",
    ],
    // LINT.ThenChange(Cargo.toml)
}

rust_binary_host {

tools/pdl/Cargo.toml

0 → 100644
+19 −0
Original line number Diff line number Diff line
[package]
name = "pdl"
version = "0.1.0"
edition = "2021"

[workspace]

[dependencies]
anyhow = "*"
codespan-reporting = "*"
pest = "*"
pest_derive = "*"
proc-macro2 = "*"
quote = "*"
serde = { version = "*", features = ["default", "derive", "serde_derive", "std"] }
serde_json = "*"
structopt = "*"
syn = "*"
tempfile = "*"
+17 −2
Original line number Diff line number Diff line
@@ -6,6 +6,22 @@ use std::io::Write;
use std::process::{Command, Stdio};
use tempfile::NamedTempFile;

/// Search for a binary in `$PATH` or as a sibling to the current
/// executable (typically the test binary).
fn find_binary(name: &str) -> Option<std::path::PathBuf> {
    let mut current_exe = std::env::current_exe().unwrap();
    current_exe.pop();
    let paths = std::env::var_os("PATH").unwrap();
    for mut path in std::iter::once(current_exe).chain(std::env::split_paths(&paths)) {
        path.push(name);
        if path.exists() {
            return Some(path);
        }
    }

    None
}

/// Parse a string fragment as a PDL file.
///
/// # Panics
@@ -23,8 +39,7 @@ pub fn parse_str(text: &str) -> ast::Grammar {
/// Panics if `rustfmt` cannot be found in the same directory as the
/// test executable or if it returns a non-zero exit code.
pub fn rustfmt(input: &str) -> String {
    let mut rustfmt_path = std::env::current_exe().unwrap();
    rustfmt_path.set_file_name("rustfmt");
    let rustfmt_path = find_binary("rustfmt").expect("cannot find rustfmt");
    let mut rustfmt = Command::new(&rustfmt_path)
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())