Skip to content

Commit c2fc1ed

Browse files
authored
fix(volo-build): use absolute path for option (#552)
* fix(volo-build): use absolute path for option Signed-off-by: Millione <[email protected]> * fix clippy Signed-off-by: Millione <[email protected]> --------- Signed-off-by: Millione <[email protected]>
1 parent 7597872 commit c2fc1ed

File tree

17 files changed

+133
-114
lines changed

17 files changed

+133
-114
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

volo-build/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volo-build"
3-
version = "0.10.18"
3+
version = "0.10.19"
44
edition.workspace = true
55
homepage.workspace = true
66
repository.workspace = true

volo-build/src/thrift_backend.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl pilota_build::CodegenBackend for VoloThriftBackend {
474474
ty = format!("::std::sync::Arc<{ty}>");
475475
}
476476
if a.kind == rir::FieldKind::Optional{
477-
ty = format!("Option<{ty}>")
477+
ty = format!("::std::option::Option<{ty}>")
478478
};
479479
format!(", {name}: {ty}")
480480
}).join("");
@@ -757,7 +757,7 @@ impl pilota_build::CodegenBackend for VoloThriftBackend {
757757
let ty = self.inner.codegen_item_ty(a.ty.kind.clone());
758758
let ident = self.cx().rust_name(a.def_id); // use the rust name as string format which will escape the keyword
759759
let ty = if a.kind == rir::FieldKind::Optional {
760-
format!("Option<{ty}>")
760+
format!("::std::option::Option<{ty}>")
761761
} else {
762762
format!("{ty}")
763763
};

volo-build/src/util.rs

+54-54
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,60 @@ pub fn detect_protocol<P: AsRef<Path>>(path: P) -> IdlProtocol {
592592
}
593593
}
594594

595+
pub(crate) fn write_item(stream: &mut String, base_dir: &Path, name: String, impl_str: String) {
596+
let path_buf = base_dir.join(&name);
597+
let path = path_buf.as_path();
598+
write_file(path, impl_str);
599+
stream.push_str(format!("include!(\"{}\");", &name).as_str());
600+
}
601+
602+
pub(crate) fn write_file(path: &Path, stream: String) {
603+
let mut file_writer = std::io::BufWriter::new(std::fs::File::create(path).unwrap());
604+
file_writer.write_all(stream.as_bytes()).unwrap();
605+
file_writer.flush().unwrap();
606+
pilota_build::fmt::fmt_file(path);
607+
}
608+
609+
pub(crate) fn get_base_dir(mode: &Mode, def_id: Option<&usize>, path: &[Symbol]) -> PathBuf {
610+
// Locate directory based on the full item path
611+
let base_dir = match mode {
612+
// In a workspace mode, the base directory is next to the `.rs` file for the service
613+
Mode::Workspace(info) => {
614+
let mut dir = info.dir.clone();
615+
if path.is_empty() {
616+
dir
617+
} else {
618+
dir.push(path[0].0.as_str());
619+
if path.len() > 1 {
620+
dir.push("src");
621+
for segment in path.iter().skip(1) {
622+
dir.push(Path::new(segment.0.as_str()));
623+
}
624+
}
625+
dir
626+
}
627+
}
628+
// In single file mode, the files directory is the root
629+
// The base directory path is the root + the item path
630+
Mode::SingleFile { file_path } => {
631+
let mut dir = file_path.clone();
632+
dir.pop();
633+
for segment in path {
634+
dir.push(Path::new(segment.0.as_str()));
635+
}
636+
dir
637+
}
638+
};
639+
640+
let base_dir = if let Some(suffix) = def_id {
641+
format!("{}_{suffix}", base_dir.display())
642+
} else {
643+
base_dir.display().to_string()
644+
};
645+
let base_dir = Path::new(&base_dir);
646+
base_dir.to_path_buf()
647+
}
648+
595649
#[cfg(test)]
596650
mod tests {
597651
use std::fs;
@@ -859,57 +913,3 @@ mod tests {
859913
);
860914
}
861915
}
862-
863-
pub(crate) fn write_item(stream: &mut String, base_dir: &Path, name: String, impl_str: String) {
864-
let path_buf = base_dir.join(&name);
865-
let path = path_buf.as_path();
866-
write_file(path, impl_str);
867-
stream.push_str(format!("include!(\"{}\");", &name).as_str());
868-
}
869-
870-
pub(crate) fn write_file(path: &Path, stream: String) {
871-
let mut file_writer = std::io::BufWriter::new(std::fs::File::create(path).unwrap());
872-
file_writer.write_all(stream.as_bytes()).unwrap();
873-
file_writer.flush().unwrap();
874-
pilota_build::fmt::fmt_file(path);
875-
}
876-
877-
pub(crate) fn get_base_dir(mode: &Mode, def_id: Option<&usize>, path: &[Symbol]) -> PathBuf {
878-
// Locate directory based on the full item path
879-
let base_dir = match mode {
880-
// In a workspace mode, the base directory is next to the `.rs` file for the service
881-
Mode::Workspace(info) => {
882-
let mut dir = info.dir.clone();
883-
if path.is_empty() {
884-
dir
885-
} else {
886-
dir.push(path[0].0.as_str());
887-
if path.len() > 1 {
888-
dir.push("src");
889-
for segment in path.iter().skip(1) {
890-
dir.push(Path::new(segment.0.as_str()));
891-
}
892-
}
893-
dir
894-
}
895-
}
896-
// In single file mode, the files directory is the root
897-
// The base directory path is the root + the item path
898-
Mode::SingleFile { file_path } => {
899-
let mut dir = file_path.clone();
900-
dir.pop();
901-
for segment in path {
902-
dir.push(Path::new(segment.0.as_str()));
903-
}
904-
dir
905-
}
906-
};
907-
908-
let base_dir = if let Some(suffix) = def_id {
909-
format!("{}_{suffix}", base_dir.display())
910-
} else {
911-
base_dir.display().to_string()
912-
};
913-
let base_dir = Path::new(&base_dir);
914-
base_dir.to_path_buf()
915-
}

