Skip to content

Commit

Permalink
formatting and preparing for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Sep 30, 2024
1 parent 5fb461c commit 93d6095
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
8 changes: 1 addition & 7 deletions src/backends/cmake_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult {

// location of the cmake file
let app_build_folder = app.src_gen_dir().join(&app.main_reactor_name);
println!("creating {}", &app_build_folder.display());
let _ = std::fs::create_dir_all(&app_build_folder);
let cmake_file = app_build_folder.clone().join("CMakeLists.txt");

println!("writing artifacts ...");
// create potential files that come from the target properties
app.properties
.write_artifacts(&app_build_folder)
.expect("cannot write artifacts");

// read file and append cmake include to generated cmake file
println!("reading cmake file ... {:?}", &cmake_file);
let mut content = fs::read_to_string(&cmake_file)?;
let include_statement = "\ninclude(./aggregated_cmake_include.cmake)";
content += &*include_statement;
content += include_statement;

println!("writing cmake file ...");
// overwrite cmake file
let mut f = fs::OpenOptions::new()
.write(true)
Expand All @@ -42,8 +38,6 @@ fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult {
f.write_all(content.as_ref()).expect("cannot write file");
f.flush().expect("cannot flush");

println!("running file ...");

// cmake args
let mut cmake = Command::new("cmake");
cmake.arg(format!(
Expand Down
10 changes: 6 additions & 4 deletions src/backends/cmake_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ fn gen_cmake_files(app: &App, options: &BuildCommandOptions) -> BuildResult {
}

fn do_cmake_build(results: &mut BatchBuildResults, options: &BuildCommandOptions) {
// open lingo.toml of the dependency
// read the version
// cry loud when it doesn't match out specified version

// configure keep going parameter
results.keep_going(options.keep_going);

// start code-generation
super::lfc::LFC::do_parallel_lfc_codegen(options, results, false);

// stop process if the user request code-generation only
if !options.compile_target_code {
return;
}

results
// generate all CMake files ahead of time
.map(|app| gen_cmake_files(app, options))
Expand Down
4 changes: 2 additions & 2 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use crate::package::{
use crate::util::errors::{AnyError, BuildResult, LingoError};

pub mod cmake_c;

pub mod cmake_cpp;
pub mod lfc;
pub mod npm;
pub mod pnpm;

#[allow(clippy::single_match)] // there more options will be added to this match block
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());
let dependencies = Vec::from_iter(config.dependencies.clone());

match command {
CommandSpec::Build(_build) => {
Expand Down
12 changes: 5 additions & 7 deletions src/package/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl DependencyLock {
error!("checksum does not match aborting!");
}

let lingo_toml_text = fs::read_to_string(&temp.join("Lingo.toml"))?;
let lingo_toml_text = fs::read_to_string(temp.join("Lingo.toml"))?;
let read_toml = toml::from_str::<ConfigFile>(&lingo_toml_text)?.to_config(&temp);

println!(
Expand All @@ -241,8 +241,6 @@ impl DependencyLock {
}
};



self.loaded_dependencies.push(DependencyTreeNode {
name: read_toml.package.name.clone(),
version: read_toml.package.version.clone(),
Expand All @@ -265,18 +263,18 @@ impl DependencyLock {

pub fn create_library_folder(
&self,
source_path: &PathBuf,
source_path: &Path,
target_path: &PathBuf,
) -> anyhow::Result<()> {
fs::create_dir_all(target_path)?;
for (_, dep) in self.dependencies.iter() {
let local_source = source_path.clone().join(&dep.checksum);
let local_source = source_path.join(&dep.checksum);
let find_source = target_path.clone().join(&dep.name);
fs::create_dir_all(&find_source)?;
copy_dir_all(&local_source, &find_source)?;
}

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

pub fn aggregate_target_properties(&self) -> anyhow::Result<LibraryTargetProperties> {
Expand All @@ -285,6 +283,6 @@ impl DependencyLock {
i.merge(&tp.properties)?;
}

return Ok(i);
Ok(i)
}
}
20 changes: 10 additions & 10 deletions src/package/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl TryFrom<&PackageLockSource> for PackageDetails {
PackageLockSourceType::TARBALL => ProjectSource::TarBall(Url::from_str(url)?),
PackageLockSourceType::PATH => ProjectSource::Path(PathBuf::from(url)),
},
git_tag: value.rev.clone().map(|rev| GitLock::Rev(rev)),
git_tag: value.rev.clone().map(GitLock::Rev),
git_rev: value.rev.clone(),
})
}
Expand All @@ -84,7 +84,7 @@ impl PackageDetails {
};

// TODO: this produces hard to debug output
let (object, reference) = repo.revparse_ext(&name)?;
let (object, reference) = repo.revparse_ext(name)?;
repo.checkout_tree(&object, None)?;

match reference {
Expand All @@ -108,15 +108,15 @@ impl PackageDetails {
impl DependencyManager {
pub fn from_dependencies(
dependencies: Vec<(String, PackageDetails)>,
target_path: &PathBuf,
target_path: &Path,
) -> anyhow::Result<DependencyManager> {
// create library folder
let library_path = target_path.clone().join(LIBRARY_DIRECTORY);
let library_path = target_path.join(LIBRARY_DIRECTORY);
fs::create_dir_all(&library_path)?;

let mut manager;
let mut lock: DependencyLock;
let lock_file = target_path.clone().join("../Lingo.lock");
let lock_file = target_path.join("../Lingo.lock");

// checks if a Lingo.lock file exists
if lock_file.exists() {
Expand All @@ -126,7 +126,7 @@ impl DependencyManager {

// if a lock file is present it will load the dependencies from it and checks
// integrity of the build directory
if let Ok(()) = lock.init(&target_path.clone().join("lfc_include")) {
if let Ok(()) = lock.init(&target_path.join("lfc_include")) {
return Ok(DependencyManager {
pulling_queue: vec![],
lock,
Expand All @@ -153,7 +153,7 @@ impl DependencyManager {
lock_file.write_all(serialized_toml.as_ref())?;

// moves the selected packages into the include folder
let include_folder = target_path.clone().join("lfc_include");
let include_folder = target_path.join("lfc_include");
lock.create_library_folder(&library_path, &include_folder)
.expect("creating lock folder failed");

Expand Down Expand Up @@ -214,7 +214,7 @@ impl DependencyManager {
// directory where the dependencies will be dropped

// creating the necessary directories
fs::create_dir_all(&library_path)?;
fs::create_dir_all(library_path)?;
fs::create_dir_all(&temporary_path)?;

// cloning the specified package
Expand Down Expand Up @@ -268,7 +268,7 @@ impl DependencyManager {
})
}

fn flatten<'a>(root_nodes: Vec<DependencyTreeNode>) -> anyhow::Result<Vec<DependencyTreeNode>> {
fn flatten(root_nodes: Vec<DependencyTreeNode>) -> anyhow::Result<Vec<DependencyTreeNode>> {
// implementation idea:
// 1. we collect all the version requirements for packages => are the different
// constraints satisfiable ?
Expand Down Expand Up @@ -300,7 +300,7 @@ impl DependencyManager {
sources
.entry(&node.name)
.and_modify(move |value| {
value.push(&node);
value.push(node);
})
.or_insert(vec![&node]);
}
Expand Down

0 comments on commit 93d6095

Please sign in to comment.