crosvm/metrics/build.rs
Dennis Kempin 4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00

55 lines
1.6 KiB
Rust

// Copyright 2022 The ChromiumOS Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::env;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use protoc_rust::Codegen;
use protoc_rust::Customize;
fn main() {
build_protos();
}
// TODO(mikehoyle): Unify all proto-building logic across crates into a common build dependency.
fn build_protos() {
let proto_files = vec!["protos/event_details.proto"];
let out_dir = format!(
"{}/metrics_protos",
env::var("OUT_DIR").expect("OUT_DIR env does not exist.")
);
fs::create_dir_all(&out_dir).unwrap();
Codegen::new()
.out_dir(&out_dir)
.inputs(&proto_files)
.customize(Customize {
serde_derive: Some(true),
..Default::default()
})
.run()
.unwrap();
create_gen_file(proto_files, &out_dir);
}
fn create_gen_file(proto_files: Vec<&str>, out_dir: &str) {
let generated = PathBuf::from(&out_dir).join("generated.rs");
let out = File::create(generated).expect("Failed to create generated file.");
for proto in proto_files {
let file_stem = PathBuf::from(proto)
.file_stem()
.unwrap()
.to_str()
.unwrap()
.to_owned();
let out_dir = out_dir.replace("\\", "/");
writeln!(&out, "#[path = \"{}/{}.rs\"]", out_dir, file_stem)
.expect("failed to write to generated.");
writeln!(&out, "pub mod {}_proto;", file_stem).expect("failed to write to generated.");
}
}