Skip to content

Commit

Permalink
check: specify pdrive requirement (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Jun 8, 2024
1 parent 11c5012 commit e0de0c8
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bin/src/commands/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
fn version(ctx: &Context) -> Version {
ctx.config()
.version()
.get(ctx.workspace().vfs())
.get(ctx.workspace_path().vfs())
.unwrap_or_else(|_| {
println!("Unable to find version");
std::process::exit(1);
Expand Down
13 changes: 11 additions & 2 deletions bin/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ impl Context {
let workspace = builder.memory().finish(
Some(config.clone()),
folder.is_some(),
config.hemtt().build().pdrive(),
if folder == Some("check") {
config.hemtt().check().pdrive()
} else {
config.hemtt().build().pdrive()
},
)?;
{
let version = config.version().get(workspace.vfs());
Expand Down Expand Up @@ -173,10 +177,15 @@ impl Context {
}

#[must_use]
pub const fn workspace(&self) -> &WorkspacePath {
pub const fn workspace_path(&self) -> &WorkspacePath {
&self.workspace
}

#[must_use]
pub fn workspace(&self) -> &Workspace {
self.workspace.workspace()
}

#[must_use]
/// The project folder
pub const fn project_folder(&self) -> &PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn release(ctx: &Context) -> Result<Report, Error> {
output.set_file_name(format!(
"{}-{}.zip",
ctx.config().prefix(),
ctx.config().version().get(ctx.workspace().vfs())?
ctx.config().version().get(ctx.workspace_path().vfs())?
));
info!("Created release: {}", output.display());
output
Expand Down
4 changes: 2 additions & 2 deletions bin/src/modules/asc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Module for ArmaScriptCompiler {
let tmp_addon = tmp.join(addon.prefix().as_pathbuf());
create_dir_all(&tmp_addon)?;
let mut entries = Vec::new();
for entry in ctx.workspace().join(addon.folder())?.walk_dir()? {
for entry in ctx.workspace_path().join(addon.folder())?.walk_dir()? {
if entry.is_file()? {
if entry.extension() != sqf_ext {
continue;
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Module for ArmaScriptCompiler {
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().join(&format!("{dst}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);
Expand Down
24 changes: 14 additions & 10 deletions bin/src/modules/binarize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ impl Module for Binarize {

#[allow(clippy::too_many_lines)]
fn check(&self, ctx: &Context) -> Result<Report, Error> {
let pdrive_option = if ctx.folder() == Some(&"check".to_string()) {
ctx.config().hemtt().check().pdrive()
} else {
ctx.config().hemtt().build().pdrive()
};

let mut report = Report::new();
let tmp_source = ctx.tmp().join("source");
let tmp_out = ctx.tmp().join("output");
let search_cache = SearchCache::new();
if let Some(pdrive) = ctx.workspace().workspace().pdrive() {
if let Some(pdrive) = ctx.workspace().pdrive() {
info!("P Drive at {}", pdrive.link().display());
} else if ctx.config().hemtt().build().pdrive() == &PDriveOption::Require {
} else if pdrive_option == &PDriveOption::Require {
report.error(MissingPDrive::code());
}
for addon in ctx.addons() {
Expand All @@ -96,7 +102,7 @@ impl Module for Binarize {
}
}
for entry in ctx
.workspace()
.workspace_path()
.join(addon.folder())
.expect("workspace should be able to join the addon folder")
.walk_dir()
Expand Down Expand Up @@ -154,10 +160,9 @@ impl Module for Binarize {
)
.expect("p3d should be able to be read if it is a valid p3d file");
let (missing_textures, missing_materials) =
p3d.missing(ctx.workspace(), &search_cache)?;
p3d.missing(ctx.workspace_path(), &search_cache)?;
if !missing_textures.is_empty() {
let warn =
*ctx.config().hemtt().build().pdrive() == PDriveOption::Ignore;
let warn = *pdrive_option == PDriveOption::Ignore;
let diag = MissingTextures::code(
entry.as_str().to_string(),
missing_textures,
Expand All @@ -170,8 +175,7 @@ impl Module for Binarize {
}
}
if !missing_materials.is_empty() {
let warn =
*ctx.config().hemtt().build().pdrive() == PDriveOption::Ignore;
let warn = *pdrive_option == PDriveOption::Ignore;
let diag = MissingMaterials::code(
entry.as_str().to_string(),
missing_materials,
Expand Down Expand Up @@ -339,7 +343,7 @@ fn setup_tmp(ctx: &Context) -> Result<(), Error> {
if !include.exists() {
return Ok(());
}
let has_pdrive = ctx.workspace().workspace().pdrive().is_some();
let has_pdrive = ctx.workspace().pdrive().is_some();
let mut warned_a3_include = false;
for outer_prefix in std::fs::read_dir(include)? {
let outer_prefix = outer_prefix?.path();
Expand Down Expand Up @@ -372,7 +376,7 @@ fn setup_tmp(ctx: &Context) -> Result<(), Error> {
if ctx.config().hemtt().build().pdrive() != &PDriveOption::Require {
return Ok(());
}
let Some(pdrive) = ctx.workspace().workspace().pdrive() else {
let Some(pdrive) = ctx.workspace().pdrive() else {
return Ok(());
};
create_link(&tmp.join("a3"), &pdrive.link())?;
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Module for Files {
for file in ctx.config().files().include() {
globs.push(glob::Pattern::new(&file)?);
}
for entry in ctx.workspace().walk_dir()? {
for entry in ctx.workspace_path().walk_dir()? {
if entry.as_str().starts_with("/.hemtt") {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/hook/libraries/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl RhaiProject {
version: ctx
.config()
.version()
.get(ctx.workspace().vfs())
.get(ctx.workspace_path().vfs())
.expect("version config is valid to get to rhai module"),
// addons: ctx.addons().to_vec(),
}
Expand Down
12 changes: 8 additions & 4 deletions bin/src/modules/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod time;
pub fn scope(ctx: &Context, vfs: bool) -> Result<Scope, Error> {
let mut scope = Scope::new();
if vfs {
scope.push_constant("HEMTT_VFS", ctx.workspace().vfs().clone());
scope.push_constant("HEMTT_VFS", ctx.workspace_path().vfs().clone());
}
scope.push_constant("HEMTT_DIRECTORY", ctx.project_folder().clone());
scope.push_constant(
Expand Down Expand Up @@ -82,7 +82,11 @@ impl Hooks {
if !self.0 {
return Ok(());
}
let folder = ctx.workspace().join(".hemtt")?.join("hooks")?.join(name)?;
let folder = ctx
.workspace_path()
.join(".hemtt")?
.join("hooks")?
.join(name)?;
if !folder.exists()? {
trace!("no {} hooks", name);
return Ok(());
Expand Down Expand Up @@ -114,7 +118,7 @@ impl Hooks {
/// If a file path is not a valid [`OsStr`] (UTF-8)
pub fn run_file(ctx: &Context, name: &str) -> Result<Report, Error> {
let mut report = Report::new();
let scripts = ctx.workspace().join(".hemtt")?.join("scripts")?;
let scripts = ctx.workspace_path().join(".hemtt")?.join("scripts")?;
let path = scripts.join(name)?.with_extension("rhai")?;
trace!("running script: {}", path.as_str());
if !path.exists()? {
Expand Down Expand Up @@ -195,7 +199,7 @@ impl Module for Hooks {
for hook in dir.read_dir().expect("hooks folder should be readable") {
let hook = hook?;
let path = ctx
.workspace()
.workspace_path()
.join(".hemtt")?
.join("hooks")?
.join(phase)?
Expand Down
4 changes: 2 additions & 2 deletions bin/src/modules/pbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum Collapse {
/// [`Error::Git`] if the git hash is invalid
/// [`Error::Pbo`] if the PBO fails to write
pub fn build(ctx: &Context, collapse: Collapse) -> Result<Report, Error> {
let version = ctx.config().version().get(ctx.workspace().vfs())?;
let version = ctx.config().version().get(ctx.workspace_path().vfs())?;
let git_hash = {
Repository::discover(".").map_or(None, |repo| {
repo.revparse_single("HEAD").map_or(None, |rev| {
Expand Down Expand Up @@ -109,7 +109,7 @@ fn _build(
pbo.add_property("hemtt", env!("HEMTT_VERSION"));
pbo.add_property("version", version.to_string());

'entries: for entry in ctx.workspace().join(addon.folder())?.walk_dir()? {
'entries: for entry in ctx.workspace_path().join(addon.folder())?.walk_dir()? {
if entry.metadata()?.file_type == VfsFileType::File {
if entry.filename() == "config.cpp" && entry.parent().join("config.bin")?.exists()? {
continue;
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/rapifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Module for Rapifier {
globs.push(glob::Pattern::new(file)?);
}
}
for entry in ctx.workspace().join(addon.folder())?.walk_dir()? {
for entry in ctx.workspace_path().join(addon.folder())?.walk_dir()? {
if entry.metadata()?.file_type == VfsFileType::File
&& can_rapify(entry.as_str())
{
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn get_authority(ctx: &Context, suffix: Option<&str>) -> Result<String, Erro
|| ctx.config().prefix().to_string(),
std::string::ToString::to_string
),
ctx.config().version().get(ctx.workspace().vfs())?
ctx.config().version().get(ctx.workspace_path().vfs())?
);
if let Some(suffix) = suffix {
authority.push_str(&format!("_{suffix}"));
Expand Down
4 changes: 2 additions & 2 deletions bin/src/modules/sqf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Module for SQFCompiler {
let counter = AtomicU16::new(0);
let mut entries = Vec::new();
for addon in ctx.addons() {
for entry in ctx.workspace().join(addon.folder())?.walk_dir()? {
for entry in ctx.workspace_path().join(addon.folder())?.walk_dir()? {
if entry.is_file()? {
if entry.extension() != sqf_ext || entry.filename().ends_with(".inc.sqf") {
continue;
Expand All @@ -37,7 +37,7 @@ impl Module for SQFCompiler {
}
}
}
let database = Database::a3_with_workspace(ctx.workspace())?;
let database = Database::a3_with_workspace(ctx.workspace_path())?;
let reports = entries
.par_iter()
.map(|(addon, entry)| {
Expand Down
23 changes: 23 additions & 0 deletions book/configuration/p-drive.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ Whenever possible, an `.\include\` folder should be used in place of a P Drive.

The most common use case is for CBA's script_macros_common.hpp, you can see an example of this in [ACE's GitHub Repo](https://github.com/acemod/ACE3/tree/master/include/x/cba/addons/main/script_macros_common.hpp).

## Default Behaviour, Ignored

By default, HEMTT will allow references to a P Drive, but will not fail the build if it does not exist. Even if a P Drive exists, it **will not** be used by HEMTT unless explicitly required by the project.

## Disallowing P Drive

If a P Drive is explicitly disallowed by the project, it can specify as such.

**.hemtt/project.toml**

```toml
[hemtt.build]
pdrive = "disallow"

[hemtt.check]
pdrive = "ignore"
```

When disallowed by the project, HEMTT will fail to build the project if any references to a P Drive are found.

## Requiring P Drive

If a P Drive is required by the project, it **must** specify as such. If the flag is not set, HEMTT will not allow the P Drive to be used.
Expand All @@ -19,6 +39,9 @@ If a P Drive is required by the project, it **must** specify as such. If the fla
```toml
[hemtt.build]
pdrive = "require"

[hemtt.check]
pdrive = "ignore"
```

When required by the project, HEMTT will fail to build the project if all required files can not be resolved. HEMTT will only enable use of `P:\a3\`.
Expand Down
2 changes: 1 addition & 1 deletion libs/common/src/arma/dlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum DLC {
/// Creator DLC: Spearhead 1944
/// <https://store.steampowered.com/app/1175380/Arma_3_Creator_DLC_Spearhead_1944/>
Spearhead1944,
#[serde(rename="rf")]
#[serde(rename = "rf")]
/// Creator DLC: Reaction Forces
/// <https://store.steampowered.com/app/2647760/Arma_3_Creator_DLC_Reaction_Forces/>
ReactionForces,
Expand Down
28 changes: 27 additions & 1 deletion libs/common/src/project/hemtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub struct Features {
#[serde(default)]
dev: DevOptions,

#[serde(default)]
check: CheckOptions,

#[serde(default)]
launch: HashMap<String, LaunchOptions>,

Expand All @@ -28,6 +31,12 @@ impl Features {
&self.dev
}

#[must_use]
/// Check options
pub const fn check(&self) -> &CheckOptions {
&self.check
}

#[must_use]
/// Get launch options by key
pub fn launch(&self, key: &str) -> Option<LaunchOptions> {
Expand Down Expand Up @@ -88,6 +97,23 @@ impl DevOptions {
}
}

#[derive(PartialEq, Eq, Debug, Default, Clone, Serialize, Deserialize)]
/// Dev specific configuration
pub struct CheckOptions {
#[serde(default)]
/// Can includes come from the P drive?
/// Default: false
pdrive: PDriveOption,
}

impl CheckOptions {
#[must_use]
/// Can includes come from the P drive?
pub const fn pdrive(&self) -> &PDriveOption {
&self.pdrive
}
}

#[derive(PartialEq, Eq, Debug, Default, Clone, Serialize, Deserialize)]
/// Launch specific configuration
pub struct LaunchOptions {
Expand Down Expand Up @@ -243,7 +269,7 @@ impl BuildOptions {
}
}

#[derive(Default, PartialEq, Eq, Debug, Clone)]
#[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
pub enum PDriveOption {
Disallow,
#[default]
Expand Down

0 comments on commit e0de0c8

Please sign in to comment.