Skip to content

Commit

Permalink
modifing the cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Jun 2, 2024
1 parent 1ad74ed commit f93ebc8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 29 deletions.
27 changes: 24 additions & 3 deletions src/backends/cmake.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fs;
use std::io::Write;

use std::process::Command;

Expand All @@ -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 {
Expand All @@ -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);

Expand All @@ -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;
}
Expand Down
31 changes: 20 additions & 11 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@ 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;
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::<BuildSystem, Vec<&App>>::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());

Expand All @@ -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::<BuildSystem, Vec<&App>>::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());

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -79,7 +79,7 @@ fn validate(config: &mut Option<Config>, command: &ConsoleCommand) -> BuildResul
}
}

fn execute_command(config: Option<&Config>, command: ConsoleCommand) -> CommandResult {
fn execute_command(config: &mut Option<Config>, 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(
Expand Down Expand Up @@ -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(),
Expand All @@ -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::<Vec<_>>();
//let dependencies = Vec::from_iter(config.dependencies.into_iter());
backends::execute_command(&task, config)
Expand Down
11 changes: 7 additions & 4 deletions src/package/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -84,13 +87,13 @@ impl DependencyLock {
copy_dir_all(&local_source, &find_source)?;
}

Ok(())
return Ok(());
}


pub fn aggregate_target_properties(&self) -> anyhow::Result<LibraryTargetProperties> {
let mut i = LibraryTargetProperties::default();

println!("aggregate target properties {}", self.loaded_dependencies.len());
for tp in &self.loaded_dependencies {
i.merge(&tp.properties)?;
}
Expand Down
17 changes: 12 additions & 5 deletions src/package/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ impl DependencyManager {
lock = serde_json::from_str::<DependencyLock>(&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();

Expand All @@ -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(
Expand Down Expand Up @@ -310,4 +314,7 @@ impl DependencyManager {
Ok(selection)
}

pub fn get_target_properties(&self) -> anyhow::Result<LibraryTargetProperties>{
self.lock.aggregate_target_properties()
}
}
7 changes: 5 additions & 2 deletions src/package/target_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand All @@ -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(())
}
Expand Down

0 comments on commit f93ebc8

Please sign in to comment.