Skip to content

Commit

Permalink
fix: missing the project root on the cached data serialized given the…
Browse files Browse the repository at this point in the history
… new structure
  • Loading branch information
TheRustifyer committed Jul 14, 2024
1 parent 2800fe7 commit e9de936
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
8 changes: 4 additions & 4 deletions zork++/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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);
Expand Down
25 changes: 15 additions & 10 deletions zork++/src/lib/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZorkCache<'a>> {
pub fn load<'a>(
config: &ZorkConfigFile<'a>,
cli_args: &CliArgs,
project_root: &Path,
) -> Result<ZorkCache<'a>> {
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())
Expand Down
10 changes: 5 additions & 5 deletions zork++/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -155,15 +155,15 @@ 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
.build
.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);
Expand Down Expand Up @@ -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());

Expand Down
19 changes: 10 additions & 9 deletions zork++/src/lib/project_model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ pub fn load<'a>(
absolute_project_root: &Path,
) -> Result<ZorkModel<'a>> {
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()))
Expand Down
4 changes: 2 additions & 2 deletions zork++/test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e9de936

Please sign in to comment.