Skip to content

Commit

Permalink
make consistent preprocess in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Oct 15, 2023
1 parent dd39247 commit 42a04d5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 51 deletions.
10 changes: 5 additions & 5 deletions bin/src/modules/rapifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ impl Module for Rapifier {
.map(|addon| {
let mut globs = Vec::new();
if let Some(config) = addon.config() {
if !config.preprocess().enabled() {
debug!("preprocessing disabled for {}", addon.name());
if !config.rapify().enabled() {
debug!("rapify disabled for {}", addon.name());
return Ok((vec![], Ok(())));
}
for file in config.preprocess().exclude() {
for file in config.rapify().exclude() {
globs.push(glob::Pattern::new(file)?);
}
}
let mut messages = Vec::new();
let mut res = Ok(());
for entry in ctx.workspace().join(addon.folder())?.walk_dir()? {
if entry.metadata()?.file_type == VfsFileType::File
&& can_preprocess(entry.as_str())
&& can_rapify(entry.as_str())
{
if globs
.iter()
Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn rapify(path: WorkspacePath, ctx: &Context) -> (Vec<String>, Result<(), Er
(messages, Ok(()))
}

pub fn can_preprocess(path: &str) -> bool {
pub fn can_rapify(path: &str) -> bool {
let path = PathBuf::from(path);
let name = path
.extension()
Expand Down
6 changes: 4 additions & 2 deletions book/commands/build.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# build

# hemtt build

<pre><code>Build your project
Expand Down Expand Up @@ -47,6 +45,10 @@ By default, `hemtt build` will create separate mods for each optional mod folder

Do not binarize any files. They will be copied directly into the PBO. `config.cpp`, `*.rvmat`, `*.ext` will still be rapified.

This can be configured per addon in [`addon.toml`](../configuration/addon.md#binarize).

### --no-rap

Do not rapify any files. They will be copied directly into the PBO.

This can be configured per addon in [`addon.toml`](../configuration/addon.md#rapify).
12 changes: 6 additions & 6 deletions book/configuration/addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exclude = [
"data/anim/chop.rtm",
]

[preprocess]
[rapify]
enabled = false # Default: true
exclude = [
"missions/**/description.ext",
Expand All @@ -29,7 +29,7 @@ iso = "14001"

## binarize

HEMTT's binarization of addons can be disabled entirely by setting `binarize.enabled` to `false`, or disabled for specific files by adding glob patterns to `binarize.exclude`.
HEMTT's binarization of addons can be disabled for the addon by setting `binarize.enabled` to `false`, or disabled for specific files by adding glob patterns to `binarize.exclude`.

**_/addons/banana/addon.toml_**

Expand All @@ -42,16 +42,16 @@ exclude = [
]
```

## preprocess
## rapify

HEMTT's preprocessing of addons can be disabled entirely by setting `preprocess.enabled` to `false`, or disabled for specific files by adding glob patterns to `preprocess.exclude`.
HEMTT's preprocessing & rapifying of addon configs can be disabled for the addon by setting `rapify.enabled` to `false`, or disabled for specific files by adding glob patterns to `rapify.exclude`.

When it is required to disable preprocessing of `config.cpp`, it is recommended to create a separate addon to house any optional config, with the minimum amount of code required to make it work. Disabling preprocessing will allow you to ship invalid config, which could cause issues for your players. It will also cause slower load times when the config is valid.
When it is required to disable preprocessing & rapifying of `config.cpp`, it is recommended to create a separate addon to house any optional config, with the minimum amount of code required to make it work. Disabling preprocessing & rapifying will allow you to ship invalid config, which could cause issues for your players. It will also cause slower load times when the config is valid.

**_/addons/banana/addon.toml_**

```toml
[preprocess]
[rapify]
enabled = false # Default: true
exclude = [
"missions/**/description.ext",
Expand Down
16 changes: 10 additions & 6 deletions book/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ The latest HEMTT release can be downloaded from the [GitHub releases page](https

Builds are available for Windows and Linux.

## Installation (Project Local)
## Installation (Winget)

The HEMTT executable can be placed in the root of your project, and used from there. It is strongly recommended not to add it to your version control system.
HEMTT can be installed using [Winget](https://github.com/microsoft/winget-cli).

HEMTT can then be ran from a terminal in the root of your project with `.\hemtt.exe` on Windows, or `./hemtt` on Linux.
```powershell
winget install hemtt
```

## Installation (Global)
## Manual Installation (Global)

HEMTT can be installed globally on your system, and used from anywhere.

The HEMTT executable can be placed in any directory on your system, and added to your `PATH` environment variable.

HEMTT can then be ran from any terminal with `hemtt`.

## Crates
## Manual Installation (Project Local)

If you have [Rust](https://www.rust-lang.org/) installed, you can install HEMTT from [crates.io](https://crates.io/crates/hemtt) with `cargo install hemtt`.
The HEMTT executable can be placed in the root of your project, and used from there. It is strongly recommended not to add it to your version control system.

HEMTT can then be ran from a terminal in the root of your project with `.\hemtt.exe` on Windows, or `./hemtt` on Linux.

## Compile from Source

Expand Down
46 changes: 14 additions & 32 deletions libs/common/src/project/addon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ use crate::error::Error;
/// Configuration for an addon
pub struct AddonConfig {
#[serde(default)]
#[serde(alias = "preprocess")]
/// Preprocess config
preprocess: Option<PreprocessCompatibility>,
rapify: RapifyConfig,

#[serde(default)]
/// A list of files to skip binarizing
no_bin: Vec<String>,

#[serde(default)]
/// Binarze config
binarize: BinarizeConfig,
Expand All @@ -35,19 +37,9 @@ pub struct AddonConfig {

impl AddonConfig {
#[must_use]
/// Preprocess config
pub fn preprocess(&self) -> PreprocessConfig {
match &self.preprocess {
Some(PreprocessCompatibility::Deprecated(enabled)) => PreprocessConfig {
enabled: *enabled,
exclude: Vec::new(),
},
Some(PreprocessCompatibility::New(config)) => config.clone(),
None => PreprocessConfig {
enabled: false,
exclude: Vec::new(),
},
}
/// Rapify config
pub const fn rapify(&self) -> &RapifyConfig {
&self.rapify
}

#[must_use]
Expand All @@ -66,6 +58,9 @@ impl AddonConfig {
/// file does not contain a valid configuration, an error is returned.
pub fn from_file(path: &Path) -> Result<Self, Error> {
let file = std::fs::read_to_string(path)?;
if file.contains("[preprocess]") {
warn!("`[preprocess]` is deprecated, use `[rapify]` instead. See <https://brettmayson.github.io/HEMTT/configuration/addon> for more information.");
}
let config = Self::from_str(&file);
if let Ok(inner) = config.as_ref() {
if !inner.exclude.is_empty() {
Expand All @@ -74,9 +69,6 @@ impl AddonConfig {
if !inner.no_bin.is_empty() {
warn!("`no_bin` is deprecated, use `binarize.exclude` instead. See <https://brettmayson.github.io/HEMTT/configuration/addon> for more information.");
}
if let Some(PreprocessCompatibility::Deprecated(_)) = inner.preprocess {
warn!("`preprocess` as a field is deprecated, use a `preprocess` object instead. See <https://brettmayson.github.io/HEMTT/configuration/addon> for more information.");
}
}
config
}
Expand Down Expand Up @@ -104,30 +96,20 @@ impl FromStr for AddonConfig {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
/// Preprocess compatibility config
pub enum PreprocessCompatibility {
/// Deprecated bool
Deprecated(bool),
/// New config
New(PreprocessConfig),
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
/// Preprocess config
pub struct PreprocessConfig {
pub struct RapifyConfig {
#[serde(default)]
enabled: bool,
enabled: Option<bool>,
#[serde(default)]
exclude: Vec<String>,
}

impl PreprocessConfig {
impl RapifyConfig {
#[must_use]
/// Is preprocess enabled
pub const fn enabled(&self) -> bool {
self.enabled
pub fn enabled(&self) -> bool {
self.enabled.unwrap_or(true)
}

#[must_use]
Expand Down

0 comments on commit 42a04d5

Please sign in to comment.