Skip to content

Commit

Permalink
preprocessor: prefix in __file__
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Oct 15, 2023
1 parent 9e7167c commit 6850bea
Show file tree
Hide file tree
Showing 46 changed files with 104 additions and 947 deletions.
18 changes: 3 additions & 15 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ members = [
"libs/config",
"libs/pbo",
"libs/preprocessor",
"libs/project",
"libs/signing",
]
resolver = "2"
Expand Down
1 change: 0 additions & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ hemtt-common = { path = "../libs/common", version = "1.0.0" }
hemtt-config = { path = "../libs/config", version = "1.0.0" }
hemtt-pbo = { path = "../libs/pbo", version = "1.0.1" }
hemtt-preprocessor = { path = "../libs/preprocessor", version = "1.0.0" }
hemtt-project = { path = "../libs/project", version = "1.0.0" }
hemtt-signing = { path = "../libs/signing", version = "1.0.0" }

ariadne = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion bin/src/addons.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fs::DirEntry, path::PathBuf, str::FromStr};

use hemtt_common::prefix::{self, Prefix};
use hemtt_project::AddonConfig;
use hemtt_common::project::AddonConfig;

use crate::error::Error;

Expand Down
2 changes: 1 addition & 1 deletion bin/src/commands/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use clap::{ArgMatches, Command};
use hemtt_project::{hemtt::LaunchOptions, ProjectConfig};
use hemtt_common::project::{hemtt::LaunchOptions, ProjectConfig};
use steamlocate::SteamDir;

use crate::{error::Error, utils::create_link};
Expand Down
6 changes: 3 additions & 3 deletions bin/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
path::PathBuf,
};

use hemtt_common::project::ProjectConfig;
use hemtt_common::workspace::{Workspace, WorkspacePath};
use hemtt_project::ProjectConfig;

use crate::{addons::Addon, error::Error};

