diff --git a/Cargo.toml b/Cargo.toml index 9b9b0cf..ba6a561 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,8 +54,8 @@ walkdir = "2.3.3" [features] default = ["compare", "foreign_document_test"] -compare = ["dep:tokio"] -foreign_document_test = ["compare", "dep:tokio", "dep:futures", "tokio/sync", "dep:walkdir"] +compare = ["tokio/process"] +foreign_document_test = ["compare", "dep:tokio", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] # Optimized build for any sort of release. diff --git a/src/compare/compare.rs b/src/compare/compare.rs index c9aff87..756dcb7 100644 --- a/src/compare/compare.rs +++ b/src/compare/compare.rs @@ -45,10 +45,10 @@ pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef>( let org_contents = org_contents.as_ref().replace("\r\n", "\n"); let org_contents = org_contents.as_str(); if !silent { - print_versions()?; + print_versions().await?; } let rust_parsed = parse_with_settings(org_contents, global_settings)?; - let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings)?; + let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings).await?; let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?; if !silent { @@ -83,7 +83,7 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef>( ) -> Result> { let org_path = org_path.as_ref(); if !silent { - print_versions()?; + print_versions().await?; } let parent_directory = org_path .parent() @@ -101,7 +101,7 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef>( global_settings }; let rust_parsed = parse_file_with_settings(org_contents, &global_settings, Some(org_path))?; - let org_sexp = emacs_parse_file_org_document(org_path, &global_settings)?; + let org_sexp = emacs_parse_file_org_document(org_path, &global_settings).await?; let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?; if !silent { @@ -129,8 +129,11 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef>( Ok(true) } -fn print_versions() -> Result<(), Box> { - eprintln!("Using emacs version: {}", get_emacs_version()?.trim()); - eprintln!("Using org-mode version: {}", get_org_mode_version()?.trim()); +async fn print_versions() -> Result<(), Box> { + eprintln!("Using emacs version: {}", get_emacs_version().await?.trim()); + eprintln!( + "Using org-mode version: {}", + get_org_mode_version().await?.trim() + ); Ok(()) } diff --git a/src/compare/parse.rs b/src/compare/parse.rs index 10cb01d..8b28fc3 100644 --- a/src/compare/parse.rs +++ b/src/compare/parse.rs @@ -1,5 +1,6 @@ use std::path::Path; -use std::process::Command; + +use tokio::process::Command; use crate::context::HeadlineLevelFilter; use crate::settings::GlobalSettings; @@ -25,9 +26,9 @@ fn global_settings_elisp(global_settings: &GlobalSettings) -> String { ret } -pub(crate) fn emacs_parse_anonymous_org_document( +pub(crate) async fn emacs_parse_anonymous_org_document<'g, 's, C>( file_contents: C, - global_settings: &GlobalSettings, + global_settings: &GlobalSettings<'g, 's>, ) -> Result> where C: AsRef, @@ -54,7 +55,7 @@ where .arg("--batch") .arg("--eval") .arg(elisp_script); - let out = cmd.output()?; + let out = cmd.output().await?; let status = out.status.exit_ok(); if status.is_err() { eprintln!( @@ -69,9 +70,9 @@ where Ok(String::from_utf8(org_sexp)?) } -pub(crate) fn emacs_parse_file_org_document

( +pub(crate) async fn emacs_parse_file_org_document<'g, 's, P>( file_path: P, - global_settings: &GlobalSettings, + global_settings: &GlobalSettings<'g, 's>, ) -> Result> where P: AsRef, @@ -106,7 +107,7 @@ where .arg("--batch") .arg("--eval") .arg(elisp_script); - let out = cmd.output()?; + let out = cmd.output().await?; let status = out.status.exit_ok(); if status.is_err() { eprintln!( @@ -143,7 +144,7 @@ where output } -pub fn get_emacs_version() -> Result> { +pub async fn get_emacs_version() -> Result> { let elisp_script = r#"(progn (message "%s" (version)) )"#; @@ -156,12 +157,12 @@ pub fn get_emacs_version() -> Result> { .arg("--eval") .arg(elisp_script); - let out = cmd.output()?; + let out = cmd.output().await?; out.status.exit_ok()?; Ok(String::from_utf8(out.stderr)?) } -pub fn get_org_mode_version() -> Result> { +pub async fn get_org_mode_version() -> Result> { let elisp_script = r#"(progn (org-mode) (message "%s" (org-version nil t nil)) @@ -175,7 +176,7 @@ pub fn get_org_mode_version() -> Result> { .arg("--eval") .arg(elisp_script); - let out = cmd.output()?; + let out = cmd.output().await?; out.status.exit_ok()?; Ok(String::from_utf8(out.stderr)?) }