Skip to content

Commit

Permalink
Merge branch 'main' into inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed Oct 10, 2024
2 parents 86db383 + fb59d8e commit 9af8cae
Show file tree
Hide file tree
Showing 64 changed files with 731 additions and 294 deletions.
533 changes: 339 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,26 @@ future_incompatible = "warn"
nonstandard_style = "warn"

[workspace.dependencies]
#arma3-wiki = "0.3.2"
arma3-wiki = { git = "https://github.com/acemod/arma3-wiki.git", rev = "cd147399fecd21253cba1e5348b7f0e7d7837948" }
arma3-wiki = "0.3.3"
automod = "1.0.14"
byteorder = "1.5.0"
chumsky = "0.9.3"
clap = "4.5.16"
clap = "4.5.20"
codespan-reporting = { version = "0.11.1", features = ["serialization"] }
git2 = "0.19.0"
indexmap = "2.5.0"
indexmap = "2.6.0"
linkme = "0.3.28"
lsp-types = "0.97.0"
paste = "1.0.15"
peekmore = "1.3.0"
pest = "2.7.11"
pest_derive = "2.7.11"
regex = "1.10.5"
serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.122"
pest = "2.7.13"
pest_derive = "2.7.13"
regex = "1.11.0"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
sha-1 = "0.10.1"
strsim = "0.11.1"
thiserror = "1.0.63"
thiserror = "1.0.64"
toml = "0.8.19"
tower-lsp = "0.20.0"
tracing = { version = "0.1.40", features = ["attributes"] }
Expand Down
7 changes: 4 additions & 3 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hemtt"
description = "HEMTT - Arma 3 Build Tool"
version = "1.13.1"
version = "1.13.2"
edition = "2021"
license = "GPL-2.0"
authors = ["Brett Mayson <[email protected]>"]
Expand Down Expand Up @@ -38,7 +38,7 @@ glob = "0.3.1"
num_cpus = "1.16.0"
rayon = "1.10.0"
regex = { workspace = true }
reqwest = { version = "0.12.7", features = ["blocking", "json"] }
reqwest = { version = "0.12.8", features = ["blocking", "json"] }
rhai = "1.19.0"
rust-embed = "8.5.0"
semver = "1.0.23"
Expand All @@ -50,7 +50,8 @@ tracing = { workspace = true }
tracing-subscriber = { version = "0.3.18", features = ["json"] }
vfs = { workspace = true }
walkdir = { workspace = true }
whoami = "1.5.1"
webbrowser = "1.0.2"
whoami = "1.5.2"
zip = { workspace = true }

[target.'cfg(windows)'.dependencies]
Expand Down
19 changes: 19 additions & 0 deletions bin/src/commands/book.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use clap::{ArgMatches, Command};

use crate::{report::Report, Error};

#[must_use]
pub fn cli() -> Command {
Command::new("book").about("Open The HEMTT book")
}

/// Execute the book command
///
/// # Errors
/// Will not return an error
pub fn execute(_: &ArgMatches) -> Result<Report, Error> {
if let Err(e) = webbrowser::open("https://brettmayson.github.io/HEMTT/") {
eprintln!("Failed to open the HEMTT book: {e}");
}
Ok(Report::new())
}
12 changes: 3 additions & 9 deletions bin/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
context::{self, Context},
error::Error,
executor::Executor,
modules::{pbo::Collapse, Binarize, Files, Hooks, Rapifier, SQFCompiler},
modules::{bom::BOMCheck, pbo::Collapse, Binarize, Files, Hooks, Rapifier, SQFCompiler},
report::Report,
};

Expand Down Expand Up @@ -42,12 +42,6 @@ pub fn add_args(cmd: Command) -> Command {
.help("Use ArmaScriptCompiler instead of HEMTT's SQF compiler")
.action(ArgAction::SetTrue),
)
.arg(
clap::Arg::new("expopti")
.long("expopti")
.help("Use SQFC Optimizer")
.action(ArgAction::SetTrue),
)
}