Expand Down Expand Up @@ -77,11 +77,11 @@ impl Context {
if include.is_dir() {
builder = builder.physical(&include);
}
builder.memory().finish()?
builder.memory().finish(Some(config.clone()))?
};
{
let version = config.version().get(workspace.vfs());
if let Err(hemtt_project::Error::Git(_)) = version {
if let Err(hemtt_common::project::Error::Git(_)) = version {
error!("Failed to find a git repository with at least one commit, if you are not using git add the following to your project.toml");
println!("\n[version]\ngit_hash = 0\n");
std::process::exit(1);
Expand Down
2 changes: 1 addition & 1 deletion bin/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum Error {
#[error("Prefix error: {0}")]
Prefix(#[from] hemtt_common::prefix::Error),
#[error("`a hemtt project file is invalid: {0}")]
Project(#[from] hemtt_project::Error),
Project(#[from] hemtt_common::project::Error),
#[error("Signing error: {0}")]
Signing(#[from] hemtt_signing::Error),
#[error("Version Error: {0}")]
Expand Down
3 changes: 3 additions & 0 deletions libs/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ description = "A library for common Hemtt functionality"
license = "GPL-2.0"

[dependencies]
ariadne = { workspace = true }
git2 = { workspace = true }
serde = { workspace = true }
thiserror = "1.0.49"
toml = { workspace = true }
tracing = { workspace = true }
vfs = { workspace = true }
2 changes: 1 addition & 1 deletion libs/common/src/arma/dlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize)]
#[derive(PartialEq, Eq, Clone, Debug, Serialize)]
/// DLCs that require opt-in.
pub enum DLC {
#[serde(rename = "contact")]
Expand Down
27 changes: 27 additions & 0 deletions libs/common/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
//! HEMTT - Error Types
#![allow(missing_docs)]

pub use thiserror;

#[derive(thiserror::Error, Debug)]
/// HEMTT Error
pub enum Error {
#[error("Invalid config: {0}")]
/// Invalid config
ConfigInvalid(String),

#[error("Git Error: {0}")]
Git(#[from] git2::Error),
#[error("IO Error: {0}")]
Io(#[from] std::io::Error),
#[error("Toml Error: {0}")]
Toml(#[from] toml::de::Error),
#[error("Version Error: {0}")]
Version(#[from] crate::version::Error),
#[error("Vfs Error {0}")]
Vfs(Box<vfs::VfsError>),
}

impl From<vfs::VfsError> for Error {
fn from(e: vfs::VfsError) -> Self {
Self::Vfs(Box::new(e))
}
}
4 changes: 4 additions & 0 deletions libs/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub mod io;
pub mod math;
pub mod position;
pub mod prefix;
pub mod project;
pub mod reporting;
pub mod version;
pub mod workspace;

mod sign_version;
pub use sign_version::BISignVersion;
19 changes: 15 additions & 4 deletions libs/common/src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ pub use error::Error;
#[allow(clippy::module_name_repetitions)]
pub use path::WorkspacePath;

use crate::prefix::{Prefix, FILES};
use crate::{
prefix::{Prefix, FILES},
project::ProjectConfig,
};

#[derive(Debug, PartialEq, Eq)]
/// A workspace (directory) containing addons and / or missions
pub struct Workspace {
pub(crate) vfs: VfsPath,
pub(crate) project: Option<ProjectConfig>,
pub(crate) pointers: HashMap<String, VfsPath>,
pub(crate) addons: Vec<VfsPath>,
pub(crate) missions: Vec<VfsPath>,
Expand All @@ -30,13 +34,20 @@ impl Workspace {
WorkspaceBuilder::default()
}

#[must_use]
/// Returns the project config
pub const fn project(&self) -> Option<&ProjectConfig> {
self.project.as_ref()
}

/// Create a new workspace from a vfs path
///
/// # Errors
/// [`Error::Vfs`] if the workspace could not be created
pub fn create(vfs: VfsPath) -> Result<WorkspacePath, Error> {
pub fn create(vfs: VfsPath, project: Option<ProjectConfig>) -> Result<WorkspacePath, Error> {
let mut workspace = Self {
vfs,
project,
pointers: HashMap::new(),
addons: Vec::new(),
missions: Vec::new(),
Expand Down Expand Up @@ -104,9 +115,9 @@ impl WorkspaceBuilder {
///
/// # Errors
/// [`Error::Vfs`] if the workspace could not be built
pub fn finish(self) -> Result<WorkspacePath, Error> {
pub fn finish(self, project: Option<ProjectConfig>) -> Result<WorkspacePath, Error> {
let mut layers = self.layers;
layers.reverse();
Workspace::create(OverlayFS::new(&layers).into())
Workspace::create(OverlayFS::new(&layers).into(), project)
}
}
6 changes: 6 additions & 0 deletions libs/common/src/workspace/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ impl WorkspacePath {
&self.path
}

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

/// join a path to the workspace path
///
/// # Errors
Expand Down
1 change: 0 additions & 1 deletion libs/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ bench = false
hemtt-common = { path = "../common", version = "1.0.0" }

hemtt-preprocessor = { path = "../preprocessor", version = "1.0.0" }
hemtt-project = { path = "../project", version = "1.0.0" }

ariadne = { workspace = true }
byteorder = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use crate::{
analyze::codes::{ce1_invalid_value::InvalidValue, ce2_invalid_value_macro::InvalidValueMacro},
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/class.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use crate::Class;

Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};

use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use crate::{Class, Config, Ident, Item, Property, Str, Value};

Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

mod array;
mod class;
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/number.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use crate::Number;

Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/property.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::Range;

use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use super::{
codes::{
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/str.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use crate::Str;

Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/analyze/value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hemtt_common::project::ProjectConfig;
use hemtt_common::reporting::{Code, Processed};
use hemtt_project::ProjectConfig;

use crate::{
analyze::codes::{ce1_invalid_value::InvalidValue, ce2_invalid_value_macro::InvalidValueMacro},
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use chumsky::{prelude::Simple, Parser};
use hemtt_common::reporting::{Code, Processed};

pub use error::Error;
use hemtt_project::ProjectConfig;
use hemtt_common::project::ProjectConfig;
pub use model::*;
pub mod parse;
pub mod rapify;
Expand Down
2 changes: 1 addition & 1 deletion libs/config/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn check(dir: &str) {
let folder = std::path::PathBuf::from(ROOT).join(dir);
let workspace = hemtt_common::workspace::Workspace::builder()
.physical(&folder)
.finish()
.finish(None)
.unwrap();
let source = workspace.join("source.hpp").unwrap();
let processed = Processor::run(&source).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion libs/config/tests/rapify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn check(dir: &str) {
let folder = std::path::PathBuf::from(ROOT).join(dir);
let workspace = hemtt_common::workspace::Workspace::builder()
.physical(&folder)
.finish()
.finish(None)
.unwrap();
let source = workspace.join("source.hpp").unwrap();
let processed = Processor::run(&source).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion libs/config/tests/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn check(dir: &str) {
let folder = std::path::PathBuf::from(ROOT).join(dir);
let workspace = hemtt_common::workspace::Workspace::builder()
.physical(&folder)
.finish()
.finish(None)
.unwrap();
let source = workspace.join("source.hpp").unwrap();
let processed = Processor::run(&source).unwrap();
Expand Down
5 changes: 3 additions & 2 deletions libs/pbo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ mod error;
mod file;
mod model;
mod read;
mod sign_version;
mod write;

pub use error::Error;
pub use model::{Checksum, Header, Mime};
pub use read::ReadablePbo;
pub use sign_version::BISignVersion;
pub use write::WritablePbo;

// Re-exported from common
pub use hemtt_common::BISignVersion;

trait WritePbo {
fn write_pbo<O: Write>(&self, output: &mut O) -> Result<(), Error>;
}
Expand Down
Loading

0 comments on commit 6850bea

Please sign in to comment.