Skip to content

Commit

Permalink
feat(volo-build): support touch and keep_unknown_fields configuration…
Browse files Browse the repository at this point in the history
… in workspace mode (#491)
  • Loading branch information
Millione authored Aug 26, 2024
1 parent 7af01d6 commit 27bb5b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion volo-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volo-build"
version = "0.10.12"
version = "0.10.13"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
Expand Down
78 changes: 46 additions & 32 deletions volo-build/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use pilota_build::{IdlService, Plugin};
use volo::FastStr;

use crate::{
model::{GitSource, Source, WorkspaceConfig},
util::{download_repos_to_target, strip_slash_prefix},
model::WorkspaceConfig,
util::{download_repos_to_target, get_idl_build_path_and_includes, ServiceBuilder},
};

pub struct Builder<MkB, P> {
Expand Down Expand Up @@ -44,7 +44,7 @@ where
MkB::Target: Send,
P: pilota_build::parser::Parser,
{
pub fn gen(self) {
pub fn gen(mut self) {
let work_dir = std::env::current_dir().unwrap();
let config = match std::fs::read(work_dir.join("volo.workspace.yml")) {
Ok(config) => config,
Expand All @@ -71,45 +71,43 @@ where
std::process::exit(1);
};

let mut includes: Vec<PathBuf> = Vec::new();

let services = config
let (idl_services, service_builders): (Vec<_>, Vec<_>) = config
.services
.into_iter()
.map(|s| {
if let Source::Git(GitSource { ref repo }) = s.idl.source {
// git should use relative path instead of absolute path
let dir = repo_dir_map
.get(repo)
.expect("git source requires the repo info for idl")
.clone();
let path = dir.join(strip_slash_prefix(s.idl.path.as_path()));
includes.extend(s.idl.includes.iter().map(|v| dir.join(v.clone())));
// To resolve absolute path dependencies, go back two levels to the domain level
if let Some(path) = dir.parent().and_then(|d| d.parent()) {
includes.push(path.to_path_buf());
}
IdlService {
path,
config: s.codegen_option.config,
}
} else {
includes.extend(s.idl.includes.iter().cloned());
let (path, includes) = get_idl_build_path_and_includes(&s.idl, &repo_dir_map);
(
IdlService {
path: s.idl.path.clone(),
path: path.clone(),
config: s.codegen_option.config,
}
}
},
ServiceBuilder {
path,
includes,
touch: s.codegen_option.touch,
keep_unknown_fields: s.codegen_option.keep_unknown_fields,
},
)
})
.collect();

self.include_dirs(includes)
.ignore_unused(!config.common_option.touch_all)
.unzip();
for ServiceBuilder {
path,
includes,
touch,
keep_unknown_fields,
} in service_builders
{
self = self.include_dirs(includes).touch([(path.clone(), touch)]);
if keep_unknown_fields {
self = self.keep_unknown_fields([path]);
}
}
self.ignore_unused(!config.common_option.touch_all)
.dedup(config.common_option.dedups)
.special_namings(config.common_option.special_namings)
.common_crate_name(config.common_crate_name)
.pilota_builder
.compile_with_config(services, pilota_build::Output::Workspace(work_dir));
.compile_with_config(idl_services, pilota_build::Output::Workspace(work_dir));
}

pub fn plugin(mut self, plugin: impl Plugin + 'static) -> Self {
Expand Down Expand Up @@ -141,4 +139,20 @@ where
self.pilota_builder = self.pilota_builder.include_dirs(include_dirs);
self
}

pub fn keep_unknown_fields(
mut self,
keep_unknown_fields: impl IntoIterator<Item = PathBuf>,
) -> Self {
self.pilota_builder = self.pilota_builder.keep_unknown_fields(keep_unknown_fields);
self
}

pub fn touch(
mut self,
items: impl IntoIterator<Item = (PathBuf, Vec<impl Into<String>>)>,
) -> Self {
self.pilota_builder = self.pilota_builder.touch(items);
self
}
}

0 comments on commit 27bb5b0

Please sign in to comment.