#[must_use]
Expand Down Expand Up @@ -99,15 +93,15 @@ pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor {
let mut executor = Executor::new(ctx);

let use_asc = matches.get_one::<bool>("asc") == Some(&true);
let use_optimizer = matches.get_one::<bool>("expopti") == Some(&true);

executor.collapse(Collapse::No);

executor.add_module(Box::<BOMCheck>::default());
executor.add_module(Box::<Hooks>::default());
if matches.get_one::<bool>("no-rap") != Some(&true) {
executor.add_module(Box::<Rapifier>::default());
}
executor.add_module(Box::new(SQFCompiler::new(!use_asc, use_optimizer)));
executor.add_module(Box::new(SQFCompiler::new(!use_asc)));
#[cfg(not(target_os = "macos"))]
if use_asc {
executor.add_module(Box::<ArmaScriptCompiler>::default());
Expand Down
3 changes: 2 additions & 1 deletion bin/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
context::Context,
error::Error,
executor::Executor,
modules::{pbo::Collapse, Binarize, Hooks, Rapifier, SQFCompiler},
modules::{bom::BOMCheck, pbo::Collapse, Binarize, Hooks, Rapifier, SQFCompiler},
report::Report,
};

Expand All @@ -28,6 +28,7 @@ pub fn execute() -> Result<Report, Error> {

executor.collapse(Collapse::Yes);

executor.add_module(Box::<BOMCheck>::default());
executor.add_module(Box::<Hooks>::default());
executor.add_module(Box::<Rapifier>::default());
executor.add_module(Box::<SQFCompiler>::default());
Expand Down
14 changes: 5 additions & 9 deletions bin/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{
context::Context,
error::Error,
executor::Executor,
modules::{pbo::Collapse, Binarize, FilePatching, Files, Hooks, Rapifier, SQFCompiler},
modules::{
bom::BOMCheck, pbo::Collapse, Binarize, FilePatching, Files, Hooks, Rapifier, SQFCompiler,
},
report::Report,
};

Expand Down Expand Up @@ -52,12 +54,6 @@ pub fn add_args(cmd: Command) -> Command {
.help("Use ArmaScriptCompiler instead of HEMTT's SQF compiler")
.action(ArgAction::SetTrue),
)
.arg(
clap::Arg::new("expopti")
.long("expopti")
.help("Use SQFC Optimizer")
.action(ArgAction::SetTrue),
)
.arg(
clap::Arg::new("no-rap")
.long("no-rap")
Expand Down Expand Up @@ -137,17 +133,17 @@ pub fn context(
}

let use_asc = matches.get_one::<bool>("asc") == Some(&true);
let use_optimizer = matches.get_one::<bool>("expopti") == Some(&true);

let mut executor = Executor::new(ctx);

executor.collapse(Collapse::Yes);

executor.add_module(Box::<BOMCheck>::default());
executor.add_module(Box::<Hooks>::default());
if rapify && matches.get_one::<bool>("no-rap") != Some(&true) {
executor.add_module(Box::<Rapifier>::default());
}
executor.add_module(Box::new(SQFCompiler::new(!use_asc, use_optimizer)));
executor.add_module(Box::new(SQFCompiler::new(!use_asc)));
#[cfg(not(target_os = "macos"))]
if use_asc {
executor.add_module(Box::<ArmaScriptCompiler>::default());
Expand Down
1 change: 1 addition & 0 deletions bin/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod book;
pub mod build;
pub mod check;
pub mod dev;
Expand Down
4 changes: 3 additions & 1 deletion bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn cli() -> Command {
.version(env!("HEMTT_VERSION"))
.subcommand_required(false)
.arg_required_else_help(true)
.subcommand(commands::book::cli())
.subcommand(commands::new::cli())
.subcommand(commands::check::cli())
.subcommand(commands::dev::cli())
Expand Down Expand Up @@ -133,6 +134,7 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
}
}
let report = match matches.subcommand() {
Some(("book", matches)) => commands::book::execute(matches).map(Some),
Some(("new", matches)) => commands::new::execute(matches).map(Some),
Some(("dev", matches)) => commands::dev::execute(matches, &[]).map(Some),
Some(("check", _matches)) => commands::check::execute().map(Some),
Expand Down Expand Up @@ -166,7 +168,7 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
report.write_to_stdout();
if !matches
.subcommand_name()
.is_some_and(|s| s == "new" || s == "utils")
.is_some_and(|s| s == "new" || s == "utils" || s == "wiki" || s == "book")
{
report.write_ci_annotations()?;
}
Expand Down
75 changes: 75 additions & 0 deletions bin/src/modules/bom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::{io::Read, path::PathBuf, sync::Arc};

use hemtt_workspace::reporting::Code;

use crate::{context::Context, report::Report};

use super::Module;

#[derive(Default)]
pub struct BOMCheck {}

impl Module for BOMCheck {
fn name(&self) -> &'static str {
"BOM Check"
}

fn check(&self, ctx: &Context) -> Result<Report, crate::Error> {
fn files_to_check(root: &PathBuf) -> Vec<PathBuf> {
const IGNORED_EXTENSIONS: [&str; 4] = ["p3d", "rtm", "bin", "paa"];
walkdir::WalkDir::new(root)
.into_iter()
.filter_map(std::result::Result::ok)
.filter(|e| e.file_type().is_file())
.filter(|e| !e.path().display().to_string().contains(".hemttout"))
.filter(|e| {
e.path().extension().map_or(false, |e| {
!IGNORED_EXTENSIONS.contains(&e.to_str().unwrap_or_default())
})
})
.map(|e| e.path().to_path_buf())
.collect::<Vec<_>>()
}
let mut report = Report::new();
for folder in ["addons", "optionals"] {
let folder = ctx.project_folder().join(folder);
if !folder.exists() {
continue;
}
let files = files_to_check(&folder);
for path in files {
let mut buffer = [0; 3];
let mut file = std::fs::File::open(&path)?;
if file.read_exact(&mut buffer).is_err() {
continue;
}
if buffer == [0xEF, 0xBB, 0xBF] {
report.push(Arc::new(BOMError {
file: {
path.display()
.to_string()
.strip_prefix(&ctx.project_folder().display().to_string())
.unwrap_or_default()
.to_string()
},
}));
}
}
}
Ok(report)
}
}

struct BOMError {
file: String,
}

impl Code for BOMError {
fn ident(&self) -> &'static str {
"BOM"
}

fn message(&self) -> String {
format!("File `{}` has a BOM marker", self.file)
}
}
1 change: 1 addition & 0 deletions bin/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{context::Context, error::Error, report::Report};
pub mod asc;

pub mod archive;
pub mod bom;
pub mod hook;
pub mod pbo;

Expand Down
13 changes: 3 additions & 10 deletions bin/src/modules/sqf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ use super::Module;
#[derive(Default)]
pub struct SQFCompiler {
pub compile: bool,
pub optimize: bool,
pub database: Option<Arc<Database>>,
}

impl SQFCompiler {
#[must_use]
pub const fn new(compile: bool, optimize: bool) -> Self {
pub const fn new(compile: bool) -> Self {
Self {
compile,
optimize,
database: None,
}
}
Expand Down Expand Up @@ -102,8 +100,7 @@ impl Module for SQFCompiler {
if !codes.failed() {
if self.compile {
let mut out = entry.with_extension("sqfc")?.create_file()?;
let sqf_to_write = if self.optimize { sqf.optimize() } else { sqf };
sqf_to_write.compile_to_writer(&processed, &mut out)?;
sqf.optimize().compile_to_writer(&processed, &mut out)?;
}
counter.fetch_add(1, Ordering::Relaxed);
}
Expand Down Expand Up @@ -139,11 +136,7 @@ impl Module for SQFCompiler {
info!(
"{} {} sqf files",
if self.compile {
if self.optimize {
"Compiled [Optimized]"
} else {
"Compiled"
}
"Compiled"
} else {
"Validated"
},
Expand Down
2 changes: 1 addition & 1 deletion bin/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn filter_codes(
} else {
!c.include()
&& c.diagnostic()
.map_or(true, |d| !d.labels.iter().any(|l| l.file().is_include()))
.map_or(true, |d| !d.labels.iter().all(|l| l.file().is_include()))
}
})
.cloned()
Expand Down
2 changes: 1 addition & 1 deletion bin/tests/alpha/.hemtt/project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ git_hash = 0
[asc]
enabled = true

[hemtt.launch]
[hemtt.launch.default]
dlc = [
"ws"
]
Expand Down
3 changes: 1 addition & 2 deletions bin/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ fn build_alpha() {
fn build_bravo() {
std::env::set_current_dir(format!("{}/tests/bravo", env!("CARGO_MANIFEST_DIR"))).unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "script", "test"])).unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release", "--in-test", "--expopti"]))
.unwrap();
hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release", "--in-test"])).unwrap();
}
4 changes: 2 additions & 2 deletions book/rhai/library/hemtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ The `HEMTT` constant gives access to information and the ability to modify the b
Returns the version of HEMTT.

```js
HEMTT.version().to_string(); // "1.13.1"
HEMTT.version().to_string(); // "1.13.2"
HEMTT.version().major(); // 1
HEMTT.version().minor(); // 13
HEMTT.version().patch(); // 1
HEMTT.version().patch(); // 2
HEMTT.version().build(); // ""
```

Expand Down
2 changes: 1 addition & 1 deletion book/rhai/library/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ debug(HEMTT.project().version.major());
```

```sh
DEBUG [post_release/test.rhai] "1.13.1"
DEBUG [post_release/test.rhai] "1.13.2"
DEBUG [post_release/test.rhai] 1
```

Expand Down
Loading

0 comments on commit 9af8cae

Please sign in to comment.