Skip to content

Commit

Permalink
feat: common crate name config (#225)
Browse files Browse the repository at this point in the history
* feat: common crate name config
  • Loading branch information
junhaideng authored Feb 20, 2024
1 parent 47b5e23 commit 497c221
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions pilota-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct Builder<MkB, P> {
keep_unknown_fields: Vec<std::path::PathBuf>,
dedups: Vec<FastStr>,
nonstandard_snake_case: bool,
common_crate_name: FastStr,
}

impl Builder<MkThriftBackend, ThriftParser> {
Expand All @@ -105,6 +106,7 @@ impl Builder<MkThriftBackend, ThriftParser> {
keep_unknown_fields: Vec::default(),
dedups: Vec::default(),
nonstandard_snake_case: false,
common_crate_name: "common".into(),
}
}
}
Expand All @@ -126,6 +128,7 @@ impl Builder<MkProtobufBackend, ProtobufParser> {
keep_unknown_fields: Vec::default(),
dedups: Vec::default(),
nonstandard_snake_case: false,
common_crate_name: "common".into(),
}
}
}
Expand All @@ -144,6 +147,11 @@ where
self.nonstandard_snake_case = flag;
self
}

pub fn common_crate_name(mut self, name: FastStr) -> Self {
self.common_crate_name = name;
self
}
}

impl<MkB, P> Builder<MkB, P> {
Expand All @@ -159,6 +167,7 @@ impl<MkB, P> Builder<MkB, P> {
keep_unknown_fields: self.keep_unknown_fields,
dedups: self.dedups,
nonstandard_snake_case: self.nonstandard_snake_case,
common_crate_name: self.common_crate_name,
}
}

Expand Down Expand Up @@ -262,6 +271,7 @@ where
keep_unknown_fields: Vec<PathBuf>,
dedups: Vec<FastStr>,
nonstandard_snake_case: bool,
common_crate_name: FastStr,
) -> Context {
let mut db = RootDatabase::default();
parser.inputs(services.iter().map(|s| &s.path));
Expand Down Expand Up @@ -336,6 +346,7 @@ where
change_case,
dedups,
nonstandard_snake_case,
common_crate_name,
)
}

Expand All @@ -353,6 +364,7 @@ where
self.keep_unknown_fields,
self.dedups,
self.nonstandard_snake_case,
self.common_crate_name,
);

cx.exec_plugin(BoxedPlugin);
Expand Down Expand Up @@ -434,6 +446,7 @@ where
self.keep_unknown_fields,
self.dedups,
self.nonstandard_snake_case,
self.common_crate_name,
);

std::thread::scope(|_scope| {
Expand Down
6 changes: 5 additions & 1 deletion pilota-build/src/middle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct Context {
pub plugin_gen: DashMap<DefLocation, String>,
pub(crate) dedups: Vec<FastStr>,
pub(crate) nonstandard_snake_case: bool,
pub(crate) common_crate_name: FastStr,
}

impl Clone for Context {
Expand All @@ -89,6 +90,7 @@ impl Clone for Context {
plugin_gen: self.plugin_gen.clone(),
dedups: self.dedups.clone(),
nonstandard_snake_case: self.nonstandard_snake_case,
common_crate_name: self.common_crate_name.clone(),
}
}
}
Expand Down Expand Up @@ -426,6 +428,7 @@ impl ContextBuilder {
change_case: bool,
dedups: Vec<FastStr>,
nonstandard_snake_case: bool,
common_crate_name: FastStr,
) -> Context {
Context {
adjusts: Default::default(),
Expand All @@ -445,6 +448,7 @@ impl ContextBuilder {
plugin_gen: Default::default(),
dedups,
nonstandard_snake_case,
common_crate_name,
}
}
}
Expand Down Expand Up @@ -956,7 +960,7 @@ impl Context {
.into()
})
}
DefLocation::Dynamic => "common".into(),
DefLocation::Dynamic => self.common_crate_name.clone(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/middle/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl PathResolver for WorkspacePathResolver {
path.extend(prefix.iter().cloned());
path
}
super::context::DefLocation::Dynamic => ["common".into()]
super::context::DefLocation::Dynamic => [cx.common_crate_name.clone().into()]
.iter()
.chain(DefaultPathResolver.mod_prefix(cx, def_id).iter())
.cloned()
Expand Down

0 comments on commit 497c221

Please sign in to comment.