Skip to content

Commit

Permalink
move asc config to sqf library
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Sep 26, 2024
1 parent e50bffa commit 994d42e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 0 additions & 2 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ hemtt-sqf = { path = "../libs/sqf" }
hemtt-preprocessor = { path = "../libs/preprocessor" }
hemtt-workspace = { path = "../libs/workspace" }

hemtt = { path = "../bin" }

automod = { workspace = true }
arma-bench = { git = "https://github.com/brettmayson/arma-bench", branch = "main" }
serde_json = { workspace = true }
6 changes: 4 additions & 2 deletions bench/src/sqf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{fs::File, io::Write, process::Command};

use arma_bench::{Client, CompareRequest, CompareResult};
use hemtt::modules::asc::ASCConfig;
use hemtt_preprocessor::Processor;
use hemtt_sqf::{asc::install, parser::database::Database};
use hemtt_sqf::{
asc::{install, ASCConfig},
parser::database::Database,
};
use hemtt_workspace::reporting::Processed;

pub fn compare(client: &Client, content: &str) -> Result<Vec<CompareResult>, String> {
Expand Down
52 changes: 1 addition & 51 deletions bin/src/modules/asc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::{
};

use hemtt_preprocessor::Processor;
use hemtt_sqf::asc::ASCConfig;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use serde::Serialize;
use std::time::Instant;

use crate::{context::Context, error::Error, report::Report};
Expand Down Expand Up @@ -156,53 +156,3 @@ impl Module for ArmaScriptCompiler {
Ok(Report::new())
}
}

#[derive(Default, Serialize)]
pub struct ASCConfig {
#[serde(rename = "inputDirs")]
input_dirs: Vec<String>,
#[serde(rename = "outputDir")]
output_dir: String,
#[serde(rename = "includePaths")]
include_dirs: Vec<String>,
#[serde(rename = "excludeList")]
exclude_list: Vec<String>,
#[serde(rename = "workerThreads")]
worker_threads: usize,
}

impl ASCConfig {
#[must_use]
pub const fn new() -> Self {
Self {
input_dirs: vec![],
output_dir: String::new(),
include_dirs: vec![],
exclude_list: vec![],
worker_threads: 2,
}
}

pub fn add_input_dir(&mut self, dir: String) {
if self.input_dirs.contains(&dir) {
return;
}
self.input_dirs.push(dir);
}

pub fn set_output_dir(&mut self, dir: String) {
self.output_dir = dir;
}

pub fn add_include_dir(&mut self, dir: String) {
self.include_dirs.push(dir);
}

pub fn add_exclude(&mut self, dir: &str) {
self.exclude_list.push(dir.replace('/', "\\"));
}

pub fn set_worker_threads(&mut self, threads: usize) {
self.worker_threads = threads;
}
}
3 changes: 2 additions & 1 deletion libs/sqf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ chumsky = { workspace = true, optional = true}
float-ord = "0.3.2"
linkme = { workspace = true }
rust-embed = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
toml = { workspace = true }
tracing = { workspace = true }

[features]
default = ["asc", "compiler", "parser"]
asc = ["rust-embed"]
asc = ["rust-embed", "serde"]
compiler = ["byteorder", "hemtt-lzo"]
parser = ["chumsky"]

Expand Down
51 changes: 51 additions & 0 deletions libs/sqf/src/asc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{fs::File, io::Write, path::Path};

use hemtt_common::error::thiserror;
use rust_embed::RustEmbed;
use serde::Serialize;
use tracing::trace;

#[cfg(windows)]
Expand Down Expand Up @@ -61,3 +62,53 @@ fn _install(path: &Path) -> Result<(), Error> {
}
Ok(())
}

#[derive(Default, Serialize)]
pub struct ASCConfig {
#[serde(rename = "inputDirs")]
input_dirs: Vec<String>,
#[serde(rename = "outputDir")]
output_dir: String,
#[serde(rename = "includePaths")]
include_dirs: Vec<String>,
#[serde(rename = "excludeList")]
exclude_list: Vec<String>,
#[serde(rename = "workerThreads")]
worker_threads: usize,
}

impl ASCConfig {
#[must_use]
pub const fn new() -> Self {
Self {
input_dirs: vec![],
output_dir: String::new(),
include_dirs: vec![],
exclude_list: vec![],
worker_threads: 2,
}
}

pub fn add_input_dir(&mut self, dir: String) {
if self.input_dirs.contains(&dir) {
return;
}
self.input_dirs.push(dir);
}

pub fn set_output_dir(&mut self, dir: String) {
self.output_dir = dir;
}

pub fn add_include_dir(&mut self, dir: String) {
self.include_dirs.push(dir);
}

pub fn add_exclude(&mut self, dir: &str) {
self.exclude_list.push(dir.replace('/', "\\"));
}

pub fn set_worker_threads(&mut self, threads: usize) {
self.worker_threads = threads;
}
}

0 comments on commit 994d42e

Please sign in to comment.