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

Commit a9b3e718 authored by Henri Chataing's avatar Henri Chataing
Browse files

Update to pdl-compiler 0.2.2

Bug: 306901204
Test: m root-canal
Change-Id: I7db58e6b0304e0aa2ba962c7188fb0aae5c618cf
parent e344aa47
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -603,7 +603,7 @@ rust_library {
    rustlibs: [
        "libbytes",
        "liblog_rust",
        "libnum_traits",
        "libpdl_runtime",
        "libthiserror",
    ],
    apex_available: [
@@ -629,7 +629,7 @@ rust_test_host {
    rustlibs: [
        "libbytes",
        "liblog_rust",
        "libnum_traits",
        "libpdl_runtime",
        "libthiserror",
    ],
}
+4 −1
Original line number Diff line number Diff line
@@ -20,14 +20,17 @@ edition = "2018"
build = "build.rs"

[dependencies]

bindgen = "0.64"
bytes = "1.0"
num-derive = "0.3"
num-traits = "0.2"
pdl-runtime = "0.2.2"
thiserror = "1.0"
walkdir = "2.2"

[build-dependencies]
pdl-compiler = "0.2.2"

[lib]
path = "lib.rs"
crate-types = ["rlib"]
+27 −34
Original line number Diff line number Diff line
@@ -13,57 +13,50 @@
//  See the License for the specific language governing permissions and
//  limitations under the License.

use pdl_compiler;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

fn main() {
    let pdl_root = match env::var("PLATFORM_SUBDIR") {
        Ok(dir) => PathBuf::from(dir).join("bt/pdl"),
        // Currently at //platform2/gd/rust/rust/packets
        Err(_) => {
            PathBuf::from(env::current_dir().unwrap()).join("../../../pdl").canonicalize().unwrap()
        }
    };

    let in_file = pdl_root.join("hci/hci_packets.pdl");
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let out_file = out_dir.join("hci_packets.rs");

    let packets_prebuilt = match env::var("HCI_PACKETS_PREBUILT") {
        Ok(dir) => PathBuf::from(dir),
        Err(_) => PathBuf::from("hci_packets.rs"),
    };

    if Path::new(packets_prebuilt.as_os_str()).exists() {
        let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
        let out_file = out_dir.join("hci_packets.rs");
        std::fs::copy(
            packets_prebuilt.as_os_str().to_str().unwrap(),
            out_file.as_os_str().to_str().unwrap(),
        )
        .unwrap();
    } else {
        generate_packets();
    }
}
        let mut sources = pdl_compiler::ast::SourceDatabase::new();
        let file = pdl_compiler::parser::parse_file(
            &mut sources,
            &in_file.into_os_string().into_string().unwrap(),
        )
        .expect("failed to parse input pdl file");
        let file =
            pdl_compiler::analyzer::analyze(&file).expect("failed to validate input pdl file");
        let generated = pdl_compiler::backends::rust::generate(&sources, &file);

fn generate_packets() {
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
        let mut f = File::create(out_file).unwrap();
        f.write_all(generated.as_bytes()).unwrap();

    let pdl_root = match env::var("PLATFORM_SUBDIR") {
        Ok(dir) => PathBuf::from(dir).join("bt/pdl"),
        // Currently at //platform2/gd/rust/rust/packets
        Err(_) => {
            PathBuf::from(env::current_dir().unwrap()).join("../../../pdl").canonicalize().unwrap()
        println!("cargo:rerun-if-changed=build.rs");
    }
    };

    let in_file = pdl_root.join("hci/hci_packets.pdl");
    let out_file = File::create(out_dir.join("hci_packets.rs")).unwrap();

    // Expect pdlc to be in the PATH
    println!("cargo:rerun-if-changed={}", in_file.display());
    let output = Command::new("pdlc")
        .arg("--output-format")
        .arg("rust")
        .arg(in_file)
        .stdout(Stdio::from(out_file))
        .output()
        .unwrap();

    println!(
        "Status: {}, stderr: {}",
        output.status,
        String::from_utf8_lossy(output.stderr.as_slice())
    );
}
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ log = "0.4"
nix = "0.23"
num-derive = "0.3"
num-traits = "0.2"
pdl-runtime = "0.2.2"
paste = "1.0"
proc-macro2 = "1.0.24"
protobuf = "2.0"
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ rust_library {
        "liblazy_static",
        "liblog_rust",
        "libnum_traits",
        "libpdl_runtime",
        "libprotobuf_deprecated",
        "libthiserror",
        "libtokio",
@@ -72,6 +73,7 @@ rust_test_host {
        "liblazy_static",
        "liblog_rust",
        "libnum_traits",
        "libpdl_runtime",
        "libprotobuf_deprecated",
        "libthiserror",
        "libtokio",
Loading