From e9de9363039024d12af86cbed51dff131a50c647 Mon Sep 17 00:00:00 2001 From: Alex Vergara Date: Sun, 14 Jul 2024 12:35:06 +0200 Subject: [PATCH] fix: missing the project root on the cached data serialized given the new structure --- zork++/benches/benchmarks.rs | 8 ++++---- zork++/src/lib/cache/mod.rs | 25 +++++++++++++++---------- zork++/src/lib/lib.rs | 10 +++++----- zork++/src/lib/project_model/mod.rs | 19 ++++++++++--------- zork++/test/test.rs | 4 ++-- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/zork++/benches/benchmarks.rs b/zork++/benches/benchmarks.rs index aa8afa61..6b8fdce1 100644 --- a/zork++/benches/benchmarks.rs +++ b/zork++/benches/benchmarks.rs @@ -6,7 +6,7 @@ use clap::Parser; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use zork::compiler::generate_commands; use zork::{ - cache::{self, ZorkCache}, + cache::ZorkCache, cli::input::CliArgs, config_file::{self, ZorkConfigFile}, utils::{self, reader::build_model}, @@ -23,9 +23,9 @@ pub fn build_project_benchmark(c: &mut Criterion) { b.iter(|| generate_commands(black_box(&program_data), black_box(&mut cache), &cli_args)) }); - c.bench_function("Cache loading time", |b| { - b.iter(|| cache::load(black_box(&program_data), &CliArgs::default())) - }); + /* c.bench_function("Cache loading time", |b| { + b.iter(|| cache::load(black_box(&config), &CliArgs::default(), &Path::new("."))) + }); */ } criterion_group!(benches, build_project_benchmark); diff --git a/zork++/src/lib/cache/mod.rs b/zork++/src/lib/cache/mod.rs index c7ebe9c6..487d39bc 100644 --- a/zork++/src/lib/cache/mod.rs +++ b/zork++/src/lib/cache/mod.rs @@ -32,17 +32,22 @@ use crate::project_model::compiler::StdLibMode; /// Standalone utility for load from the file system the Zork++ cache file /// for the target [`CppCompiler`] -pub fn load<'a>(config: &ZorkConfigFile<'a>, cli_args: &CliArgs) -> Result> { +pub fn load<'a>( + config: &ZorkConfigFile<'a>, + cli_args: &CliArgs, + project_root: &Path, +) -> Result> { let compiler: CppCompiler = config.compiler.cpp_compiler.into(); - let cache_path = Path::new( - &config - .build - .as_ref() - .and_then(|build_attr| build_attr.output_dir) - .unwrap_or("out"), - ) - .join("zork") - .join("cache"); + let cache_path = Path::new(project_root) + .join( + config + .build + .as_ref() + .and_then(|build_attr| build_attr.output_dir) + .unwrap_or("out"), + ) + .join("zork") + .join("cache"); let cache_file_path = cache_path .join(compiler.as_ref()) diff --git a/zork++/src/lib/lib.rs b/zork++/src/lib/lib.rs index a59201f4..af4d05c9 100644 --- a/zork++/src/lib/lib.rs +++ b/zork++/src/lib/lib.rs @@ -80,8 +80,8 @@ pub mod worker { let config = config_file::zork_cfg_from_file(raw_file.as_str()) .with_context(|| error_messages::PARSE_CFG_FILE)?; - create_output_directory(&config)?; // TODO: avoid this call without check if exists - let cache = cache::load(&config, cli_args)?; + create_output_directory(&config, &abs_project_root)?; // TODO: avoid this call without check if exists + let cache = cache::load(&config, cli_args, &abs_project_root)?; // TODO: Big one, need to call cache.load_tasks or whatever, or metadata won't be // loaded @@ -155,7 +155,7 @@ pub mod worker { /// - a /cache folder, where lives the metadata cached by Zork++ /// in order to track different aspects of the program (last time /// modified files, last process build time...) - fn create_output_directory(config: &ZorkConfigFile) -> Result<()> { + fn create_output_directory(config: &ZorkConfigFile, project_root: &Path) -> Result<()> { let compiler: CppCompiler = config.compiler.cpp_compiler.into(); let compiler_name = compiler.as_ref(); let binding = config @@ -163,7 +163,7 @@ pub mod worker { .as_ref() .and_then(|build_attr| build_attr.output_dir) .unwrap_or("out"); - let out_dir = Path::new(&binding); + let out_dir = Path::new(project_root).join(binding); // Recursively create the directories below and all of its parent components if they are missing let modules_path = out_dir.join(compiler_name).join(dir_names::MODULES); @@ -228,7 +228,7 @@ pub mod worker { let modules_path = compiler_folder_dir.join("modules"); // This should create and out/ directory at the root of the tmp path - super::create_output_directory(&zcf)?; + super::create_output_directory(&zcf, temp_path)?; assert!(out_dir.exists()); diff --git a/zork++/src/lib/project_model/mod.rs b/zork++/src/lib/project_model/mod.rs index 5dca2dde..ad067913 100644 --- a/zork++/src/lib/project_model/mod.rs +++ b/zork++/src/lib/project_model/mod.rs @@ -49,15 +49,16 @@ pub fn load<'a>( absolute_project_root: &Path, ) -> Result> { let compiler: CppCompiler = config.compiler.cpp_compiler.into(); - let cache_path = Path::new( - &config - .build - .as_ref() - .and_then(|build_attr| build_attr.output_dir) - .unwrap_or("out"), - ) - .join("zork") - .join("cache"); + let cache_path = Path::new(absolute_project_root) + .join( + config + .build + .as_ref() + .and_then(|build_attr| build_attr.output_dir) + .unwrap_or("out"), + ) + .join("zork") + .join("cache"); let cached_project_model_path = cache_path .join(format!("{}_pm", compiler.as_ref())) diff --git a/zork++/test/test.rs b/zork++/test/test.rs index ab36b4a0..871fd5b0 100644 --- a/zork++/test/test.rs +++ b/zork++/test/test.rs @@ -35,8 +35,8 @@ fn test_clang_full_process() -> Result<()> { "-vv", "--root", &project_root, - /* "--driver-path", - "clang++-16", // Local cfg issues */ + "--driver-path", + "clang++-16", // Local cfg issues "run", ])); assert!(process_result.is_ok(), "{}", process_result.unwrap_err());