Skip to content

Commit

Permalink
Merge branch 'main' into notnot
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed Oct 22, 2024
2 parents 8656e9c + d23d6e6 commit 82f29fa
Show file tree
Hide file tree
Showing 66 changed files with 825 additions and 312 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ jobs:
name: linux-x64
path: release

- name: Zip Linux x64
run: |
cd release && zip linux-x64.zip hemtt && rm hemtt
- name: Rename Linux x64
run: |
cd release && mv hemtt linux-x64
Expand All @@ -153,6 +157,10 @@ jobs:
name: macos-x64
path: release

- name: Zip MacOS x64
run: |
cd release && zip macos-x64.zip hemtt && rm hemtt
- name: Rename MacOS x64
run: |
cd release && mv hemtt darwin-x64
Expand Down
34 changes: 33 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dirs = { workspace = true }
fs_extra = "1.3.0"
git2 = { workspace = true }
glob = "0.3.1"
indicatif = "0.17.8"
num_cpus = "1.16.0"
paste = { workspace = true }
rayon = "1.10.0"
Expand Down
8 changes: 4 additions & 4 deletions bin/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use crate::{
context::{self, Context},
error::Error,
executor::Executor,
modules::{bom::BOMCheck, pbo::Collapse, Binarize, Files, Hooks, Rapifier, SQFCompiler},
modules::{pbo::Collapse, Binarize, Files, Rapifier},
report::Report,
};

use super::global_modules;

