-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix prost proto packages not sanitizing to valid module names (#2044)
* Fix prost proto packages not sanitizing to lowercase * Add support for snake casing to match prost-build
- Loading branch information
1 parent
c080d7b
commit 6a7872a
Showing
8 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load("@rules_rust//rust:defs.bzl", "rust_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
rust_library( | ||
name = "heck", | ||
srcs = glob(["**/*.rs"]), | ||
crate_features = [ | ||
"default", | ||
], | ||
crate_root = "src/lib.rs", | ||
edition = "2018", | ||
rustc_flags = ["--cap-lints=allow"], | ||
tags = [ | ||
"manual", | ||
"noclippy", | ||
"norustfmt", | ||
], | ||
version = "0.4.1", | ||
) |
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
load("@rules_rust//rust:defs.bzl", "rust_test") | ||
load("//proto/prost:defs.bzl", "rust_prost_library") | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = [ | ||
"foo.proto", | ||
], | ||
strip_import_prefix = "/proto/prost/private/tests/sanitized_modules", | ||
) | ||
|
||
proto_library( | ||
name = "bar_proto", | ||
srcs = [ | ||
"bar.proto", | ||
], | ||
deps = [ | ||
"foo_proto", | ||
], | ||
) | ||
|
||
rust_prost_library( | ||
name = "bar_proto_rs", | ||
proto = ":bar_proto", | ||
) | ||
|
||
rust_test( | ||
name = "sanitized_modules_test", | ||
srcs = ["sanitized_modules_test.rs"], | ||
edition = "2021", | ||
deps = [":bar_proto_rs"], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
import "foo.proto"; | ||
|
||
package bAR.bAz.QAZ.QuX; | ||
|
||
message Bar { | ||
string name = 1; | ||
|
||
Foo.QuuX.CoRgE.GRAULT.gaRply.Foo foo = 2; | ||
|
||
Foo.QuuX.CoRgE.GRAULT.gaRply.Foo.NestedFoo nested_foo = 3; | ||
|
||
message Baz { | ||
string name = 4; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
package Foo.QuuX.CoRgE.GRAULT.gaRply; | ||
|
||
message Foo { | ||
string name = 1; | ||
|
||
message NestedFoo { | ||
string name = 2; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
proto/prost/private/tests/sanitized_modules/sanitized_modules_test.rs
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! Tests protos with various capitalizations in their package names are | ||
//! consumable in an expected way. | ||
|
||
use bar_proto::b_ar::b_az::qaz::qu_x::bar::Baz as BazMessage; | ||
use bar_proto::b_ar::b_az::qaz::qu_x::Bar as BarMessage; | ||
use foo_proto::foo::quu_x::co_rg_e::grault::ga_rply::foo::NestedFoo as NestedFooMessage; | ||
use foo_proto::foo::quu_x::co_rg_e::grault::ga_rply::Foo as FooMessage; | ||
|
||
#[test] | ||
fn test_packages() { | ||
let bar_message = BarMessage { | ||
name: "bar".to_string(), | ||
foo: Some(FooMessage { | ||
name: "foo".to_string(), | ||
}), | ||
nested_foo: Some(NestedFooMessage { | ||
name: "nested_foo".to_string(), | ||
}), | ||
}; | ||
let baz_message = BazMessage { | ||
name: "baz".to_string(), | ||
}; | ||
|
||
assert_eq!(bar_message.name, "bar"); | ||
assert_eq!(baz_message.name, "baz"); | ||
} |
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