Skip to content

Commit ceb7507

Browse files
committed
working on cli, but not hls
1 parent be0feb1 commit ceb7507

File tree

19 files changed

+242
-114
lines changed

19 files changed

+242
-114
lines changed

Cargo.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "hemtt"
33
description = "HEMTT - Arma 3 Build Tool"
4-
version = "1.18.1"
4+
version = "1.19.0"
55
edition = "2024"
66
license = "GPL-2.0"
77
authors = ["Brett Mayson <brett@mayson.io>"]

bin/src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod photoshoot;
2424
pub fn global_modules(executor: &mut crate::executor::Executor) {
2525
executor.add_module(Box::<crate::modules::bom::BOMCheck>::default());
2626
executor.add_module(Box::<crate::modules::fnl::FineNewLineCheck>::default());
27+
executor.add_module(Box::<crate::modules::preprocess::PreProcess>::default());
2728
executor.add_module(Box::<crate::modules::Hooks>::default());
2829
executor.add_module(Box::<crate::modules::Stringtables>::default());
2930
executor.add_module(Box::<crate::modules::SQFCompiler>::default());

bin/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl Context {
286286
.version()
287287
.get(self.workspace_path().vfs())
288288
.expect("version config is valid to get to rhai module"),
289-
// addons: self.addons().to_vec(),
289+
addons: self.addons().to_vec(),
290290
}
291291
}
292292
}

