-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamically read proto paths instead of hardcoding
- Loading branch information
Showing
4 changed files
with
62 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
use std::{path::PathBuf, process::Command}; | ||
use std::{fs, path::PathBuf, process::Command}; | ||
|
||
#[test] | ||
fn bootstrap() { | ||
let iface_files = &[ | ||
"proto/trace.proto", | ||
"proto/common.proto", | ||
"proto/tasks.proto", | ||
"proto/instrument.proto", | ||
"proto/resources.proto", | ||
"proto/async_ops.proto", | ||
]; | ||
let dirs = &["proto"]; | ||
let root_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")); | ||
let proto_dir = root_dir.join("proto"); | ||
let proto_files = fs::read_dir(&proto_dir).and_then(|dir| { | ||
dir.filter_map(|entry| { | ||
(|| { | ||
let entry = entry?; | ||
if entry.file_type()?.is_dir() { | ||
return Ok(None); | ||
} | ||
Ok(Some(entry.path())) | ||
})() | ||
.transpose() | ||
}) | ||
.collect::<Result<Vec<_>, _>>() | ||
}); | ||
let proto_files = match proto_files { | ||
Ok(files) => files, | ||
Err(error) => panic!("failed to list proto files: {}", error), | ||
}; | ||
|
||
let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) | ||
.join("src") | ||
.join("generated"); | ||
let out_dir = root_dir.join("src").join("generated"); | ||
|
||
tonic_build::configure() | ||
if let Err(error) = tonic_build::configure() | ||
.build_client(true) | ||
.build_server(true) | ||
.emit_rerun_if_changed(false) | ||
.protoc_arg("--experimental_allow_proto3_optional") | ||
.out_dir(format!("{}", out_dir.display())) | ||
.compile(iface_files, dirs) | ||
.unwrap(); | ||
.out_dir(&out_dir) | ||
.compile(&proto_files[..], &[proto_dir]) | ||
{ | ||
panic!("failed to compile `console-api` protobuf: {}", error); | ||
} | ||
|
||
let status = Command::new("git") | ||
.arg("diff") | ||
.arg("--exit-code") | ||
.arg("--") | ||
.arg(format!("{}", out_dir.display())) | ||
.status() | ||
.unwrap(); | ||
|
||
if !status.success() { | ||
panic!("You should commit the protobuf files"); | ||
.arg(out_dir) | ||
.status(); | ||
match status { | ||
Ok(status) if !status.success() => panic!("You should commit the protobuf files"), | ||
Err(error) => panic!("failed to run `git diff`: {}", error), | ||
Ok(_) => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters