From f8fa06a4c5e8ed14fa8f63494d91d83ebb142863 Mon Sep 17 00:00:00 2001 From: lucasvreis Date: Wed, 17 Apr 2024 20:23:54 -0300 Subject: [PATCH 1/3] latexmk: use new '-dir-report-only' option This is supported since latexmk v4.82, dated 24 December 2023, but output got changed in v4.84 to print the dirs in a new line, breaking the current parser. --- crates/parser/src/latexmkrc.rs | 47 ++++++++++++++-------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/crates/parser/src/latexmkrc.rs b/crates/parser/src/latexmkrc.rs index 63c92bd3..a3f45af3 100644 --- a/crates/parser/src/latexmkrc.rs +++ b/crates/parser/src/latexmkrc.rs @@ -1,25 +1,17 @@ +use std::str::Lines; + use syntax::latexmkrc::LatexmkrcData; -use tempfile::tempdir; pub fn parse_latexmkrc(_input: &str) -> std::io::Result { - let temp_dir = tempdir()?; - let non_existent_tex = temp_dir.path().join("NONEXISTENT.tex"); - - // Run `latexmk -dir-report $TMPDIR/NONEXISTENT.tex` to obtain out_dir - // and aux_dir values. We pass nonexistent file to prevent latexmk from - // building anything, since we need this invocation only to extract the - // -dir-report variables. - // - // In the future, latexmk plans to implement -dir-report-only option and we - // won't have to resort to this hack with NONEXISTENT.tex. + + // Run `latexmk -dir-report-only` to obtain out_dir and aux_dir values. let output = std::process::Command::new("latexmk") - .arg("-dir-report") - .arg(non_existent_tex) + .arg("-dir-report-only") .output()?; - let stderr = String::from_utf8_lossy(&output.stderr); + let stdout = String::from_utf8_lossy(&output.stdout); - let (aux_dir, out_dir) = stderr.lines().find_map(extract_dirs).ok_or_else(|| { + let (aux_dir, out_dir) = extract_dirs(stdout.lines()).ok_or_else(|| { std::io::Error::new( std::io::ErrorKind::InvalidData, "Normalized aux and out dir were not found in latexmk output", @@ -34,19 +26,18 @@ pub fn parse_latexmkrc(_input: &str) -> std::io::Result { /// Extracts $aux_dir and $out_dir from lines of the form /// -/// Latexmk: Normalized aux dir and out dir: '$aux_dir', '$out_dir' -fn extract_dirs(line: &str) -> Option<(String, String)> { - let mut it = line - .strip_prefix("Latexmk: Normalized aux dir and out dir: ")? - .split(", "); - - let aux_dir = it.next()?.strip_prefix('\'')?.strip_suffix('\'')?; - let out_dir = it.next()?.strip_prefix('\'')?.strip_suffix('\'')?; - - // Ensure there's no more data - if it.next().is_some() { - return None; - } +/// Latexmk: Normalized aux dir and out dirs: +/// '$aux_dir', '$out_dir', [...] +fn extract_dirs(lines: Lines) -> Option<(String, String)> { + let mut it = + lines.skip_while(|line| { + !line.starts_with("Latexmk: Normalized aux dir and out dirs:") + }) + .nth(1)? + .split(","); + + let aux_dir = it.next()?.trim().strip_prefix('\'')?.strip_suffix('\'')?; + let out_dir = it.next()?.trim().strip_prefix('\'')?.strip_suffix('\'')?; Some((String::from(aux_dir), String::from(out_dir))) } From 80d4334ead1116bea29725d7c097c75731bb215f Mon Sep 17 00:00:00 2001 From: lucasvreis Date: Wed, 17 Apr 2024 20:24:20 -0300 Subject: [PATCH 2/3] fix(latexmk): use aux_dir as log_dir 'latexmk' writes the .log file to the user-specified '$aux_dir' path, instead of the PDF output path. From the MAN page: -auxdir=FOO or -aux-directory=FOO Sets the directory for auxiliary output files of *latex (.aux, .log etc). These are all the generated files, with the exception of final output files (.dvi, .ps, .pdf, .synctex.gz, .synctex). See the -outdir/-output-directory option for directories for the main output files, and the -out2dir option for the final output files. --- crates/base-db/src/deps/root.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/base-db/src/deps/root.rs b/crates/base-db/src/deps/root.rs index 442d6f9e..935fd08e 100644 --- a/crates/base-db/src/deps/root.rs +++ b/crates/base-db/src/deps/root.rs @@ -93,7 +93,7 @@ impl ProjectRoot { .and_then(|path| append_dir(dir, path).ok()) .unwrap_or_else(|| dir.clone()); - let log_dir = out_dir.clone(); + let log_dir = aux_dir.clone(); let pdf_dir = out_dir; let additional_files = vec![]; From 7bd2b11b79d84bf278784156048f60ad21cf4aca Mon Sep 17 00:00:00 2001 From: lucasvreis Date: Wed, 17 Apr 2024 20:40:15 -0300 Subject: [PATCH 3/3] latexmk: use out2dir if available Supported since latexmk v4.85. From the man page: -out2dir=FOO (Experimental new feature.) Sets the directory for the final output files of a whole round of compilations. --- crates/parser/src/latexmkrc.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/parser/src/latexmkrc.rs b/crates/parser/src/latexmkrc.rs index a3f45af3..cccaf9ff 100644 --- a/crates/parser/src/latexmkrc.rs +++ b/crates/parser/src/latexmkrc.rs @@ -37,7 +37,15 @@ fn extract_dirs(lines: Lines) -> Option<(String, String)> { .split(","); let aux_dir = it.next()?.trim().strip_prefix('\'')?.strip_suffix('\'')?; + + it.next(); // Skip the old 'outdir' option. + let out_dir = it.next()?.trim().strip_prefix('\'')?.strip_suffix('\'')?; + // Ensure there's no more data + if it.next().is_some() { + return None; + } + Some((String::from(aux_dir), String::from(out_dir))) }