diff --git a/src/backends/cmake.rs b/src/backends/cmake.rs index 1884ce2..cca82b0 100644 --- a/src/backends/cmake.rs +++ b/src/backends/cmake.rs @@ -1,4 +1,5 @@ use std::fs; +use std::io::Write; use std::process::Command; @@ -15,8 +16,28 @@ fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult { let build_dir = app.output_root.join("build"); fs::create_dir_all(&build_dir)?; - let mut cmake = Command::new("cmake"); + // location of the cmake file + let app_build_folder = app.src_gen_dir().join(&app.name); + let cmake_file = app_build_folder.clone().join("CMakeLists.txt"); + + // create potential files that come from the target properties + app.properties.write_artifacts(&app_build_folder)?; + + // we need to modify the cmake file here to include our generated cmake files + let src_gen_dir = app.src_gen_dir(); + + // read file and append cmake include to generated cmake file + let mut content = fs::read_to_string(&cmake_file)?; + let include_statement = format!("\ninclude({}/aggregated_cmake_include.cmake)", app_build_folder.display()); + content += &*include_statement; + + // overwrite cmake file + let mut f = fs::OpenOptions::new().write(true).open(&cmake_file)?; + f.write_all(content.as_ref())?; + f.flush()?; + // cmake args + let mut cmake = Command::new("cmake"); cmake.arg(format!( "-DCMAKE_BUILD_TYPE={}", if options.profile == BuildProfile::Release { @@ -39,7 +60,7 @@ fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult { .expect("not a valid main reactor path") .display() )); - cmake.arg(app.src_gen_dir()); + cmake.arg(src_gen_dir); cmake.arg(format!("-B {}", build_dir.display())); cmake.current_dir(&build_dir); @@ -52,7 +73,7 @@ fn do_cmake_build(results: &mut BatchBuildResults, options: &BuildCommandOptions // cry loud when it doesn't match out specified version results.keep_going(options.keep_going); - super::lfc::LFC::do_parallel_lfc_codegen(options, results, true); + super::lfc::LFC::do_parallel_lfc_codegen(options, results, false); if !options.compile_target_code { return; } diff --git a/src/backends/mod.rs b/src/backends/mod.rs index a56f5c0..3048ea5 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -9,6 +9,7 @@ use crate::args::{BuildSystem, Platform}; use crate::package::management::DependencyManager; use crate::package::tree::PackageDetails; use crate::package::{App, Config}; +use crate::package::target_properties::MergeTargetProperties; use crate::util::errors::{AnyError, BuildResult, LingoError}; pub mod cmake; @@ -16,16 +17,7 @@ pub mod lfc; pub mod npm; pub mod pnpm; -pub fn execute_command<'a>(command: &CommandSpec, config: &'a Config) -> BatchBuildResults<'a> { - // Group apps by build system - let mut by_build_system = HashMap::>::new(); - for app in &config.apps { - by_build_system - .entry(app.build_system()) - .or_default() - .push(app); - } - +pub fn execute_command<'a>(command: &CommandSpec, config: &'a mut Config) -> BatchBuildResults<'a> { let mut result = BatchBuildResults::new(); let dependencies = Vec::from_iter(config.dependencies.clone().into_iter()); @@ -35,12 +27,29 @@ pub fn execute_command<'a>(command: &CommandSpec, config: &'a Config) -> BatchBu let manager = DependencyManager::from_dependencies( dependencies.clone(), &PathBuf::from("./target"), - ); + ).expect("failed to create dep manager"); + + // enriching the apps with the target properties from the libraries + let library_properties = manager.get_target_properties().expect("lib properties"); + // merging app with library target properties + for app in &mut config.apps { + println!("merging app with lib target properties"); + app.properties.merge(&library_properties); + } } _ => {} } + // Group apps by build system + let mut by_build_system = HashMap::>::new(); + for app in &config.apps { + by_build_system + .entry(app.build_system()) + .or_default() + .push(app); + } + for (build_system, apps) in by_build_system { let mut sub_res = BatchBuildResults::for_apps(&apps, dependencies.clone()); diff --git a/src/main.rs b/src/main.rs index b4198b1..a2ce926 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ fn main() { print_res(result) } - let result = execute_command(wrapped_config.as_ref(), args.command); + let result = execute_command(&mut wrapped_config, args.command); match result { CommandResult::Batch(res) => res.print_results(), @@ -79,7 +79,7 @@ fn validate(config: &mut Option, command: &ConsoleCommand) -> BuildResul } } -fn execute_command(config: Option<&Config>, command: ConsoleCommand) -> CommandResult { +fn execute_command(config: &mut Option, command: ConsoleCommand) -> CommandResult { match (config, command) { (_, ConsoleCommand::Init(init_config)) => CommandResult::Single(do_init(init_config)), (None, _) => CommandResult::Single(Err(Box::new(io::Error::new( @@ -115,7 +115,7 @@ fn do_init(init_config: InitArgs) -> BuildResult { ) } -fn build<'a>(args: &BuildArgs, config: &'a Config) -> BatchBuildResults<'a> { +fn build<'a>(args: &BuildArgs, config: &'a mut Config) -> BatchBuildResults<'a> { run_command( CommandSpec::Build(BuildCommandOptions { profile: args.build_profile(), @@ -129,7 +129,7 @@ fn build<'a>(args: &BuildArgs, config: &'a Config) -> BatchBuildResults<'a> { ) } -fn run_command(task: CommandSpec, config: &Config, _fail_at_end: bool) -> BatchBuildResults { +fn run_command(task: CommandSpec, config: &mut Config, _fail_at_end: bool) -> BatchBuildResults { //let apps = config.apps.iter().collect::>(); //let dependencies = Vec::from_iter(config.dependencies.into_iter()); backends::execute_command(&task, config) diff --git a/src/package/lock.rs b/src/package/lock.rs index fb4f385..ace426c 100644 --- a/src/package/lock.rs +++ b/src/package/lock.rs @@ -63,12 +63,15 @@ impl DependencyLock { mutual_exclusive: ProjectSource::Empty, }, location: temp, - hash: "".parse()?, + hash: "".to_string(), dependencies: vec![], properties: read_toml.library.unwrap().properties - }) + }); + } + println!("after init {}",self.loaded_dependencies.len()); + Ok(()) } @@ -84,13 +87,13 @@ impl DependencyLock { copy_dir_all(&local_source, &find_source)?; } - Ok(()) + return Ok(()); } pub fn aggregate_target_properties(&self) -> anyhow::Result { let mut i = LibraryTargetProperties::default(); - + println!("aggregate target properties {}", self.loaded_dependencies.len()); for tp in &self.loaded_dependencies { i.merge(&tp.properties)?; } diff --git a/src/package/management.rs b/src/package/management.rs index 020b5d8..9e66ded 100644 --- a/src/package/management.rs +++ b/src/package/management.rs @@ -98,6 +98,11 @@ impl DependencyManager { lock = serde_json::from_str::(&std::fs::read_to_string(lock_file).expect("cannot read lock file")).expect("cannot parse lock file"); println!("reading lfc_include folder ..."); lock.init(&target_path.clone().join("lfc_include")).expect("init failed"); + + Ok(DependencyManager { + pulling_queue: vec![], + lock, + }) } else { manager = DependencyManager::new(); @@ -114,12 +119,11 @@ impl DependencyManager { let include_folder = target_path.clone().join("lfc_include"); lock.create_library_folder(&library_path, &include_folder).expect("creating lock folder failed"); - } - let result = lock.aggregate_target_properties().expect("aggregation failed"); - println!("cmake: {}", &result.cmake_include); - - Ok(DependencyManager::new()) + manager.lock = lock; + + return Ok(manager); + } } pub fn pull( @@ -310,4 +314,7 @@ impl DependencyManager { Ok(selection) } + pub fn get_target_properties(&self) -> anyhow::Result{ + self.lock.aggregate_target_properties() + } } diff --git a/src/package/target_properties.rs b/src/package/target_properties.rs index 889c2f9..95ea3d6 100644 --- a/src/package/target_properties.rs +++ b/src/package/target_properties.rs @@ -149,14 +149,16 @@ pub trait MergeTargetProperties { impl MergeTargetProperties for LibraryTargetProperties { fn merge(&mut self, partent: &LibraryTargetProperties) -> anyhow::Result<()> { + println!("mergaaaaaaaaaaaaaaaaa"); self.cmake_include.merge(&partent.cmake_include)?; Ok(()) } } impl MergeTargetProperties for AppTargetProperties { - fn merge(&mut self, partent: &LibraryTargetProperties) -> anyhow::Result<()> { - self.cmake_include.merge(&partent.cmake_include)?; + fn merge(&mut self, parent: &LibraryTargetProperties) -> anyhow::Result<()> { + println!("mergeeeeeeeeeeeeeeeeee"); + self.cmake_include.merge(&parent.cmake_include)?; Ok(()) } } @@ -176,6 +178,7 @@ impl AppTargetProperties { let mut fd = std::fs::File::create(file)?; fd.write(self.cmake_include.0.as_ref())?; + fd.flush()?; Ok(()) }