diff --git a/Cargo.lock b/Cargo.lock index 2e3e8bb1..bc2a28e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3570,7 +3570,7 @@ dependencies = [ [[package]] name = "volo-build" -version = "0.10.12" +version = "0.10.13" dependencies = [ "ahash", "anyhow", diff --git a/volo-build/Cargo.toml b/volo-build/Cargo.toml index 5456a859..688cb588 100644 --- a/volo-build/Cargo.toml +++ b/volo-build/Cargo.toml @@ -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 diff --git a/volo-build/src/workspace.rs b/volo-build/src/workspace.rs index ad666421..425b8cc4 100644 --- a/volo-build/src/workspace.rs +++ b/volo-build/src/workspace.rs @@ -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 { @@ -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, @@ -71,45 +71,43 @@ where std::process::exit(1); }; - let mut includes: Vec = 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 { @@ -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, + ) -> Self { + self.pilota_builder = self.pilota_builder.keep_unknown_fields(keep_unknown_fields); + self + } + + pub fn touch( + mut self, + items: impl IntoIterator>)>, + ) -> Self { + self.pilota_builder = self.pilota_builder.touch(items); + self + } }