#[must_use]
pub fn cli() -> Command {
add_just(add_args(
Expand Down Expand Up @@ -82,15 +84,13 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
#[must_use]
pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor {
let mut executor = Executor::new(ctx);
global_modules(&mut executor);

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::default()));
if matches.get_one::<bool>("no-bin") != Some(&true) {
executor.add_module(Box::<Binarize>::default());
}
Expand Down
7 changes: 3 additions & 4 deletions bin/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use clap::Command;

use crate::{
commands::global_modules,
context::Context,
error::Error,
executor::Executor,
modules::{bom::BOMCheck, pbo::Collapse, Binarize, Hooks, Rapifier, SQFCompiler},
modules::{pbo::Collapse, Binarize, Rapifier},
report::Report,
};

Expand All @@ -25,13 +26,11 @@ pub fn execute() -> Result<Report, Error> {
)?;

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

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());
executor.add_module(Box::<Binarize>::new(Binarize::new(true)));

info!("Running checks");
Expand Down
9 changes: 3 additions & 6 deletions bin/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use clap::{ArgAction, ArgMatches, Command};
use hemtt_workspace::addons::Location;

use crate::{
commands::global_modules,
context::Context,
error::Error,
executor::Executor,
modules::{
bom::BOMCheck, pbo::Collapse, Binarize, FilePatching, Files, Hooks, Rapifier, SQFCompiler,
},
modules::{pbo::Collapse, Binarize, FilePatching, Files, Rapifier},
report::Report,
};

Expand Down Expand Up @@ -124,15 +123,13 @@ pub fn context(
}

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

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::default()));
executor.add_module(Box::<Files>::default());
executor.add_module(Box::<FilePatching>::default());
if force_binarize || matches.get_one::<bool>("binarize") == Some(&true) {
Expand Down
12 changes: 12 additions & 0 deletions bin/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ pub mod script;
pub mod utils;
pub mod value;
pub mod wiki;

/// Adds modules that should apply to:
/// - hemtt check
/// - hemtt dev
/// - hemtt build
/// - hemtt release
pub fn global_modules(executor: &mut crate::executor::Executor) {
executor.add_module(Box::<crate::modules::bom::BOMCheck>::default());
executor.add_module(Box::<crate::modules::Hooks>::default());
executor.add_module(Box::<crate::modules::Stringtables>::default());
executor.add_module(Box::<crate::modules::SQFCompiler>::default());
}
1 change: 1 addition & 0 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod executor;
pub mod link;
pub mod logging;
pub mod modules;
mod progress;
pub mod report;
pub mod update;
pub mod utils;
Expand Down
34 changes: 28 additions & 6 deletions bin/src/modules/archive.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use std::fs::{create_dir_all, File};
use std::{
fs::{create_dir_all, File},
path::PathBuf,
};

use walkdir::WalkDir;
use zip::{write::SimpleFileOptions, ZipWriter};

use crate::{context::Context, error::Error, report::Report};
use crate::{context::Context, error::Error, progress::progress_bar, report::Report};

enum Entry {
File(String, PathBuf),
Directory(String),
}

/// Creates the release zips
///
Expand All @@ -27,7 +35,7 @@ pub fn release(ctx: &Context) -> Result<Report, Error> {
let options = SimpleFileOptions::default().compression_level(Some(9));

debug!("creating release at {:?}", output.display());
let mut zip = ZipWriter::new(File::create(&output)?);
let mut to_write = Vec::new();
for entry in WalkDir::new(ctx.build_folder().expect("build folder exists")) {
let Ok(entry) = entry else {
continue;
Expand All @@ -48,7 +56,7 @@ pub fn release(ctx: &Context) -> Result<Report, Error> {
path.replace('\\', "/")
);
trace!("zip: creating directory {:?}", dir);
zip.add_directory(dir, options)?;
to_write.push(Entry::Directory(dir));
continue;
}
let name = path
Expand All @@ -60,9 +68,23 @@ pub fn release(ctx: &Context) -> Result<Report, Error> {
name.display().to_string().replace('\\', "/")
);
trace!("zip: adding file {:?}", file);
zip.start_file(file, options)?;
std::io::copy(&mut File::open(path)?, &mut zip)?;
to_write.push(Entry::File(file, path.to_owned()));
}
let progress = progress_bar(to_write.len() as u64).with_message("Creating release");
let mut zip = ZipWriter::new(File::create(&output)?);
for entry in to_write {
match entry {
Entry::File(file, path) => {
zip.start_file(file, options)?;
std::io::copy(&mut File::open(path)?, &mut zip)?;
}
Entry::Directory(dir) => {
zip.add_directory(dir, options)?;
}
}
progress.inc(1);
}
progress.finish_and_clear();
zip.finish()?;
info!("Created release: {}", output.display());
std::fs::copy(&output, {
Expand Down
14 changes: 10 additions & 4 deletions bin/src/modules/binarize/error/bbw1_tools_not_found.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ impl Code for ToolsNotFound {
}

fn message(&self) -> String {
String::from("Arma 3 Tools not found in registry.")
String::from("Arma 3 Tools not found.")
}

fn help(&self) -> Option<String> {
Some(String::from(
"Install Arma 3 Tools from Steam and run them at least once.",
))
if cfg!(windows) {
Some(String::from(
"Install Arma 3 Tools from Steam and run them at least once.",
))
} else {
Some(String::from(
"Install Arma 3 Tools, and ensure either `wine64` or Proton Sniper is installed.",
))
}
}

fn diagnostic(&self) -> Option<Diagnostic> {
Expand Down
13 changes: 12 additions & 1 deletion bin/src/modules/binarize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Module for Binarize {

#[cfg(not(windows))]
fn init(&mut self, ctx: &Context) -> Result<Report, Error> {
use dirs::home_dir;
use hemtt_common::steam;

let mut report = Report::new();
Expand Down Expand Up @@ -117,7 +118,17 @@ impl Module for Binarize {
let mut cmd = Command::new("wine64");
cmd.arg("--version");
if cmd.output().is_err() {
self.proton = true;
if home_dir()
.expect("home directory exists")
.join(".local/share/Steam/steamapps/common/SteamLinuxRuntime_sniper/run")
.exists()
{
self.proton = true;
} else {
debug!("tools found, but not wine64 or proton");
report.push(ToolsNotFound::code(Severity::Warning));
self.command = None;
}
}
} else {
report.push(ToolsNotFound::code(Severity::Warning));
Expand Down
17 changes: 13 additions & 4 deletions bin/src/modules/files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fs::create_dir_all;

use crate::{context::Context, error::Error, report::Report};
use crate::{context::Context, error::Error, progress::progress_bar, report::Report};

use super::Module;

Expand All @@ -17,7 +17,7 @@ impl Module for Files {
require_literal_separator: true,
..Default::default()
};
let mut copied = 0;
let mut to_copy = Vec::new();
let mut globs = Vec::new();
for file in ctx.config().files().include() {
globs.push(glob::Pattern::new(file)?);
Expand Down Expand Up @@ -47,10 +47,19 @@ impl Module for Files {
if !folder.exists() {
std::mem::drop(create_dir_all(folder));
}
debug!("copying {:?} => {:?}", entry.as_str(), d.display());
std::io::copy(&mut entry.open_file()?, &mut std::fs::File::create(&d)?)?;
to_copy.push((entry, d));
}

let mut copied = 0;
let progress = progress_bar(to_copy.len() as u64).with_message("Copying files");
for (source, dest) in to_copy {
debug!("copying {:?} => {:?}", source.as_str(), dest.display());
progress.set_message(format!("Copying {}", source.as_str()));
std::io::copy(&mut source.open_file()?, &mut std::fs::File::create(&dest)?)?;
copied += 1;
progress.inc(1);
}
progress.finish_and_clear();
info!("Copied {} files", copied);
Ok(Report::new())
}
Expand Down
Loading

0 comments on commit 82f29fa

Please sign in to comment.