bin/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub enum Error {
3939

4040
#[error("Preprocessor not found: {0}")]
4141
PreprocessorNotFound(String),
42+
#[error("Preprocessor did not return a string: {0}")]
43+
PreprocessorDidNotReturnString(String),
44+
#[error("Preprocessor error in '{0}': {1}")]
45+
PreprocessorError(String, String),
4246

4347
#[error("Dialoguer Error: {0}")]
4448
Dialoguer(#[from] dialoguer::Error),

bin/src/modules/hook/error/bhe4_runtime_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct RuntimeError {
1616

1717
impl Code for RuntimeError {
1818
fn ident(&self) -> &'static str {
19-
"BHE3"
19+
"BHE4"
2020
}
2121

2222
fn message(&self) -> String {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::sync::Arc;
2+
3+
use hemtt_workspace::{
4+
WorkspacePath,
5+
reporting::{Code, Diagnostic, Label},
6+
};
7+
use rhai::Position;
8+
9+
use super::get_offset;
10+
11+
pub struct RuntimeFatal {
12+
script: WorkspacePath,
13+
error: String,
14+
location: Position,
15+
}
16+
17+
impl Code for RuntimeFatal {
18+
fn ident(&self) -> &'static str {
19+
"BHE5"
20+
}
21+
22+
fn message(&self) -> String {
23+
format!("Script {} intentionally failed at runtime", self.script)
24+
}
25+
26+
fn diagnostic(&self) -> Option<Diagnostic> {
27+
let content = self.script.read_to_string().ok()?;
28+
Some(
29+
Diagnostic::from_code(self).with_label(
30+
Label::primary(
31+
self.script.clone(),
32+
get_offset(&content, self.location)..get_offset(&content, self.location),
33+
)
34+
.with_message({
35+
let mut chars = self.error.chars();
36+
chars.next().map_or_else(
37+
|| self.error.clone(),
38+
|first| first.to_lowercase().collect::<String>() + chars.as_str(),
39+
)
40+
}),
41+
),
42+
)
43+
}
44+
}
45+
46+
impl RuntimeFatal {
47+
pub fn code(script: WorkspacePath, error: String, location: Position) -> Arc<dyn Code> {
48+
Arc::new(Self {
49+
script,
50+
error,
51+
location,
52+
})
53+
}
54+
}

bin/src/modules/hook/error/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rhai::Position;
55
pub mod bhe1_script_not_found;
66
pub mod bhe3_parse_error;
77
pub mod bhe4_runtime_error;
8+
pub mod bhe5_runtime_fatal;
89

910
fn get_offset(content: &str, location: Position) -> usize {
1011
let mut offset = 0;

bin/src/modules/hook/mod.rs

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use ::rhai::{Engine, Scope, packages::Package};
2-
use hemtt_rhai::libraries::{RfsPackage, VfsPackage};
2+
use hemtt_rhai::libraries::VfsPackage;
33
use hemtt_workspace::WorkspacePath;
4-
use rhai::{Dynamic, EvalAltResult};
4+
use rhai::Dynamic;
55
use whoami::Result;
66

77
use crate::{
8-
context::Context, error::Error, modules::hook::libraries::hemtt::RhaiHemtt, report::Report,
8+
context::Context,
9+
error::Error,
10+
modules::hook::{error::bhe5_runtime_fatal::RuntimeFatal, libraries::hemtt::RhaiHemtt},
11+
report::Report,
912
};
1013

1114
use self::error::{
@@ -25,34 +28,34 @@ mod libraries;
2528
///
2629
/// # Panics
2730
/// If the build folder does not exist
28-
pub fn scope(ctx: &'_ Context, vfs: bool) -> Result<Scope<'_>, Error> {
31+
pub fn scope(ctx: &'_ Context, hemtt: bool, vfs: bool) -> Result<Scope<'_>, Error> {
2932
let mut scope = Scope::new();
3033
if vfs {
3134
scope.push_constant("HEMTT_VFS", ctx.workspace_path().vfs().clone());
3235
}
33-
scope.push_constant("HEMTT_DIRECTORY", ctx.project_folder().clone());
34-
scope.push_constant(
35-
"HEMTT_OUTPUT",
36-
ctx.build_folder().expect("build folder exists").clone(),
37-
);
3836
scope.push_constant("HEMTT_RFS", ctx.project_folder().clone());
39-
scope.push_constant(
40-
"HEMTT_OUT",
41-
ctx.build_folder().expect("build folder exists").clone(),
42-
);
4337

44-
scope.push_constant("HEMTT", RhaiHemtt::new(ctx));
38+
if hemtt {
39+
scope.push_constant(
40+
"HEMTT_OUTPUT",
41+
ctx.build_folder().expect("build folder exists").clone(),
42+
);
43+
scope.push_constant(
44+
"HEMTT_OUT",
45+
ctx.build_folder().expect("build folder exists").clone(),
46+
);
47+
scope.push_constant("HEMTT", RhaiHemtt::new(ctx));
48+
}
4549

4650
Ok(scope)
4751
}
4852

49-
fn engine(vfs: bool) -> Engine {
50-
let mut engine = hemtt_rhai::engine();
53+
fn engine(name: String, vfs: bool) -> Engine {
54+
let mut engine = hemtt_rhai::engine(name);
5155
if vfs {
5256
let virt = VfsPackage::new();
5357
engine.register_static_module("hemtt_vfs", virt.as_shared_module());
5458
}
55-
engine.register_static_module("hemtt_rfs", RfsPackage::new().as_shared_module());
5659
engine.register_static_module("hemtt", libraries::HEMTTPackage::new().as_shared_module());
5760
engine
5861
}
@@ -102,6 +105,9 @@ impl Hooks {
102105
);
103106
report.merge(Self::run(ctx, file, vfs)?.0);
104107
ctx.config().version().invalidate();
108+
if report.failed() {
109+
break;
110+
}
105111
}
106112
Ok(report)
107113
}
@@ -132,45 +138,24 @@ impl Hooks {
132138
#[allow(clippy::needless_pass_by_value)] // rhai things
133139
fn run(ctx: &Context, path: WorkspacePath, vfs: bool) -> Result<(Report, Dynamic), Error> {
134140
let mut report = Report::new();
135-
let mut engine = engine(vfs);
136-
let mut scope = scope(ctx, vfs)?;
137141
let parts = path.as_str().split('/');
138142
let name = parts
139143
.clone()
140144
.skip(parts.count().saturating_sub(2))
141145
.collect::<Vec<_>>()
142146
.join("/");
143-
let inner_name = name.clone();
144-
engine.on_debug(move |x, _src, _pos| {
145-
debug!("[{inner_name}] {x}");
146-
});
147-
let inner_name = name.clone();
148-
engine.on_print(move |s| {
149-
info!("[{inner_name}] {s}");
150-
});
151-
let inner_name = name.clone();
152-
engine.register_fn("info", move |s: &str| {
153-
info!("[{inner_name}] {s}");
154-
});
155-
let inner_name = name.clone();
156-
engine.register_fn("warn", move |s: &str| {
157-
warn!("[{inner_name}] {s}");
158-
});
159-
let inner_name = name.clone();
160-
engine.register_fn("error", move |s: &str| {
161-
error!("[{inner_name}] {s}");
162-
});
163-
let inner_name = name;
164-
engine.register_fn("fatal", move |s: &str| -> Result<(), Box<EvalAltResult>> {
165-
error!("[{inner_name}] {s}");
166-
Err(Box::new(EvalAltResult::ErrorRuntime(
167-
"Script called fatal".into(),
168-
rhai::Position::NONE,
169-
)))
170-
});
147+
let engine = engine(name, vfs);
148+
let mut scope = scope(ctx, true, vfs)?;
171149
match engine.eval_with_scope(&mut scope, &path.read_to_string()?) {
172150
Err(e) => {
173-
report.push(RuntimeError::code(path, &e));
151+
match *e {
152+
rhai::EvalAltResult::ErrorTerminated(message, pos) => {
153+
report.push(RuntimeFatal::code(path, message.to_string(), pos));
154+
}
155+
_ => {
156+
report.push(RuntimeError::code(path, &e));
157+
}
158+
}
174159
Ok((report, Dynamic::UNIT))
175160
}
176161
Ok(ret) => Ok((report, ret)),
@@ -188,7 +173,7 @@ impl Module for Hooks {
188173
self.0 = ctx.hemtt_folder().join("hooks").exists();
189174
if self.0 {
190175
for phase in &["pre_build", "post_build", "pre_release", "post_release"] {
191-
let engine = engine(phase != &"post_release");
176+
let engine = engine(String::from(*phase), phase != &"post_release");
192177
let dir = ctx.hemtt_folder().join("hooks").join(phase);
193178
if !dir.exists() {
194179
continue;

0 commit comments

Comments
 (0)