James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.47k stars 519 forks source link

Autoclean runs between recipe tools #4247

Closed Holbormon closed 3 months ago

Holbormon commented 3 months ago

Pre-checks*

Environment*

The Issue*

When automatic auxiliary file cleanup is enabled (whether latex-workshop.latex.autoClean.run is set to onBuilt or onSucceeded), it seems as though files are cleaned up in-between tool use (within recipes). For common recipes such as "pdflatex, bibtex, pdflatex x2", this results in missing bibliography/refrences, with the warning that pdflatex should be ran again.

Reproduction Steps

  1. Create a .tex document which uses \label and \ref commands
  2. Set autoclean to onBuilt/onSucceeded
  3. Compile using the following toolchain: pdflatex, bibtex, pdflatex x2
  4. Observe: LaTeX: Label(s) may have changed. Rerun to get cross-references right.
  5. Turn off autoclean (set latex-workshop.latex.autoClean.run to never)
  6. Repeat 4
  7. Document references are included properly this time (although files are not cleaned-up)

Expected Behavior

Anything Else?

The problem arises independently of latex-workshop.latex.autoBuild.cleanAndRetry.enabled

Holbormon commented 3 months ago

After further examination of the logs, it turns out the problem rather lies in an extra recipe step being run after the whole recipe has completed, resulting in the cleaner being run twice.

