Skip to content

Commit

Permalink
fix: Allowing the user to declare absolute file paths in the configur…
Browse files Browse the repository at this point in the history
…ation file
  • Loading branch information
TheRustifyer committed Aug 17, 2024
1 parent 29285c1 commit 2a2df6d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.10.4] - 2024 - 08 - 17

### Fixes

- Allowing the user to declare absolute file paths in the configuration file

## [0.10.3] - 2024 - 08 - 12

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion zork++/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion zork++/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zork"
version = "0.10.3"
version = "0.10.4"
authors = ["Zero Day Code"]
edition = "2021"
description = "A modern C++ project manager and build system for modern C++"
Expand Down
16 changes: 8 additions & 8 deletions zork++/src/lib/cache/compile_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn map_generated_commands_to_compilation_db(
) -> Result<()> {
log::debug!("Generating the compilation database...");
let compiler = program_data.compiler.cpp_compiler;

let generated_commands = cache.get_all_commands_iter();
let mut compilation_db_entries: Vec<CompileCommand> =
Vec::with_capacity(cache.count_total_generated_commands());
Expand All @@ -40,16 +40,16 @@ pub(crate) fn map_generated_commands_to_compilation_db(
.with_context(|| error_messages::COMPILER_SPECIFIC_COMMON_ARGS_NOT_FOUND)?
.get_args();

let compile_but_dont_link: [Argument; 1] =
[Argument::from(match compiler {
CppCompiler::CLANG | CppCompiler::GCC => "-c",
CppCompiler::MSVC => "/c",
})];
let compile_but_dont_link: [Argument; 1] = [Argument::from(match compiler {
CppCompiler::CLANG | CppCompiler::GCC => "-c",
CppCompiler::MSVC => "/c",
})];

let compiler_driver: [Argument; 1] = [Argument::from(compiler.get_driver(&program_data.compiler))];
let compiler_driver: [Argument; 1] =
[Argument::from(compiler.get_driver(&program_data.compiler))];

for source_command_line in generated_commands {
let translation_unit_cmd_args = compiler_driver
let translation_unit_cmd_args = compiler_driver
.iter()
.chain(general_args.iter())
.chain(compiler_specific_shared_args.iter())
Expand Down
2 changes: 1 addition & 1 deletion zork++/src/lib/cli/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::project_model;
#[derive(Parser, Debug, Default)]
#[command(name = "Zork++")]
#[command(author = "Zero Day Code")]
#[command(version = "0.10.3")]
#[command(version = "0.10.4")]
#[command(
about = "Zork++ is a build system for modern C++ projects",
long_about = "Zork++ is a project of Zero Day Code. Find us: https://github.com/zerodaycode/Zork"
Expand Down
32 changes: 24 additions & 8 deletions zork++/src/lib/utils/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@ fn assemble_modules_model<'a>(

fn assemble_module_interface_model<'a>(
config: ModuleInterface<'a>,
base_path: &Path,
base_ifcs_dir_path: &Path,
code_root: &Path,
) -> ModuleInterfaceModel<'a> {
let cfg_file = config.file;
let file = config.file;

let file_path = Path::new(code_root).join(base_path).join(cfg_file);
let file_path = get_file_path(code_root, Some(base_ifcs_dir_path), file);

let module_name = if let Some(mod_name) = config.module_name {
Cow::Borrowed(mod_name)
} else {
Path::new(cfg_file)
Path::new(file)
.file_stem()
.unwrap_or_else(|| panic!("Found ill-formed file_stem data for: {cfg_file}"))
.unwrap_or_else(|| panic!("Found ill-formed file_stem data for: {file}"))
.to_string_lossy()
};
let dependencies = config
Expand All @@ -277,17 +277,19 @@ fn assemble_module_interface_model<'a>(

fn assemble_module_implementation_model<'a>(
config: ModuleImplementation<'a>,
base_path: &Path,
base_impls_dir_path: &Path,
code_root: &Path,
) -> ModuleImplementationModel<'a> {
let file = config.file;

let mut dependencies = config
.dependencies
.unwrap_or_default()
.into_iter()
.map(Cow::Borrowed)
.collect::<Vec<Cow<str>>>();

let file_path = Path::new(code_root).join(base_path).join(config.file);
let file_path = get_file_path(code_root, Some(base_impls_dir_path), file);

if dependencies.is_empty() {
let last_dot_index = config.file.rfind('.');
Expand Down Expand Up @@ -362,7 +364,7 @@ fn get_sources_for_target<'a>(srcs: Vec<Cow<str>>, code_root: &Path) -> SourceSe
let sources = srcs
.iter()
.map(|src| {
let target_src = code_root.join(src.as_ref());
let target_src = get_file_path(code_root, None, src.as_ref());
if src.contains('*') {
Source::Glob(GlobPattern(target_src))
} else {
Expand All @@ -389,6 +391,20 @@ fn get_sources_for_target<'a>(srcs: Vec<Cow<str>>, code_root: &Path) -> SourceSe
SourceSet::new(sources)
}

/// Helper to build the file path of a [`TranslationUnit`]
/// Parameter *reduction* is any intermediate path offered by configuration that lives after the
/// code root and before the file itself
fn get_file_path(code_root: &Path, reduction: Option<&Path>, declared_file_path: &str) -> PathBuf {
let declared_file_path = Path::new(declared_file_path);
if declared_file_path.is_absolute() {
declared_file_path.to_owned()
} else if let Some(reduction_path) = reduction {
code_root.join(reduction_path).join(declared_file_path)
} else {
code_root.join(declared_file_path)
}
}

#[cfg(test)]
mod test {
use std::borrow::Cow;
Expand Down

0 comments on commit 2a2df6d

Please sign in to comment.