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:
@@ -93,6 +93,7 @@ module.exports = CompileManager =
|
|||||||
compiler: request.compiler
|
compiler: request.compiler
|
||||||
timeout: request.timeout
|
timeout: request.timeout
|
||||||
image: request.imageName
|
image: request.imageName
|
||||||
|
flags: request.flags
|
||||||
environment: env
|
environment: env
|
||||||
}, (error, output, stats, timings) ->
|
}, (error, output, stats, timings) ->
|
||||||
# request was for validation only
|
# request was for validation only
|
||||||
|
|||||||
@@ -8,24 +8,24 @@ ProcessTable = {} # table of currently running jobs (pids or docker container n
|
|||||||
|
|
||||||
module.exports = LatexRunner =
|
module.exports = LatexRunner =
|
||||||
runLatex: (project_id, options, callback = (error) ->) ->
|
runLatex: (project_id, options, callback = (error) ->) ->
|
||||||
{directory, mainFile, compiler, timeout, image, environment} = options
|
{directory, mainFile, compiler, timeout, image, environment, flags} = options
|
||||||
compiler ||= "pdflatex"
|
compiler ||= "pdflatex"
|
||||||
timeout ||= 60000 # milliseconds
|
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
|
# We want to run latexmk on the tex file which we will automatically
|
||||||
# generate from the Rtex/Rmd/md file.
|
# generate from the Rtex/Rmd/md file.
|
||||||
mainFile = mainFile.replace(/\.(Rtex|md|Rmd)$/, ".tex")
|
mainFile = mainFile.replace(/\.(Rtex|md|Rmd)$/, ".tex")
|
||||||
|
|
||||||
if compiler == "pdflatex"
|
if compiler == "pdflatex"
|
||||||
command = LatexRunner._pdflatexCommand mainFile
|
command = LatexRunner._pdflatexCommand mainFile, flags
|
||||||
else if compiler == "latex"
|
else if compiler == "latex"
|
||||||
command = LatexRunner._latexCommand mainFile
|
command = LatexRunner._latexCommand mainFile, flags
|
||||||
else if compiler == "xelatex"
|
else if compiler == "xelatex"
|
||||||
command = LatexRunner._xelatexCommand mainFile
|
command = LatexRunner._xelatexCommand mainFile, flags
|
||||||
else if compiler == "lualatex"
|
else if compiler == "lualatex"
|
||||||
command = LatexRunner._lualatexCommand mainFile
|
command = LatexRunner._lualatexCommand mainFile, flags
|
||||||
else
|
else
|
||||||
return callback new Error("unknown compiler: #{compiler}")
|
return callback new Error("unknown compiler: #{compiler}")
|
||||||
|
|
||||||
@@ -63,31 +63,32 @@ module.exports = LatexRunner =
|
|||||||
else
|
else
|
||||||
CommandRunner.kill ProcessTable[id], callback
|
CommandRunner.kill ProcessTable[id], callback
|
||||||
|
|
||||||
_latexmkBaseCommand: (Settings?.clsi?.latexmkCommandPrefix || []).concat([
|
_latexmkBaseCommand: (flags) ->
|
||||||
"latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR",
|
args = ["latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR", "-synctex=1","-interaction=batchmode"]
|
||||||
"-synctex=1","-interaction=batchmode"
|
if flags
|
||||||
])
|
args = args.concat(flags)
|
||||||
|
(Settings?.clsi?.latexmkCommandPrefix || []).concat(args)
|
||||||
|
|
||||||
_pdflatexCommand: (mainFile) ->
|
_pdflatexCommand: (mainFile, flags) ->
|
||||||
LatexRunner._latexmkBaseCommand.concat [
|
LatexRunner._latexmkBaseCommand(flags).concat [
|
||||||
"-pdf",
|
"-pdf",
|
||||||
Path.join("$COMPILE_DIR", mainFile)
|
Path.join("$COMPILE_DIR", mainFile)
|
||||||
]
|
]
|
||||||
|
|
||||||
_latexCommand: (mainFile) ->
|
_latexCommand: (mainFile, flags) ->
|
||||||
LatexRunner._latexmkBaseCommand.concat [
|
LatexRunner._latexmkBaseCommand(flags).concat [
|
||||||
"-pdfdvi",
|
"-pdfdvi",
|
||||||
Path.join("$COMPILE_DIR", mainFile)
|
Path.join("$COMPILE_DIR", mainFile)
|
||||||
]
|
]
|
||||||
|
|
||||||
_xelatexCommand: (mainFile) ->
|
_xelatexCommand: (mainFile, flags) ->
|
||||||
LatexRunner._latexmkBaseCommand.concat [
|
LatexRunner._latexmkBaseCommand(flags).concat [
|
||||||
"-xelatex",
|
"-xelatex",
|
||||||
Path.join("$COMPILE_DIR", mainFile)
|
Path.join("$COMPILE_DIR", mainFile)
|
||||||
]
|
]
|
||||||
|
|
||||||
_lualatexCommand: (mainFile) ->
|
_lualatexCommand: (mainFile, flags) ->
|
||||||
LatexRunner._latexmkBaseCommand.concat [
|
LatexRunner._latexmkBaseCommand(flags).concat [
|
||||||
"-lualatex",
|
"-lualatex",
|
||||||
Path.join("$COMPILE_DIR", mainFile)
|
Path.join("$COMPILE_DIR", mainFile)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ module.exports = RequestParser =
|
|||||||
response.check = @_parseAttribute "check",
|
response.check = @_parseAttribute "check",
|
||||||
compile.options.check,
|
compile.options.check,
|
||||||
type: "string"
|
type: "string"
|
||||||
|
response.flags = @_parseAttribute "flags",
|
||||||
|
compile.options.flags,
|
||||||
|
default: [],
|
||||||
|
type: "object"
|
||||||
|
|
||||||
# The syncType specifies whether the request contains all
|
# The syncType specifies whether the request contains all
|
||||||
# resources (full) or only those resources to be updated
|
# resources (full) or only those resources to be updated
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ describe "CompileManager", ->
|
|||||||
compiler: @compiler = "pdflatex"
|
compiler: @compiler = "pdflatex"
|
||||||
timeout: @timeout = 42000
|
timeout: @timeout = 42000
|
||||||
imageName: @image = "example.com/image"
|
imageName: @image = "example.com/image"
|
||||||
|
flags: @flags = ["-file-line-error"]
|
||||||
@env = {}
|
@env = {}
|
||||||
@Settings.compileDir = "compiles"
|
@Settings.compileDir = "compiles"
|
||||||
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
||||||
@@ -135,6 +136,7 @@ describe "CompileManager", ->
|
|||||||
compiler: @compiler
|
compiler: @compiler
|
||||||
timeout: @timeout
|
timeout: @timeout
|
||||||
image: @image
|
image: @image
|
||||||
|
flags: @flags
|
||||||
environment: @env
|
environment: @env
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
@@ -173,6 +175,7 @@ describe "CompileManager", ->
|
|||||||
compiler: @compiler
|
compiler: @compiler
|
||||||
timeout: @timeout
|
timeout: @timeout
|
||||||
image: @image
|
image: @image
|
||||||
|
flags: @flags
|
||||||
environment: {'CHKTEX_OPTIONS': '-nall -e9 -e10 -w15 -w16', 'CHKTEX_EXIT_ON_ERROR':1, 'CHKTEX_ULIMIT_OPTIONS': '-t 5 -v 64000'}
|
environment: {'CHKTEX_OPTIONS': '-nall -e9 -e10 -w15 -w16', 'CHKTEX_EXIT_ON_ERROR':1, 'CHKTEX_ULIMIT_OPTIONS': '-t 5 -v 64000'}
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
@@ -191,6 +194,7 @@ describe "CompileManager", ->
|
|||||||
compiler: @compiler
|
compiler: @compiler
|
||||||
timeout: @timeout
|
timeout: @timeout
|
||||||
image: @image
|
image: @image
|
||||||
|
flags: @flags
|
||||||
environment: @env
|
environment: @env
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|||||||
@@ -59,3 +59,21 @@ describe "LatexRunner", ->
|
|||||||
mainFile = command.slice(-1)[0]
|
mainFile = command.slice(-1)[0]
|
||||||
mainFile.should.equal "$COMPILE_DIR/main-file.tex"
|
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"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
SandboxedModule = require('sandboxed-module')
|
SandboxedModule = require('sandboxed-module')
|
||||||
sinon = require('sinon')
|
sinon = require('sinon')
|
||||||
require('chai').should()
|
require('chai').should()
|
||||||
|
expect = require('chai').expect
|
||||||
modulePath = require('path').join __dirname, '../../../app/js/RequestParser'
|
modulePath = require('path').join __dirname, '../../../app/js/RequestParser'
|
||||||
tk = require("timekeeper")
|
tk = require("timekeeper")
|
||||||
|
|
||||||
@@ -66,6 +67,21 @@ describe "RequestParser", ->
|
|||||||
it "should set the imageName", ->
|
it "should set the imageName", ->
|
||||||
@data.imageName.should.equal "basicImageName/here:2017-1"
|
@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", ->
|
describe "without a timeout specified", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
delete @validRequest.compile.options.timeout
|
delete @validRequest.compile.options.timeout
|
||||||
|
|||||||
Reference in New Issue
Block a user