1 //
2 // Copyright 2021 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::path::PathBuf;
18 use std::process::Command;
19
main()20 fn main() {
21 let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
22
23 let gd_root = match env::var("PLATFORM_SUBDIR") {
24 Ok(dir) => PathBuf::from(dir).join("bt/gd"),
25 // Currently at //platform2/gd/rust/rust/packets
26 Err(_) => PathBuf::from(env::current_dir().unwrap()).join("../..").canonicalize().unwrap(),
27 };
28
29 let input_files = [gd_root.join("hci/hci_packets.pdl")];
30 let outputted = [out_dir.join("../../hci/hci_packets.rs")];
31
32 // Find the packetgen tool. Expecting it at CARGO_HOME/bin
33 let packetgen =
34 PathBuf::from(env::var("CARGO_HOME").unwrap()).join("bin").join("bluetooth_packetgen");
35
36 for i in 0..input_files.len() {
37 let output = Command::new(packetgen.as_os_str().to_str().unwrap())
38 .arg("--source_root=".to_owned() + gd_root.as_os_str().to_str().unwrap())
39 .arg("--out=".to_owned() + out_dir.as_os_str().to_str().unwrap())
40 .arg("--include=bt/gd")
41 .arg("--rust")
42 .arg(input_files[i].as_os_str().to_str().unwrap())
43 .output()
44 .unwrap();
45
46 println!(
47 "Status: {}, stdout: {}, stderr: {}",
48 output.status,
49 String::from_utf8_lossy(output.stdout.as_slice()),
50 String::from_utf8_lossy(output.stderr.as_slice())
51 );
52
53 // File will be at ${OUT_DIR}/../../${input_files[i].strip('.pdl')}.rs
54 std::fs::rename(
55 outputted[i].as_os_str().to_str().unwrap(),
56 out_dir.join(outputted[i].file_name().unwrap()).as_os_str().to_str().unwrap(),
57 )
58 .unwrap();
59 }
60 }
61