Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: common crate name config #225

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading