Skip to content

Commit

Permalink
fix: removed unused borrows of the project configuration since its ow…
Browse files Browse the repository at this point in the history
…nership is transferred to the build_model procedure

fix: changed back the types on the config file data structures to their original reference types
  • Loading branch information
TheRustifyer committed Jun 24, 2024
1 parent 7535b3a commit dbadd89
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
cargo fmt --all -- --check
unit-and-doc-tests:
name: Verify code formatting
name: Run unit and doc tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
15 changes: 7 additions & 8 deletions zork++/src/lib/config_file/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! file for represent the available configuration properties within Zork++
//! for setting up the target compiler
use std::borrow::Cow;

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -70,16 +69,16 @@ use crate::project_model;
/// [`zork::config_file::ZorkConfigFile`] doc-test
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct CompilerAttribute {
pub struct CompilerAttribute<'a> {
pub cpp_compiler: CppCompiler,
// #[serde(borrow)]
pub driver_path: Option<Cow<'static, str>>,
#[serde(borrow)]
pub driver_path: Option<&'a str>,
pub cpp_standard: LanguageLevel,
pub std_lib: Option<StdLib>,
// #[serde(borrow)]
pub extra_args: Option<Vec<Cow<'static, str>>>,
// #[serde(borrow)]
pub system_headers_path: Option<Cow<'static, str>>,
#[serde(borrow)]
pub extra_args: Option<Vec<&'a str>>,
#[serde(borrow)]
pub system_headers_path: Option<&'a str>,
}

/// The C++ compilers available within Zork++
Expand Down
17 changes: 8 additions & 9 deletions zork++/src/lib/config_file/executable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Specify the execution configuration
use std::borrow::Cow;

use serde::*;

Expand Down Expand Up @@ -44,12 +43,12 @@ use serde::*;
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)]
#[serde(deny_unknown_fields)]
pub struct ExecutableAttribute<'a> {
// #[serde(borrow)]
pub executable_name: Option<Cow<'a, str>>,
// #[serde(borrow)]
pub sources_base_path: Option<Cow<'a, str>>,
// #[serde(borrow)]
pub sources: Option<Vec<Cow<'a, str>>>,
// #[serde(borrow)]
pub extra_args: Option<Vec<Cow<'a, str>>>,
#[serde(borrow)]
pub executable_name: Option<&'a str>,
#[serde(borrow)]
pub sources_base_path: Option<&'a str>,
#[serde(borrow)]
pub sources: Option<Vec<&'a str>>,
#[serde(borrow)]
pub extra_args: Option<Vec<&'a str>>,
}
4 changes: 2 additions & 2 deletions zork++/src/lib/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use self::{
pub struct ZorkConfigFile<'a> {
#[serde(borrow)]
pub project: ProjectAttribute<'a>,
// #[serde(borrow)]
pub compiler: CompilerAttribute,
#[serde(borrow)]
pub compiler: CompilerAttribute<'a>,
#[serde(borrow)]
pub build: Option<BuildAttribute<'a>>,
#[serde(borrow)]
Expand Down
37 changes: 22 additions & 15 deletions zork++/src/lib/utils/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ fn assemble_project_model(config: ProjectAttribute) -> ProjectModel {
}
}

fn assemble_compiler_model(config: CompilerAttribute, cli_args: &CliArgs) -> CompilerModel {
fn assemble_compiler_model<'a>(
config: CompilerAttribute<'a>,
cli_args: &'a CliArgs,
) -> CompilerModel<'a> {
let extra_args = config
.extra_args
.map(|args| args.into_iter().map(Argument::from).collect())
Expand Down Expand Up @@ -179,18 +182,25 @@ fn assemble_executable_model<'a>(
let config = config.as_ref();

let executable_name = config
.and_then(|exe| -> Option<Cow<'_, str>> { exe.executable_name.clone() })
.and_then(|exe| exe.executable_name)
.map(Cow::Borrowed)
.unwrap_or(project_name);

let sources = config

Check failure on line 189 in zork++/src/lib/utils/reader.rs

View workflow job for this annotation

GitHub Actions / Verify code formatting

Diff in /home/runner/work/Zork/Zork/zork++/src/lib/utils/reader.rs
.and_then(|exe| exe.sources.clone())
.unwrap_or_else(|| Vec::with_capacity(0));
.and_then(|exe| exe.sources.as_ref())
.map(|srcs| {
srcs.iter()// TODO: abstract this kind of procedures away to some method of TranslationUnit, for example?
// or some other new trait (can't this have a default impl on the trait definition itself?
.map(|src| Cow::Borrowed(*src))
.collect::<Vec<Cow<str>>>()
})
.unwrap_or_default();

let sourceset = get_sourceset_for(sources, project_root);

let extra_args = config
.and_then(|exe| exe.extra_args.as_ref())
.map(|args| args.iter().map(Argument::from).collect())
.map(|args| args.iter().map(|arg| Argument::from(*arg)).collect())
.unwrap_or_default();

ExecutableModel {
Expand Down Expand Up @@ -352,7 +362,11 @@ fn assemble_tests_model<'a>(

let sources = config
.and_then(|exe| exe.sources.as_ref())
.map(|srcs| srcs.iter().map(|src| Cow::Borrowed(*src)).collect())
.map(|srcs| {
srcs.iter()
.map(|src| Cow::Borrowed(*src))
.collect::<Vec<Cow<str>>>()
})
.unwrap_or_default();
let sourceset = get_sourceset_for(sources, project_root);

Expand All @@ -368,7 +382,7 @@ fn assemble_tests_model<'a>(
}
}

fn get_sourceset_for<'a>(srcs: Vec<Cow<'_, str>>, project_root: &Path) -> SourceSet<'a> {
fn get_sourceset_for<'a>(srcs: Vec<Cow<str>>, project_root: &Path) -> SourceSet<'a> {
let sources = srcs
.iter()
.map(|src| {
Expand Down Expand Up @@ -452,14 +466,7 @@ mod test {
sourceset: SourceSet { sources: vec![] },
extra_args: vec![],
},
modules: Some(ModulesModel {
base_ifcs_dir: Path::new("."),
interfaces: vec![],
base_impls_dir: Path::new("."),
implementations: vec![],
sys_modules: vec![],
extra_args: vec![],
}),
modules: None,
tests: TestsModel {
test_executable_name: "Zork++_test".into(),
sourceset: SourceSet { sources: vec![] },
Expand Down

0 comments on commit dbadd89

Please sign in to comment.