volo-grpc/src/codec/compression.rs

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl CompressionEncoding {
137137
}
138138

139139
/// Get the value of `grpc-encoding` header. Returns an error if the encoding isn't supported.
140+
#[allow(clippy::result_large_err)]
140141
pub fn from_encoding_header(
141142
headers: &http::HeaderMap,
142143
config: &Option<Vec<Self>>,

volo-grpc/src/codec/decode.rs

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl<T: Message + Default> RecvStream<T> {
116116
}
117117
}
118118

119+
#[allow(clippy::result_large_err)]
119120
fn decode_chunk(&mut self) -> Result<Option<T>, Status> {
120121
if let State::Header = self.state {
121122
// data is not enough to decode header, return and keep reading

volo-grpc/src/message.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub trait SendEntryMessage {
1313
) -> crate::BoxStream<'static, Result<Frame<Bytes>, crate::Status>>;
1414
}
1515

16+
#[allow(clippy::result_large_err)]
1617
pub trait RecvEntryMessage: Sized {
1718
fn from_body(
1819
method: Option<&str>,

volo-grpc/src/metadata/value.rs

+51-51
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ macro_rules! from_integers {
452452
let val = AsciiMetadataValue::from(n);
453453
assert_eq!(val, &n.to_string());
454454

455-
let n = ::std::$t::MAX;
455+
let n = $t::MAX;
456456
let val = AsciiMetadataValue::from(n);
457457
assert_eq!(val, &n.to_string());
458458
}
@@ -771,86 +771,86 @@ fn test_from_shared_base64_encodes() {
771771

772772
#[test]
773773
fn test_value_eq_value() {
774-
type BMV = BinaryMetadataValue;
775-
type AMV = AsciiMetadataValue;
774+
type Bmv = BinaryMetadataValue;
775+
type Amv = AsciiMetadataValue;
776776

777-
assert_eq!(AMV::from_static("abc"), AMV::from_static("abc"));
778-
assert_ne!(AMV::from_static("abc"), AMV::from_static("ABC"));
777+
assert_eq!(Amv::from_static("abc"), Amv::from_static("abc"));
778+
assert_ne!(Amv::from_static("abc"), Amv::from_static("ABC"));
779779

780-
assert_eq!(BMV::from_bytes(b"abc"), BMV::from_bytes(b"abc"));
781-
assert_ne!(BMV::from_bytes(b"abc"), BMV::from_bytes(b"ABC"));
780+
assert_eq!(Bmv::from_bytes(b"abc"), Bmv::from_bytes(b"abc"));
781+
assert_ne!(Bmv::from_bytes(b"abc"), Bmv::from_bytes(b"ABC"));
782782

783783
// Padding is ignored.
784784
assert_eq!(
785-
BMV::from_static("SGVsbG8hIQ=="),
786-
BMV::from_static("SGVsbG8hIQ")
785+
Bmv::from_static("SGVsbG8hIQ=="),
786+
Bmv::from_static("SGVsbG8hIQ")
787787
);
788788
// Invalid values are all just invalid from this point of view.
789789
// SAFETY: metadata value is valid here
790790
unsafe {
791791
assert_eq!(
792-
BMV::from_shared_unchecked(Bytes::from_static(b"..{}")),
793-
BMV::from_shared_unchecked(Bytes::from_static(b"{}.."))
792+
Bmv::from_shared_unchecked(Bytes::from_static(b"..{}")),
793+
Bmv::from_shared_unchecked(Bytes::from_static(b"{}.."))
794794
);
795795
}
796796
}
797797

798798
#[test]
799799
fn test_value_eq_str() {
800-
type BMV = BinaryMetadataValue;
801-
type AMV = AsciiMetadataValue;
800+
type Bmv = BinaryMetadataValue;
801+
type Amv = AsciiMetadataValue;
802802

803-
assert_eq!(AMV::from_static("abc"), "abc");
804-
assert_ne!(AMV::from_static("abc"), "ABC");
805-
assert_eq!("abc", AMV::from_static("abc"));
806-
assert_ne!("ABC", AMV::from_static("abc"));
803+
assert_eq!(Amv::from_static("abc"), "abc");
804+
assert_ne!(Amv::from_static("abc"), "ABC");
805+
assert_eq!("abc", Amv::from_static("abc"));
806+
assert_ne!("ABC", Amv::from_static("abc"));
807807

808-
assert_eq!(BMV::from_bytes(b"abc"), "abc");
809-
assert_ne!(BMV::from_bytes(b"abc"), "ABC");
810-
assert_eq!("abc", BMV::from_bytes(b"abc"));
811-
assert_ne!("ABC", BMV::from_bytes(b"abc"));
808+
assert_eq!(Bmv::from_bytes(b"abc"), "abc");
809+
assert_ne!(Bmv::from_bytes(b"abc"), "ABC");
810+
assert_eq!("abc", Bmv::from_bytes(b"abc"));
811+
assert_ne!("ABC", Bmv::from_bytes(b"abc"));
812812

813813
// Padding is ignored.
814-
assert_eq!(BMV::from_static("SGVsbG8hIQ=="), "Hello!!");
815-
assert_eq!("Hello!!", BMV::from_static("SGVsbG8hIQ=="));
814+
assert_eq!(Bmv::from_static("SGVsbG8hIQ=="), "Hello!!");
815+
assert_eq!("Hello!!", Bmv::from_static("SGVsbG8hIQ=="));
816816
}
817817

818818
#[test]
819819
fn test_value_eq_bytes() {
820-
type BMV = BinaryMetadataValue;
821-
type AMV = AsciiMetadataValue;
820+
type Bmv = BinaryMetadataValue;
821+
type Amv = AsciiMetadataValue;
822822

823-
assert_eq!(AMV::from_static("abc"), "abc".as_bytes());
824-
assert_ne!(AMV::from_static("abc"), "ABC".as_bytes());
825-
assert_eq!(*"abc".as_bytes(), AMV::from_static("abc"));
826-
assert_ne!(*"ABC".as_bytes(), AMV::from_static("abc"));
823+
assert_eq!(Amv::from_static("abc"), "abc".as_bytes());
824+
assert_ne!(Amv::from_static("abc"), "ABC".as_bytes());
825+
assert_eq!(*"abc".as_bytes(), Amv::from_static("abc"));
826+
assert_ne!(*"ABC".as_bytes(), Amv::from_static("abc"));
827827

828-
assert_eq!(*"abc".as_bytes(), BMV::from_bytes(b"abc"));
829-
assert_ne!(*"ABC".as_bytes(), BMV::from_bytes(b"abc"));
828+
assert_eq!(*"abc".as_bytes(), Bmv::from_bytes(b"abc"));
829+
assert_ne!(*"ABC".as_bytes(), Bmv::from_bytes(b"abc"));
830830

831831
// Padding is ignored.
832-
assert_eq!(BMV::from_static("SGVsbG8hIQ=="), "Hello!!".as_bytes());
833-
assert_eq!(*"Hello!!".as_bytes(), BMV::from_static("SGVsbG8hIQ=="));
832+
assert_eq!(Bmv::from_static("SGVsbG8hIQ=="), "Hello!!".as_bytes());
833+
assert_eq!(*"Hello!!".as_bytes(), Bmv::from_static("SGVsbG8hIQ=="));
834834
}
835835

836836
#[test]
837837
fn test_ascii_value_hash() {
838838
use std::collections::hash_map::DefaultHasher;
839-
type AMV = AsciiMetadataValue;
839+
type Amv = AsciiMetadataValue;
840840

841-
fn hash(value: AMV) -> u64 {
841+
fn hash(value: Amv) -> u64 {
842842
let mut hasher = DefaultHasher::new();
843843
value.hash(&mut hasher);
844844
hasher.finish()
845845
}
846846

847-
let value1 = AMV::from_static("abc");
848-
let value2 = AMV::from_static("abc");
847+
let value1 = Amv::from_static("abc");
848+
let value2 = Amv::from_static("abc");
849849
assert_eq!(value1, value2);
850850
assert_eq!(hash(value1), hash(value2));
851851

852-
let value1 = AMV::from_static("abc");
853-
let value2 = AMV::from_static("xyz");
852+
let value1 = Amv::from_static("abc");
853+
let value2 = Amv::from_static("xyz");
854854

855855
assert_ne!(value1, value2);
856856
assert_ne!(hash(value1), hash(value2));
@@ -859,48 +859,48 @@ fn test_ascii_value_hash() {
859859
#[test]
860860
fn test_valid_binary_value_hash() {
861861
use std::collections::hash_map::DefaultHasher;
862-
type BMV = BinaryMetadataValue;
862+
type Bmv = BinaryMetadataValue;
863863

864-
fn hash(value: BMV) -> u64 {
864+
fn hash(value: Bmv) -> u64 {
865865
let mut hasher = DefaultHasher::new();
866866
value.hash(&mut hasher);
867867
hasher.finish()
868868
}
869869

870-
let value1 = BMV::from_bytes(b"abc");
871-
let value2 = BMV::from_bytes(b"abc");
870+
let value1 = Bmv::from_bytes(b"abc");
871+
let value2 = Bmv::from_bytes(b"abc");
872872
assert_eq!(value1, value2);
873873
assert_eq!(hash(value1), hash(value2));
874874

875-
let value1 = BMV::from_bytes(b"abc");
876-
let value2 = BMV::from_bytes(b"xyz");
875+
let value1 = Bmv::from_bytes(b"abc");
876+
let value2 = Bmv::from_bytes(b"xyz");
877877
assert_ne!(value1, value2);
878878
assert_ne!(hash(value1), hash(value2));
879879
}
880880

881881
#[test]
882882
fn test_invalid_binary_value_hash() {
883883
use std::collections::hash_map::DefaultHasher;
884-
type BMV = BinaryMetadataValue;
884+
type Bmv = BinaryMetadataValue;
885885

886-
fn hash(value: BMV) -> u64 {
886+
fn hash(value: Bmv) -> u64 {
887887
let mut hasher = DefaultHasher::new();
888888
value.hash(&mut hasher);
889889
hasher.finish()
890890
}
891891

892892
// SAFETY: metadata value is valid here
893893
unsafe {
894-
let value1 = BMV::from_shared_unchecked(Bytes::from_static(b"..{}"));
895-
let value2 = BMV::from_shared_unchecked(Bytes::from_static(b"{}.."));
894+
let value1 = Bmv::from_shared_unchecked(Bytes::from_static(b"..{}"));
895+
let value2 = Bmv::from_shared_unchecked(Bytes::from_static(b"{}.."));
896896
assert_eq!(value1, value2);
897897
assert_eq!(hash(value1), hash(value2));
898898
}
899899

900900
// SAFETY: metadata value is valid here
901901
unsafe {
902-
let valid = BMV::from_bytes(b"abc");
903-
let invalid = BMV::from_shared_unchecked(Bytes::from_static(b"{}.."));
902+
let valid = Bmv::from_bytes(b"abc");
903+
let invalid = Bmv::from_shared_unchecked(Bytes::from_static(b"{}.."));
904904
assert_ne!(valid, invalid);
905905
assert_ne!(hash(valid), hash(invalid));
906906
}

volo-grpc/src/status.rs

+3
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ impl Status {
482482
}
483483

484484
/// Take the `Status` value from `trailers' if it is available, else from 'status_code'.
485+
#[allow(clippy::result_large_err)]
485486
pub fn infer_grpc_status(
486487
trailers: Option<&HeaderMap>,
487488
status_code: http::StatusCode,
@@ -548,13 +549,15 @@ impl Status {
548549
}
549550

550551
/// Convert to HeaderMap
552+
#[allow(clippy::result_large_err)]
551553
pub fn to_header_map(&self) -> Result<HeaderMap, Self> {
552554
let mut header_map = HeaderMap::with_capacity(3 + self.metadata.len());
553555
self.add_header(&mut header_map)?;
554556
Ok(header_map)
555557
}
556558

557559
/// Insert the associated code, message, and binary details field into the `HeaderMap`.
560+
#[allow(clippy::result_large_err)]
558561
pub(crate) fn add_header(&self, header_map: &mut HeaderMap) -> Result<(), Self> {
559562
header_map.extend(self.metadata.clone().into_sanitized_headers());
560563

0 commit comments

Comments
 (0)