Add flags option to request JSON

Adds a `flags` parameter to the request JSON, appearing under the `compile.options` key (alongside such stalwarts as `compiler`, `timeout`, etc.).

This is primarily to support `-file-line-error` as an option, but could have other uses as well.

`flags` should be an array of strings, or absent. If supplied, the listed arguments are added to the base latexmk command.
This commit is contained in:
Michael Mazour 2019-05-10 16:51:40 +01:00
parent 4ccaa3bf2f
commit 1ddf9283f2
6 changed files with 82 additions and 38 deletions

View file

@ -93,6 +93,7 @@ module.exports = CompileManager =
compiler: request.compiler
timeout: request.timeout
image: request.imageName
flags: request.flags
environment: env
}, (error, output, stats, timings) ->
# request was for validation only

View file

@ -8,24 +8,24 @@ ProcessTable = {} # table of currently running jobs (pids or docker container n
module.exports = LatexRunner =
runLatex: (project_id, options, callback = (error) ->) ->
{directory, mainFile, compiler, timeout, image, environment} = options
{directory, mainFile, compiler, timeout, image, environment, flags} = options
compiler ||= "pdflatex"
timeout ||= 60000 # milliseconds
logger.log directory: directory, compiler: compiler, timeout: timeout, mainFile: mainFile, environment: environment, "starting compile"
logger.log directory: directory, compiler: compiler, timeout: timeout, mainFile: mainFile, environment: environment, flags:flags, "starting compile"
# We want to run latexmk on the tex file which we will automatically
# generate from the Rtex/Rmd/md file.
mainFile = mainFile.replace(/\.(Rtex|md|Rmd)$/, ".tex")
if compiler == "pdflatex"
command = LatexRunner._pdflatexCommand mainFile
command = LatexRunner._pdflatexCommand mainFile, flags
else if compiler == "latex"
command = LatexRunner._latexCommand mainFile
command = LatexRunner._latexCommand mainFile, flags
else if compiler == "xelatex"
command = LatexRunner._xelatexCommand mainFile
command = LatexRunner._xelatexCommand mainFile, flags
else if compiler == "lualatex"
command = LatexRunner._lualatexCommand mainFile
command = LatexRunner._lualatexCommand mainFile, flags
else
return callback new Error("unknown compiler: #{compiler}")
@ -63,31 +63,32 @@ module.exports = LatexRunner =
else
CommandRunner.kill ProcessTable[id], callback
_latexmkBaseCommand: (Settings?.clsi?.latexmkCommandPrefix || []).concat([
"latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR",
"-synctex=1","-interaction=batchmode"
])
_latexmkBaseCommand: (flags) ->
args = ["latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR", "-synctex=1","-interaction=batchmode"]
if flags
args = args.concat(flags)
(Settings?.clsi?.latexmkCommandPrefix || []).concat(args)
_pdflatexCommand: (mainFile) ->
LatexRunner._latexmkBaseCommand.concat [
_pdflatexCommand: (mainFile, flags) ->
LatexRunner._latexmkBaseCommand(flags).concat [
"-pdf",
Path.join("$COMPILE_DIR", mainFile)
]
_latexCommand: (mainFile) ->
LatexRunner._latexmkBaseCommand.concat [
_latexCommand: (mainFile, flags) ->
LatexRunner._latexmkBaseCommand(flags).concat [
"-pdfdvi",
Path.join("$COMPILE_DIR", mainFile)
]
_xelatexCommand: (mainFile) ->
LatexRunner._latexmkBaseCommand.concat [
_xelatexCommand: (mainFile, flags) ->
LatexRunner._latexmkBaseCommand(flags).concat [
"-xelatex",
Path.join("$COMPILE_DIR", mainFile)
]
_lualatexCommand: (mainFile) ->
LatexRunner._latexmkBaseCommand.concat [
_lualatexCommand: (mainFile, flags) ->
LatexRunner._latexmkBaseCommand(flags).concat [
"-lualatex",
Path.join("$COMPILE_DIR", mainFile)
]

View file

@ -33,6 +33,10 @@ module.exports = RequestParser =
response.check = @_parseAttribute "check",
compile.options.check,
type: "string"
response.flags = @_parseAttribute "flags",
compile.options.flags,
default: [],
type: "object"
# The syncType specifies whether the request contains all
# resources (full) or only those resources to be updated

View file

@ -108,6 +108,7 @@ describe "CompileManager", ->
compiler: @compiler = "pdflatex"
timeout: @timeout = 42000
imageName: @image = "example.com/image"
flags: @flags = ["-file-line-error"]
@env = {}
@Settings.compileDir = "compiles"
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
@ -135,6 +136,7 @@ describe "CompileManager", ->
compiler: @compiler
timeout: @timeout
image: @image
flags: @flags
environment: @env
})
.should.equal true
@ -173,6 +175,7 @@ describe "CompileManager", ->
compiler: @compiler
timeout: @timeout
image: @image
flags: @flags
environment: {'CHKTEX_OPTIONS': '-nall -e9 -e10 -w15 -w16', 'CHKTEX_EXIT_ON_ERROR':1, 'CHKTEX_ULIMIT_OPTIONS': '-t 5 -v 64000'}
})
.should.equal true
@ -191,6 +194,7 @@ describe "CompileManager", ->
compiler: @compiler
timeout: @timeout
image: @image
flags: @flags
environment: @env
})
.should.equal true

View file

@ -59,3 +59,21 @@ describe "LatexRunner", ->
mainFile = command.slice(-1)[0]
mainFile.should.equal "$COMPILE_DIR/main-file.tex"
describe "with a flags option", ->
beforeEach ->
@LatexRunner.runLatex @project_id,
directory: @directory
mainFile: @mainFile
compiler: @compiler
image: @image
timeout: @timeout = 42000
flags: ["-file-line-error", "-halt-on-error"]
@callback
it "should include the flags in the command", ->
command = @CommandRunner.run.args[0][1]
flags = command.filter (arg) ->
(arg == "-file-line-error") || (arg == "-halt-on-error")
flags.length.should.equal 2
flags[0].should.equal "-file-line-error"
flags[1].should.equal "-halt-on-error"

View file

@ -1,6 +1,7 @@
SandboxedModule = require('sandboxed-module')
sinon = require('sinon')
require('chai').should()
expect = require('chai').expect
modulePath = require('path').join __dirname, '../../../app/js/RequestParser'
tk = require("timekeeper")
@ -66,6 +67,21 @@ describe "RequestParser", ->
it "should set the imageName", ->
@data.imageName.should.equal "basicImageName/here:2017-1"
describe "with flags set", ->
beforeEach ->
@validRequest.compile.options.flags = ["-file-line-error"]
@RequestParser.parse @validRequest, (error, @data) =>
it "should set the flags attribute", ->
expect(@data.flags).to.deep.equal ["-file-line-error"]
describe "with flags not specified", ->
beforeEach ->
@RequestParser.parse @validRequest, (error, @data) =>
it "it should have an empty flags list", ->
expect(@data.flags).to.deep.equal []
describe "without a timeout specified", ->
beforeEach ->
delete @validRequest.compile.options.timeout