🐛 fix: revert macro remova

This commit is contained in:
Pauline 2024-07-27 17:26:11 +02:00
parent bcb2d55b95
commit c853a66969
No known key found for this signature in database
GPG key ID: 722BB181973296AE
23 changed files with 107 additions and 2 deletions

View file

@ -3,7 +3,8 @@ resolver = "2"
members = [
"apps/testing",
"apps/desktop",
"packages/core"
"packages/core",
"packages/macros"
]
[workspace.package]
@ -21,6 +22,7 @@ version = "1.0.0-alpha.1"
[workspace.dependencies]
onelauncher = { path = "./packages/core" }
onelauncher_macros = { path = "./packages/macros" }
# tauri uses latest crates.io beta channel (temporarily can use v2 and main branches if necessary)
tauri = { version = "=2.0.0-beta.23", features = [

View file

@ -23,6 +23,8 @@ specta = [ "dep:specta" ]
cli = [ "dep:indicatif" ]
[dependencies]
onelauncher_macros = { workspace = true }
# GUI-only deps
tauri = { workspace = true, optional = true }
tauri-specta = { workspace = true, optional = true }

View file

@ -13,6 +13,7 @@ use std::path::PathBuf;
/// Creates a [`Cluster`] and adds it to the memory [`State`].
/// Returns a relative filepath ([`ClusterPath`]) which can be used to access the cluster.
#[tracing::instrument]
#[onelauncher_macros::memory]
#[allow(clippy::too_many_arguments)]
pub async fn create_cluster(
mut name: String,
@ -206,6 +207,7 @@ pub async fn create_cluster_from_duplicate(from: ClusterPath) -> crate::Result<C
/// Get the latest [`LoaderVersion`] from a [`Loader`].
#[tracing::instrument]
#[onelauncher_macros::memory]
pub(crate) async fn get_loader_version(
mc_version: String,
loader: Loader,

View file

@ -86,6 +86,7 @@ pub async fn run(path: &ClusterPath) -> crate::Result<Arc<RwLock<ProcessorChild>
/// run a Minecraft [`Cluster`] using [`MinecraftCredentials`] for authentication.
/// returns an [`Arc`] pointer to [`RwLock`] to [`ProcessorChild`].
#[tracing::instrument(skip(creds))]
#[onelauncher_macros::memory]
pub async fn run_credentials(
path: &ClusterPath,
creds: &MinecraftCredentials,
@ -358,6 +359,7 @@ pub async fn get_optimal_java_version(path: &ClusterPath) -> crate::Result<Optio
/// Try to update a [`Cluster`]'s playtime.
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn update_playtime(path: &ClusterPath) -> crate::Result<()> {
let state = State::get().await?;
let cluster = get(path, None)

View file

@ -27,6 +27,7 @@ pub async fn filter_java_version(java_version: Option<u32>) -> crate::Result<Vec
})
}
#[onelauncher_macros::memory]
pub async fn install_java(java_version: u32) -> crate::Result<PathBuf> {
let state = State::get().await?;

View file

@ -185,6 +185,7 @@ pub fn get_cluster_from_pack(location: CreatePackLocation) -> CreatePackCluster
}
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn generate_pack_from_version_id(
package_id: String,
version_id: String,
@ -294,6 +295,7 @@ pub async fn generate_pack_from_version_id(
}
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn generate_pack_from_file(
path: PathBuf,
cluster_path: ClusterPath,
@ -314,6 +316,7 @@ pub async fn generate_pack_from_file(
/// Sets generated cluster attributes to the pack attributes (using `cluster::edit`).
/// This includes the pack name, icon, game version, loader version, and loader.
#[onelauncher_macros::memory]
pub async fn set_cluster_information(
cluster_path: ClusterPath,
description: &CreatePackDescription,

View file

@ -113,6 +113,7 @@ pub async fn is_valid_atlauncher(instance_folder: PathBuf) -> bool {
}
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn import_atlauncher(
// The path to the base ATLauncher folder.
atlauncher_base_path: PathBuf,

View file

@ -107,6 +107,7 @@ pub async fn import_instances(import: ImportType, path: PathBuf) -> crate::Resul
}
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn import_instance(
cluster_path: ClusterPath,
import: ImportType,
@ -184,6 +185,7 @@ pub fn default_launcher_path(r#type: ImportType) -> Option<PathBuf> {
/// Checks if a [`PathBuf`] is a valid instance for a given [`ImportType`]
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn is_valid_instance(instance_path: PathBuf, r#type: ImportType) -> bool {
match r#type {
ImportType::MultiMC | ImportType::PrismLauncher => {
@ -202,6 +204,7 @@ pub async fn is_valid_instance(instance_path: PathBuf, r#type: ImportType) -> bo
}
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn cache_icon(icon_path: PathBuf) -> crate::Result<Option<PathBuf>> {
let state = crate::State::get().await?;
let bytes = tokio::fs::read(&icon_path).await;
@ -251,6 +254,7 @@ pub async fn copy_minecraft(
}
/// recursively get a [`Vec<PathBuf>`] of all subfiles.
#[onelauncher_macros::memory]
#[async_recursion::async_recursion]
#[tracing::instrument]
pub async fn sub(path: &Path) -> crate::Result<Vec<PathBuf>> {

View file

@ -169,6 +169,7 @@ async fn load_instance_cfg(file_path: &Path) -> crate::Result<MMCInstance> {
}
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn import_mmc(
mmc_base_path: PathBuf,
instance_folder: String,

View file

@ -25,6 +25,7 @@ use super::from::{
/// Wrapper around [`install_pack_files`] that generates a pack creation description, and
/// attempts to install the pack files. If it fails, it will remove the cluster (fail safely)
/// Install a modpack from a mrpack file (a modrinth .zip format)
#[onelauncher_macros::memory]
pub async fn install_zipped_mrpack(
location: CreatePackLocation,
cluster_path: ClusterPath,
@ -65,6 +66,7 @@ pub async fn install_zipped_mrpack(
}
/// Install all pack files from a description. Does not remove the cluster if it fails
#[onelauncher_macros::memory]
pub async fn install_zipped_mrpack_files(
create_pack: CreatePack,
ignore_lock: bool,
@ -239,6 +241,7 @@ pub async fn install_zipped_mrpack_files(
}
#[tracing::instrument(skip(mrpack_file))]
#[onelauncher_macros::memory]
pub async fn remove_all_related_files(
cluster_path: ClusterPath,
mrpack_file: bytes::Bytes,

View file

@ -11,6 +11,7 @@ use crate::api::proxy::{ClusterPayload, IngressPayload, MessagePayload, ProcessP
#[cfg(feature = "tauri")]
use tauri::Manager;
#[onelauncher_macros::memory]
pub async fn init_ingress(
ingress_type: IngressType,
total: f64,
@ -24,6 +25,7 @@ pub async fn init_ingress(
#[cfg(feature = "cli")]
const CLI_TOTAL_INGRESS: u64 = 1000;
#[onelauncher_macros::memory]
pub async fn init_ingress_internal(
ingress_type: IngressType,
total: f64,
@ -98,6 +100,7 @@ pub async fn edit_ingress(
#[allow(unused_variables)]
#[tracing::instrument(level = "debug")]
#[onelauncher_macros::memory]
pub async fn send_ingress(
key: &IngressId,
increment: f64,

View file

@ -45,6 +45,7 @@ macro_rules! ingress_join {
/// TryStreamExt concurrently for Ingress feeds
#[tracing::instrument(skip(stream, f))]
#[onelauncher_macros::memory]
pub async fn ingress_try_for_each<I, F, Fut, T>(
stream: I,
limit: Option<usize>,

View file

@ -50,6 +50,7 @@ pub async fn download_minecraft(
}
#[tracing::instrument(skip_all, fields(version = version.id.as_str(), loader = ?loader))]
#[onelauncher_macros::memory]
pub async fn download_version_info(
st: &State,
version: &GameVersion,
@ -112,6 +113,7 @@ pub async fn fetch_partial_version(
}
#[tracing::instrument(skip_all)]
#[onelauncher_macros::memory]
pub async fn download_assets_index(
st: &State,
version: &GameVersionInfo,
@ -160,6 +162,7 @@ pub async fn fetch_assets_index(
}
#[tracing::instrument(skip(st, index))]
#[onelauncher_macros::memory]
pub async fn download_assets(
st: &State,
legacy: bool,
@ -221,6 +224,7 @@ pub async fn download_assets(
}
#[tracing::instrument(skip(st, libraries))]
#[onelauncher_macros::memory]
#[allow(clippy::too_many_arguments)]
pub async fn download_libraries(
st: &State,
@ -315,6 +319,7 @@ pub async fn download_libraries(
}
#[tracing::instrument(skip_all)]
#[onelauncher_macros::memory]
pub async fn download_client(
st: &State,
version: &GameVersionInfo,

View file

@ -36,6 +36,7 @@ macro_rules! data_entry {
}
#[tracing::instrument(skip(cluster))]
#[onelauncher_macros::memory]
pub async fn install_minecraft(
cluster: &Cluster,
old_ingress: Option<IngressId>,
@ -242,6 +243,7 @@ pub async fn install_minecraft(
}
#[tracing::instrument(skip_all)]
#[onelauncher_macros::memory]
#[allow(clippy::too_many_arguments)]
pub async fn launch_minecraft(
cluster: &Cluster,

View file

@ -512,6 +512,7 @@ impl Cluster {
/// watch the filesystem for changes with [`notify`].
#[tracing::instrument(skip(watcher))]
#[onelauncher_macros::memory]
pub async fn watch(
cluster_path: &Path,
watcher: &mut Debouncer<RecommendedWatcher>,
@ -542,6 +543,7 @@ impl Cluster {
impl Clusters {
/// Initialize the cluster manager and HashMap.
#[tracing::instrument(skip(watcher))]
#[onelauncher_macros::memory]
pub async fn initialize(
dirs: &Directories,
watcher: &mut Debouncer<RecommendedWatcher>,
@ -578,6 +580,7 @@ impl Clusters {
/// update registered packages
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn update_packages() {
let res = async {
let state = State::get().await?;
@ -631,6 +634,7 @@ impl Clusters {
/// update all available package versions
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn update_versions() {
let res = async {
let state = State::get().await?;
@ -666,6 +670,7 @@ impl Clusters {
/// insert a cluster into the HashMap
#[tracing::instrument(skip(self, cluster))]
#[onelauncher_macros::memory]
pub async fn insert(&mut self, cluster: Cluster, dont_watch: bool) -> crate::Result<&Self> {
send_cluster(
cluster.uuid,

View file

@ -144,6 +144,7 @@ impl Metadata {
/// Initialize the core Metadata manager.
#[tracing::instrument(skip(io_semaphore, fetch_semaphore))]
#[onelauncher_macros::memory]
pub async fn initialize(
dirs: &Directories,
online: bool,

View file

@ -110,6 +110,7 @@ impl State {
/// Initializes the core OneLauncher state fully.
#[tracing::instrument]
#[onelauncher_macros::memory]
async fn initialize() -> crate::Result<RwLock<State>> {
let ingress =
init_ingress_internal(crate::IngressType::Initialize, 100.0, "initializing state")
@ -202,6 +203,7 @@ impl State {
/// Synchronizes data that can change outside of our control.
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn sync() -> crate::Result<()> {
let state = Self::get().await?;
let sync_settings = async {

View file

@ -21,6 +21,7 @@ use super::{Cluster, PackagePath};
/// Creates [`Package`] data for a given [`Cluster`] from on-device files and APIs.
/// Paths must be the full paths and not relative paths.
#[tracing::instrument(skip(paths, _cluster, _io_semaphore, _fetch_semaphore))]
#[onelauncher_macros::memory]
pub async fn generate_context(
_cluster: Cluster,
paths: Vec<PathBuf>,
@ -323,6 +324,7 @@ pub enum PackageFile {
}
#[tracing::instrument(skip(io_semaphore))]
#[onelauncher_macros::memory]
async fn read_icon(
icon_path: Option<String>,
cache_path: &Path,

View file

@ -412,6 +412,7 @@ impl Processor {
/// insert a process with a command and [`ClusterPath`].
#[tracing::instrument(skip(self, uuid, command, post, censors))]
#[tracing::instrument(level = "trace", skip(self))]
#[onelauncher_macros::memory]
pub async fn insert_process(
&mut self,
uuid: Uuid,
@ -455,6 +456,7 @@ impl Processor {
/// Insert a cached process with a [`ProcessorCache`].
#[tracing::instrument(skip(self, cache))]
#[tracing::instrument(level = "trace", skip(self))]
#[onelauncher_macros::memory]
pub async fn insert_restored(
&mut self,
cache: ProcessorCache,
@ -542,6 +544,7 @@ impl Processor {
/// Get a process manager and runner awaiting for the exit status.
#[tracing::instrument(skip(current_child))]
#[onelauncher_macros::memory]
async fn manager(
uuid: Uuid,
post: Option<String>,

View file

@ -76,6 +76,7 @@ where
/// Advanced HTTP fetch interface with json, sha1 validation, and ingress support.
#[tracing::instrument(skip(json_body, semaphore))]
#[onelauncher_macros::memory]
pub async fn fetch_advanced(
method: Method,
url: &str,
@ -166,6 +167,7 @@ pub async fn fetch_advanced(
/// A utility to fetch from multiple mirrored sources.
#[tracing::instrument(skip(semaphore))]
#[onelauncher_macros::memory]
pub async fn fetch_from_mirrors(
mirrors: &[&str],
sha1: Option<&str>,
@ -187,6 +189,7 @@ pub async fn fetch_from_mirrors(
/// Checks if we are playing offline by contacting a reliable server.
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn check_internet_connection(timeout: u64) -> bool {
REQWEST_CLIENT
.get("https://api.polyfrost.org/")
@ -196,8 +199,9 @@ pub async fn check_internet_connection(timeout: u64) -> bool {
.is_ok()
}
/// Post JSON to a specified URL (helpful for Microsoft auth)
/// Post JSON to a specified URL (helpful for Microsoft auth and Metadata)
#[tracing::instrument(skip(json_body, semaphore))]
#[onelauncher_macros::memory]
pub async fn post_json<T>(
url: &str,
json_body: serde_json::Value,

View file

@ -183,6 +183,7 @@ pub async fn locate_java() -> Result<Vec<JavaVersion>, JavaError> {
/// Locate JRE's auto-installed by the launcher instance.
#[tracing::instrument]
#[onelauncher_macros::memory]
async fn locate_installed_java() -> Result<HashSet<PathBuf>, JavaError> {
Box::pin(async move {
let state = State::get().await.map_err(|_| JavaError::MutexError)?;
@ -244,6 +245,7 @@ pub async fn check_java(paths: HashSet<PathBuf>) -> HashSet<JavaVersion> {
/// Verifies that a java instance [`Path`] is valid.
/// java_check from https://github.com/modrinth/theseus/blob/master/theseus/library/JavaInfo.class under MIT
#[tracing::instrument]
#[onelauncher_macros::memory]
pub async fn check_java_instance(path: &Path) -> Option<JavaVersion> {
let Ok(path) = io::canonicalize(path) else {
return None;

View file

@ -0,0 +1,18 @@
[package]
name = "onelauncher_macros"
description = "Debugger macros for OneLauncher"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
homepage = { workspace = true }
authors = { workspace = true }
[lib]
proc-macro = true
[dependencies]
syn = { workspace = true }
quote = { workspace = true }

View file

@ -0,0 +1,36 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};
/// Procedural macro that isolates a [`Box`] to ensure proper memory allocation in
/// debug environments.
#[proc_macro_attribute]
pub fn memory(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as ItemFn);
let attrs = &input.attrs;
let vis = &input.vis;
let sig = &input.sig;
let body = &input.block;
#[cfg(debug_assertions)]
let result = quote! {
#(#attrs)*
#vis #sig {
Box::pin(async move {
#body
}).await
}
};
#[cfg(not(debug_assertions))]
let result = quote! {
#(#attrs)*
#vis #sig {
#body
}
};
TokenStream::from(result)
}