diff --git a/bin/dist/asc/linux/asc b/bin/dist/asc/linux/asc deleted file mode 100644 index bb894a4d..00000000 Binary files a/bin/dist/asc/linux/asc and /dev/null differ diff --git a/bin/dist/asc/windows/asc.exe b/bin/dist/asc/windows/asc.exe deleted file mode 100644 index a05088e4..00000000 Binary files a/bin/dist/asc/windows/asc.exe and /dev/null differ diff --git a/bin/src/commands/build.rs b/bin/src/commands/build.rs index 0f58f3d3..5a08eccd 100644 --- a/bin/src/commands/build.rs +++ b/bin/src/commands/build.rs @@ -8,9 +8,6 @@ use crate::{ report::Report, }; -#[cfg(not(target_os = "macos"))] -use crate::modules::asc::ArmaScriptCompiler; - #[must_use] pub fn cli() -> Command { add_just(add_args( @@ -36,12 +33,6 @@ pub fn add_args(cmd: Command) -> Command { .help("Do not rapify (cpp, rvmat)") .action(ArgAction::SetTrue), ) - .arg( - clap::Arg::new("asc") - .long("asc") - .help("Use ArmaScriptCompiler instead of HEMTT's SQF compiler") - .action(ArgAction::SetTrue), - ) } #[must_use] @@ -92,12 +83,6 @@ pub fn execute(matches: &ArgMatches) -> Result { pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor { let mut executor = Executor::new(ctx); - let use_asc = matches.get_one::("asc") == Some(&true); - if cfg!(target_os = "macos") && use_asc { - error!("ArmaScriptCompiler is not supported on macOS"); - std::process::exit(1); - } - executor.collapse(Collapse::No); executor.add_module(Box::::default()); @@ -105,11 +90,7 @@ pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor { if matches.get_one::("no-rap") != Some(&true) { executor.add_module(Box::::default()); } - executor.add_module(Box::new(SQFCompiler::new(!use_asc))); - #[cfg(not(target_os = "macos"))] - if use_asc { - executor.add_module(Box::::default()); - } + executor.add_module(Box::new(SQFCompiler::default())); if matches.get_one::("no-bin") != Some(&true) { executor.add_module(Box::::default()); } diff --git a/bin/src/commands/dev.rs b/bin/src/commands/dev.rs index 5064fdc4..35fcc5f0 100644 --- a/bin/src/commands/dev.rs +++ b/bin/src/commands/dev.rs @@ -11,9 +11,6 @@ use crate::{ report::Report, }; -#[cfg(not(target_os = "macos"))] -use crate::modules::asc::ArmaScriptCompiler; - use super::build::add_just; #[must_use] @@ -48,12 +45,6 @@ pub fn add_args(cmd: Command) -> Command { .help("Include all optional addon folders") .action(ArgAction::SetTrue), ) - .arg( - clap::Arg::new("asc") - .long("asc") - .help("Use ArmaScriptCompiler instead of HEMTT's SQF compiler") - .action(ArgAction::SetTrue), - ) .arg( clap::Arg::new("no-rap") .long("no-rap") @@ -132,12 +123,6 @@ pub fn context( } } - let use_asc = matches.get_one::("asc") == Some(&true); - if cfg!(target_os = "macos") && use_asc { - error!("ArmaScriptCompiler is not supported on macOS"); - std::process::exit(1); - } - let mut executor = Executor::new(ctx); executor.collapse(Collapse::Yes); @@ -147,11 +132,7 @@ pub fn context( if rapify && matches.get_one::("no-rap") != Some(&true) { executor.add_module(Box::::default()); } - executor.add_module(Box::new(SQFCompiler::new(!use_asc))); - #[cfg(not(target_os = "macos"))] - if use_asc { - executor.add_module(Box::::default()); - } + executor.add_module(Box::new(SQFCompiler::default())); executor.add_module(Box::::default()); executor.add_module(Box::::default()); if force_binarize || matches.get_one::("binarize") == Some(&true) { diff --git a/bin/src/error.rs b/bin/src/error.rs index 84e20dfa..186969a3 100644 --- a/bin/src/error.rs +++ b/bin/src/error.rs @@ -5,10 +5,6 @@ pub enum Error { #[error("`.hemtt/project.toml` not found")] ConfigNotFound, - #[error("ASC: {0}")] - #[cfg(not(target_os = "macos"))] - ArmaScriptCompiler(String), - #[error("Unable to create link: {0}")] #[allow(dead_code)] // Unused on Linux and Mac Link(String), diff --git a/bin/src/modules/asc.rs b/bin/src/modules/asc.rs deleted file mode 100644 index 62f10619..00000000 --- a/bin/src/modules/asc.rs +++ /dev/null @@ -1,240 +0,0 @@ -use std::{ - fs::{create_dir_all, File}, - io::{Read, Write}, - process::Command, - sync::{ - atomic::{AtomicU16, Ordering}, - Arc, RwLock, - }, -}; - -use hemtt_preprocessor::Processor; -use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; -use rust_embed::RustEmbed; -use serde::Serialize; -use std::time::Instant; - -use crate::{context::Context, error::Error, report::Report}; - -use super::Module; - -#[cfg(windows)] -#[derive(RustEmbed)] -#[folder = "dist/asc/windows"] -struct Distributables; - -#[cfg(not(windows))] -#[derive(RustEmbed)] -#[folder = "dist/asc/linux"] -struct Distributables; - -#[derive(Default)] -pub struct ArmaScriptCompiler; - -#[cfg(windows)] -const SOURCE: [&str; 1] = ["asc.exe"]; - -#[cfg(not(windows))] -const SOURCE: [&str; 1] = ["asc"]; - -impl Module for ArmaScriptCompiler { - fn name(&self) -> &'static str { - "ArmaScriptCompiler" - } - - fn init(&mut self, ctx: &Context) -> Result { - let asc = ctx.tmp().join("asc"); - trace!("using asc folder at {:?}", asc.display()); - create_dir_all(asc.join("output"))?; - Ok(Report::new()) - } - - #[allow(clippy::too_many_lines)] - #[allow(dependency_on_unit_never_type_fallback)] // ToDo: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html - fn pre_build(&self, ctx: &Context) -> Result { - let mut out_file = - File::create(".hemttout/asc.log").expect("Unable to create `.hemttout/asc.log`"); - let mut config = ASCConfig::new(); - let tmp = ctx.tmp().join("asc"); - for file in SOURCE { - let out = tmp.join(file); - let _ = std::fs::create_dir_all(out.parent().expect("must have parent")); - trace!("unpacking {:?} to {:?}", file, out.display()); - let mut f = File::create(&out)?; - f.write_all( - &Distributables::get(file) - .expect("dist files should exist") - .data, - )?; - #[cfg(target_os = "linux")] - { - use std::os::unix::fs::PermissionsExt; - std::fs::set_permissions(out, PermissionsExt::from_mode(0o744))?; - } - } - let sqf_ext = Some(String::from("sqf")); - let files = Arc::new(RwLock::new(Vec::new())); - let start = Instant::now(); - let mut root_dirs = Vec::new(); - for addon in ctx.addons() { - if !root_dirs.contains(&addon.prefix().main_prefix()) { - root_dirs.push(addon.prefix().main_prefix()); - } - let tmp_addon = tmp.join(addon.prefix().as_pathbuf()); - create_dir_all(&tmp_addon)?; - let mut entries = Vec::new(); - for entry in ctx.workspace_path().join(addon.folder())?.walk_dir()? { - if entry.is_file()? { - if entry.extension() != sqf_ext { - continue; - } - if entry.filename().ends_with(".inc.sqf") { - continue; - } - entries.push(entry); - } - } - entries - .par_iter() - .map(|entry| { - let processed = Processor::run(entry).map_err(|(_, e)| e)?; - let source = tmp_addon.join( - entry - .as_str() - .trim_start_matches(&format!("/{}/", addon.folder())), - ); - let parent = source.parent().expect("must have parent"); - if !parent.exists() { - std::mem::drop(create_dir_all(parent)); - } - let mut f = File::create(source)?; - f.write_all(processed.as_str().as_bytes())?; - files - .write() - .expect("unable to write to source files to tmp") - .push(( - format!( - "{}{}", - addon - .prefix() - .to_string() - .replace('\\', "/") - .trim_end_matches(&addon.folder().replacen( - "optionals/", - "addons/", - 1 - )) - .trim_end_matches(&addon.folder()), - entry.as_str().to_string().trim_start_matches('/'), - ), - entry - .as_str() - .to_string() - .trim_start_matches('/') - .to_string(), - )); - Ok(()) - }) - .collect::>()?; - } - debug!("ASC Preprocess took {:?}", start.elapsed().as_millis()); - for root in root_dirs { - config.add_input_dir(root.to_string()); - } - config.set_output_dir(tmp.join("output").display().to_string()); - let include = tmp.join("source").join("include"); - if include.exists() { - config.add_include_dir(include.display().to_string()); - } - config.set_worker_threads(num_cpus::get()); - let mut f = File::create(tmp.join("sqfc.json"))?; - f.write_all(serde_json::to_string_pretty(&config)?.as_bytes())?; - std::env::set_current_dir(&tmp)?; - let start = Instant::now(); - let command = Command::new(tmp.join(SOURCE[0])).output()?; - out_file.write_all(&command.stdout)?; - out_file.write_all(&command.stderr)?; - if String::from_utf8(command.stdout.clone()) - .expect("stdout should be valid utf8") - .contains("Parse Error") - { - warn!("ASC 'Parse Error' - check .hemttout/asc.log"); - } - if command.status.success() { - debug!("ASC took {:?}", start.elapsed().as_millis()); - } else { - return Err(Error::ArmaScriptCompiler( - String::from_utf8(command.stdout).expect("stdout should be valid utf8"), - )); - } - std::env::set_current_dir(ctx.project_folder())?; - let tmp_output = tmp.join("output"); - let counter = AtomicU16::new(0); - for (src, dst) in &*files.read().expect("unable to read source files") { - let from = tmp_output.join(format!("{src}c")); - let to = ctx.workspace_path().join(format!("{dst}c"))?; - if !from.exists() { - // sqf that have parse errors OR just empty//no-code - debug!("asc didn't process {}", src); - continue; - } - let mut f = File::open(from)?; - let mut data = Vec::new(); - f.read_to_end(&mut data)?; - to.create_file()?.write_all(&data)?; - counter.fetch_add(1, Ordering::Relaxed); - } - info!("Compiled {} sqf files", counter.load(Ordering::Relaxed)); - Ok(Report::new()) - } -} - -#[derive(Default, Serialize)] -pub struct ASCConfig { - #[serde(rename = "inputDirs")] - input_dirs: Vec, - #[serde(rename = "outputDir")] - output_dir: String, - #[serde(rename = "includePaths")] - include_dirs: Vec, - #[serde(rename = "excludeList")] - exclude_list: Vec, - #[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; - } -} diff --git a/bin/src/modules/mod.rs b/bin/src/modules/mod.rs index 5da54869..2c1b32e7 100644 --- a/bin/src/modules/mod.rs +++ b/bin/src/modules/mod.rs @@ -1,8 +1,5 @@ use crate::{context::Context, error::Error, report::Report}; -#[cfg(not(target_os = "macos"))] -pub mod asc; - pub mod archive; pub mod bom; pub mod hook; diff --git a/bin/src/modules/sqf.rs b/bin/src/modules/sqf.rs index f236fca8..cb5f6921 100644 --- a/bin/src/modules/sqf.rs +++ b/bin/src/modules/sqf.rs @@ -18,17 +18,13 @@ use super::Module; #[derive(Default)] pub struct SQFCompiler { - pub compile: bool, pub database: Option>, } impl SQFCompiler { #[must_use] - pub const fn new(compile: bool) -> Self { - Self { - compile, - database: None, - } + pub const fn new() -> Self { + Self { database: None } } } @@ -98,10 +94,8 @@ impl Module for SQFCompiler { database.clone(), ); if !codes.failed() { - if self.compile { - let mut out = entry.with_extension("sqfc")?.create_file()?; - sqf.optimize().compile_to_writer(&processed, &mut out)?; - } + let mut out = entry.with_extension("sqfc")?.create_file()?; + sqf.optimize().compile_to_writer(&processed, &mut out)?; counter.fetch_add(1, Ordering::Relaxed); } for code in codes { @@ -133,15 +127,7 @@ impl Module for SQFCompiler { for new_report in reports { report.merge(new_report); } - info!( - "{} {} sqf files", - if self.compile { - "Compiled" - } else { - "Validated" - }, - counter.load(Ordering::Relaxed) - ); + info!("Compiled {} sqf files", counter.load(Ordering::Relaxed)); Ok(report) } diff --git a/bin/tests/alpha/.hemtt/project.toml b/bin/tests/alpha/.hemtt/project.toml index 5361f6d8..89bc08cd 100644 --- a/bin/tests/alpha/.hemtt/project.toml +++ b/bin/tests/alpha/.hemtt/project.toml @@ -8,9 +8,6 @@ minor = 0 patch = 4 git_hash = 0 -[asc] -enabled = true - [hemtt.launch.default] dlc = [ "ws" diff --git a/libs/sqf/src/compiler/serializer/mod.rs b/libs/sqf/src/compiler/serializer/mod.rs index 07f107b2..a2e15232 100644 --- a/libs/sqf/src/compiler/serializer/mod.rs +++ b/libs/sqf/src/compiler/serializer/mod.rs @@ -15,7 +15,6 @@ use std::cmp::Ordering; use std::io::{self, Read, Write}; use std::sync::Arc; -/// `ArmaScriptCompiler` defaults to `1`, so this is hardcoded for now. pub const VERSION: u32 = 1; #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]