Switch to using tokio too invoke emacs async.

This commit is contained in:
Tom Alexander 2023-10-14 17:55:53 -04:00
parent 123da9cca3
commit e1fde88a60
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 24 additions and 20 deletions

View File

@ -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.

View File

@ -45,10 +45,10 @@ pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
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<Path>>(
) -> Result<bool, Box<dyn std::error::Error>> {
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<Path>>(
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<Path>>(
Ok(true)
}
fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
eprintln!("Using emacs version: {}", get_emacs_version()?.trim());
eprintln!("Using org-mode version: {}", get_org_mode_version()?.trim());
async fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
eprintln!("Using emacs version: {}", get_emacs_version().await?.trim());
eprintln!(
"Using org-mode version: {}",
get_org_mode_version().await?.trim()
);
Ok(())
}

View File

@ -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<C>(
pub(crate) async fn emacs_parse_anonymous_org_document<'g, 's, C>(
file_contents: C,
global_settings: &GlobalSettings,
global_settings: &GlobalSettings<'g, 's>,
) -> Result<String, Box<dyn std::error::Error>>
where
C: AsRef<str>,
@ -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<P>(
pub(crate) async fn emacs_parse_file_org_document<'g, 's, P>(
file_path: P,
global_settings: &GlobalSettings,
global_settings: &GlobalSettings<'g, 's>,
) -> Result<String, Box<dyn std::error::Error>>
where
P: AsRef<Path>,
@ -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<String, Box<dyn std::error::Error>> {
pub async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
let elisp_script = r#"(progn
(message "%s" (version))
)"#;
@ -156,12 +157,12 @@ pub fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
.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<String, Box<dyn std::error::Error>> {
pub async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
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<String, Box<dyn std::error::Error>> {
.arg("--eval")
.arg(elisp_script);
let out = cmd.output()?;
let out = cmd.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
}