1 //
2 //  Copyright 2023 Google, Inc.
3 //
4 //  Licensed under the Apache License, Version 2.0 (the "License");
5 //  you may not use this file except in compliance with the License.
6 //  You may obtain a copy of the License at:
7 //
8 //  http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //  Unless required by applicable law or agreed to in writing, software
11 //  distributed under the License is distributed on an "AS IS" BASIS,
12 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //  See the License for the specific language governing permissions and
14 //  limitations under the License.
15 
16 use std::env;
17 use std::fs::File;
18 use std::path::PathBuf;
19 use std::process::{Command, Stdio};
20 
main()21 fn main() {
22     generate_packets();
23 }
24 
generate_packets()25 fn generate_packets() {
26     let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
27     let out_file = File::create(out_dir.join("l2cap_packets.rs")).unwrap();
28     let in_file = PathBuf::from("l2cap_packets.pdl");
29 
30     // Expect pdlc to be in the PATH
31     println!("cargo:rerun-if-changed={}", in_file.display());
32     let output = Command::new("pdlc")
33         .arg("--output-format")
34         .arg("rust")
35         .arg(in_file)
36         .stdout(Stdio::from(out_file))
37         .output()
38         .unwrap();
39 
40     println!(
41         "Status: {}, stderr: {}",
42         output.status,
43         String::from_utf8_lossy(output.stderr.as_slice())
44     );
45 
46     let out_file = File::create(out_dir.join("hci_packets.rs")).unwrap();
47     let in_file = PathBuf::from("../../../tools/rootcanal/packets/hci_packets.pdl");
48 
49     println!("cargo:rerun-if-changed={}", in_file.display());
50     let output = Command::new("pdlc")
51         .arg("--output-format")
52         .arg("rust")
53         .arg(in_file)
54         .stdout(Stdio::from(out_file))
55         .output()
56         .unwrap();
57 
58     println!(
59         "Status: {}, stderr: {}",
60         output.status,
61         String::from_utf8_lossy(output.stderr.as_slice())
62     );
63 }
64