From 05edd2ec64682e9a9d933b833cb0338121e0dd20 Mon Sep 17 00:00:00 2001 From: tanneberger Date: Sat, 21 Sep 2024 01:08:39 +0200 Subject: [PATCH] formatting and preparing for merge --- Cargo.lock | 9 +++++---- Cargo.toml | 2 +- src/args.rs | 1 - src/backends/cmake_c.rs | 8 +------- src/backends/cmake_cpp.rs | 10 ++++++---- src/backends/mod.rs | 4 ++-- src/package/lock.rs | 12 +++++------- src/package/management.rs | 20 ++++++++++---------- src/package/mod.rs | 2 +- 9 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b221d53..02b52cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,9 +362,9 @@ checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" [[package]] name = "itertools" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] @@ -891,8 +891,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "versions" -version = "6.1.0" -source = "git+https://github.com/tanneberger/rs-versions.git#7802574585abc55d06b5e21e20be7ced02b5ffab" +version = "6.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f25d498b63d1fdb376b4250f39ab3a5ee8d103957346abacd911e2d8b612c139" dependencies = [ "itertools", "nom", diff --git a/Cargo.toml b/Cargo.toml index 6aa8f9d..1133fc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ git2 = "0.18" tempfile = "3.0" url = { version = "2.5", features = ["serde"] } anyhow = "1.0" -versions = { git = "https://github.com/tanneberger/rs-versions.git", features = ["serde"]} +versions = { version = "6.3.2", features = ["serde"]} log = "0.4" sha1dir = { version = "1.0", git = "https://github.com/tanneberger/sha1dir" } colored = "2.1.0" diff --git a/src/args.rs b/src/args.rs index f391ba6..f60d98d 100644 --- a/src/args.rs +++ b/src/args.rs @@ -32,7 +32,6 @@ pub enum BuildSystem { #[derive(Args, Debug)] pub struct BuildArgs { /// Which build system to use - /// TODO: discuss this #[arg(short, long)] pub build_system: Option, diff --git a/src/backends/cmake_c.rs b/src/backends/cmake_c.rs index f6075ef..a3718bf 100644 --- a/src/backends/cmake_c.rs +++ b/src/backends/cmake_c.rs @@ -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) @@ -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!( diff --git a/src/backends/cmake_cpp.rs b/src/backends/cmake_cpp.rs index 1e049f9..eab56b5 100644 --- a/src/backends/cmake_cpp.rs +++ b/src/backends/cmake_cpp.rs @@ -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)) diff --git a/src/backends/mod.rs b/src/backends/mod.rs index cbbc86d..60ce8e2 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -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) => { diff --git a/src/package/lock.rs b/src/package/lock.rs index dd6c39c..5722b70 100644 --- a/src/package/lock.rs +++ b/src/package/lock.rs @@ -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::(&lingo_toml_text)?.to_config(&temp); println!( @@ -241,8 +241,6 @@ impl DependencyLock { } }; - - self.loaded_dependencies.push(DependencyTreeNode { name: read_toml.package.name.clone(), version: read_toml.package.version.clone(), @@ -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 { @@ -285,6 +283,6 @@ impl DependencyLock { i.merge(&tp.properties)?; } - return Ok(i); + Ok(i) } } diff --git a/src/package/management.rs b/src/package/management.rs index 0a6bff9..a5c0dc5 100644 --- a/src/package/management.rs +++ b/src/package/management.rs @@ -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(), }) } @@ -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 { @@ -108,15 +108,15 @@ impl PackageDetails { impl DependencyManager { pub fn from_dependencies( dependencies: Vec<(String, PackageDetails)>, - target_path: &PathBuf, + target_path: &Path, ) -> anyhow::Result { // 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() { @@ -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, @@ -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"); @@ -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 @@ -268,7 +268,7 @@ impl DependencyManager { }) } - fn flatten<'a>(root_nodes: Vec) -> anyhow::Result> { + fn flatten(root_nodes: Vec) -> anyhow::Result> { // implementation idea: // 1. we collect all the version requirements for packages => are the different // constraints satisfiable ? @@ -300,7 +300,7 @@ impl DependencyManager { sources .entry(&node.name) .and_modify(move |value| { - value.push(&node); + value.push(node); }) .or_insert(vec![&node]); } diff --git a/src/package/mod.rs b/src/package/mod.rs index cc8258a..1a5e494 100644 --- a/src/package/mod.rs +++ b/src/package/mod.rs @@ -46,7 +46,7 @@ pub const LIBRARY_DIRECTORY: &str = "libraries"; const DEFAULT_EXECUTABLE_FOLDER: &str = "src"; /// default folder for lf library files -const DEFAULT_LIBRARY_FOLDER: &str = "lib"; +const DEFAULT_LIBRARY_FOLDER: &str = "src/lib"; fn is_valid_location_for_project(path: &std::path::Path) -> bool { !path.join(DEFAULT_EXECUTABLE_FOLDER).exists()