[16:53:06.928][Commander] RECIPES command invoked.
[16:53:06.929][Commander] BUILD command invoked.
[16:53:06.930][Build] The document of the active editor: file://%WS2%/P1/P1.tex
[16:53:06.930][Build] The languageId of the document: latex
[16:53:06.931][Root] Current workspace folders: ["file://%WS1%","file://%WS2%"]
[16:53:06.935][Root] Found root file from active editor: %WS2%/P1/P1.tex
[16:53:06.936][Root] Keep using the same root file: %WS2%/P1/P1.tex
[16:53:06.936][Event] ROOT_FILE_SEARCHED
[16:53:06.937][Event] STRUCTURE_UPDATED
[16:53:06.938][Build] Building root file: %WS2%/P1/P1.tex
[16:53:06.938][Build][Recipe] Build root file %WS2%/P1/P1.tex
[16:53:06.991][Extension] onDidSaveTextDocument triggered: file://%WS2%/P1/P1.tex
[16:53:06.992][Build] Auto build started on saving file: %WS2%/P1/P1.tex .
[16:53:06.993][Event] AUTO_BUILD_INITIATED: {"type":"onSave","file":"%WS2%/P1/P1.tex"}
[16:53:06.993][Build] The document of the active editor: file://%WS2%/P1/P1.tex
[16:53:06.993][Build] The languageId of the document: latex
[16:53:06.994][Build] Building root file: %WS2%/P1/P1.tex
[16:53:06.994][Build][Recipe] Build root file %WS2%/P1/P1.tex
[16:53:06.996][Build][Recipe] Preparing to run recipe: Build.
[16:53:06.997][Build][Recipe] Prepared 4 tools.
[16:53:06.998][Build][Recipe] outDir: %WS2%/P1 .
[16:53:06.999][Build] Recipe step 1 The command is pdflatex:["-interaction=nonstopmode","-file-line-error","-shell-escape","%WS2%/P1/P1"].
[16:53:06.999][Build] env: {}
[16:53:06.999][Build] root: %WS2%/P1/P1.tex
[16:53:07.000][Build] cwd: %WS2%/P1
[16:53:07.007][Build] LaTeX build process spawned with PID 7378.
[16:53:07.009][Build][Recipe] Preparing to run recipe: Quickbuild.
[16:53:07.009][Build][Recipe] Prepared 1 tools.
[16:53:07.010][Build][Recipe] outDir: %WS2%/P1 .
[16:53:07.053][Cacher][Watcher] "change" emitted on %WS2%/P1/P1.tex.
[16:53:07.056][Cacher] Caching %WS2%/P1/P1.tex .
[16:53:07.058][Cacher] Updated inputs of %WS2%/P1/P1.tex .
[16:53:07.058][Cacher] Parse LaTeX AST: %WS2%/P1/P1.tex .
[16:53:07.059][Event] FILE_CHANGED: "%WS2%/P1/P1.tex"
[16:53:07.544][Cacher] Parsed LaTeX AST: %WS2%/P1/P1.tex .
[16:53:07.586][Cacher] Bib %WS2%/P1/src.bib from %WS2%/P1/P1.tex .
[16:53:07.587][Cacher] Updated elements in 42.27 ms: %WS2%/P1/P1.tex .
[16:53:07.587][Event] FILE_PARSED: "%WS2%/P1/P1.tex"
[16:53:07.592][Structure] Structure force updated with 4 root sections for %WS2%/P1/P1.tex .
[16:53:07.592][Event] STRUCTURE_UPDATED
[16:53:08.591][Parser][TexLog] Logged 81 messages.
[16:53:08.598][Build] Finished a step in recipe with PID 7378.
[16:53:08.598][Build] Recipe step 2 The command is bibtex:["P1"].
[16:53:08.599][Build] env: {}
[16:53:08.599][Build] root: %WS2%/P1/P1.tex
[16:53:08.599][Build] cwd: %WS2%/P1
[16:53:08.604][Build] LaTeX build process spawned with PID 7384.
[16:53:08.717][Parser][BibTeXLog] Logged 0 messages.
[16:53:08.717][Build] Finished a step in recipe with PID 7384.
[16:53:08.718][Build] Recipe step 3 The command is pdflatex:["-interaction=nonstopmode","-file-line-error","-shell-escape","%WS2%/P1/P1"].
[16:53:08.718][Build] env: {}
[16:53:08.718][Build] root: %WS2%/P1/P1.tex
[16:53:08.719][Build] cwd: %WS2%/P1
[16:53:08.729][Build] LaTeX build process spawned with PID 7385.
[16:53:10.137][Parser][TexLog] Logged 37 messages.
[16:53:10.144][Build] Finished a step in recipe with PID 7385.
[16:53:10.146][Build] Recipe step 4 The command is pdflatex:["-interaction=nonstopmode","-file-line-error","-shell-escape","%WS2%/P1/P1"].
[16:53:10.146][Build] env: {}
[16:53:10.146][Build] root: %WS2%/P1/P1.tex
[16:53:10.147][Build] cwd: %WS2%/P1
[16:53:10.152][Build] LaTeX build process spawned with PID 7391.
[16:53:11.661][Parser][TexLog] Logged 2 messages.
[16:53:11.663][Build] Finished a step in recipe with PID 7391.
[16:53:11.663][Build] Successfully built %WS2%/P1/P1.tex .
[16:53:11.664][Event] BUILD_DONE
[16:53:11.664][Viewer] Call refreshExistingViewer: "%WS2%/P1/P1.pdf" .
[16:53:11.664][Viewer] Not found PDF viewers to refresh: %WS2%/P1/P1.pdf
[16:53:11.666][Build] Auto Clean invoked.
[16:53:11.668][Cleaner] Clean glob matched files {"globs":["P1.aux","P1.bbl","P1.blg","P1.idx","P1.ind","P1.lof","P1.lot","P1.out","P1.toc","P1.acn","P1.acr","P1.alg","P1.glg","P1.glo","P1.gls","P1.fls","P1.log","P1.fdb_latexmk","P1.snm","P1.synctex(busy)","P1.synctex.gz(busy)","P1.nav","P1.vrb","svg-inkscape/*","svg-inkscape*/","P1.sta","P1.auxlock"],"outdir":"%WS2%/P1"} .
[16:53:11.669][Cleaner] Ignore folder glob patterns with globstar:  .
[16:53:11.676][Cleaner] Cleaning file %WS2%/P1/P1.out .
[16:53:11.677][Cleaner] Cleaning file %WS2%/P1/P1.log .
[16:53:11.678][Cleaner] Cleaning file %WS2%/P1/P1.blg .
[16:53:11.678][Cleaner] Cleaning file %WS2%/P1/P1.bbl .
[16:53:11.679][Cleaner] Cleaning file %WS2%/P1/P1.auxlock .
[16:53:11.679][Cleaner] Cleaning file %WS2%/P1/P1.aux .
[16:53:11.679][Event] AUTO_CLEANED
[16:53:11.680][Build] Recipe step 1 The command is pdflatex:["-interaction=nonstopmode","-file-line-error","-shell-escape","%WS2%/P1/P1"].
[16:53:11.680][Build] env: {}
[16:53:11.680][Build] root: %WS2%/P1/P1.tex
[16:53:11.681][Build] cwd: %WS2%/P1
[16:53:11.685][Build] LaTeX build process spawned with PID 7395.
[16:53:13.157][Parser][TexLog] Logged 81 messages.
[16:53:13.166][Build] Finished a step in recipe with PID 7395.
[16:53:13.166][Build] Successfully built %WS2%/P1/P1.tex .
[16:53:13.167][Event] BUILD_DONE
[16:53:13.167][Viewer] Call refreshExistingViewer: "%WS2%/P1/P1.pdf" .
[16:53:13.167][Viewer] Not found PDF viewers to refresh: %WS2%/P1/P1.pdf
[16:53:13.169][Build] Auto Clean invoked.
[16:53:13.170][Cleaner] Clean glob matched files {"globs":["P1.aux","P1.bbl","P1.blg","P1.idx","P1.ind","P1.lof","P1.lot","P1.out","P1.toc","P1.acn","P1.acr","P1.alg","P1.glg","P1.glo","P1.gls","P1.fls","P1.log","P1.fdb_latexmk","P1.snm","P1.synctex(busy)","P1.synctex.gz(busy)","P1.nav","P1.vrb","svg-inkscape/*","svg-inkscape*/","P1.sta","P1.auxlock"],"outdir":"%WS2%/P1"} .
[16:53:13.170][Cleaner] Ignore folder glob patterns with globstar:  .
[16:53:13.176][Cleaner] Cleaning file %WS2%/P1/P1.out .
[16:53:13.177][Cleaner] Cleaning file %WS2%/P1/P1.log .
[16:53:13.178][Cleaner] Cleaning file %WS2%/P1/P1.auxlock .
[16:53:13.178][Cleaner] Cleaning file %WS2%/P1/P1.aux .
[16:53:13.179][Event] AUTO_CLEANED

I have changed latex-workshop.latex.autoBuild.run from onSave to onFileChange, and the issue disappeared. Now my document compiles properly, even though Tex still reports LaTeX: Label(s) may have changed. Rerun to get cross-references right. for some reason.

James-Yu commented 3 months ago

This was a racing issue and has been fixed in b58bc13 . Thanks for the log report.