Skip to content

Commit

Permalink
fix(outputters): Setup --makedeps to play along without explicit --ou…
Browse files Browse the repository at this point in the history
…tput

Both SILE's own regression suite and CaSILE have happily used this
broken feature for a long time because it always specifies --output
explicitly, but the --makedeps feature has been broken for a long time
because it couldn't derive the correct filename and was trying to
concatenate nil.
  • Loading branch information
alerque committed Apr 13, 2023
1 parent 402dddb commit 79bbccd
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion core/makedeps.lua
Expand Up @@ -29,7 +29,7 @@ local makeDeps = {
end
local depfile, err = io.open(self.filename, "w")
if not depfile then return SU.error(err) end
depfile:write(SILE.outputFilename .. ": " .. tostring(self._deps) .. "\n")
depfile:write(SILE.outputter:getOutputFilename() .. ": " .. tostring(self._deps) .. "\n")
depfile:close()
end
}
Expand Down
18 changes: 14 additions & 4 deletions outputters/base.lua
Expand Up @@ -34,10 +34,20 @@ function outputter.debugFrame (_, _, _) end

function outputter.debugHbox (_, _, _) end

function outputter.getOutputFilename (_, ext)
if SILE.outputFilename then return SILE.outputFilename end
if SILE.masterFilename then return SILE.masterFilename .. "." .. ext end
SU.error("Cannot guess output filename without an input name")
function outputter:getOutputFilename ()
local fname
if SILE.outputFilename then
fname = SILE.outputFilename
elseif SILE.masterFilename then
fname = SILE.masterFilename
if self.extension then
fname = fname .. "." .. self.extension
end
end
if not fname then
SU.error("Cannot guess output filename without an input name")
end
return fname
end

return outputter
3 changes: 2 additions & 1 deletion outputters/cairo.lua
Expand Up @@ -19,9 +19,10 @@ local sgs

local outputter = pl.class(base)
outputter._name = "cairo"
outputter.extension = "pdf"

function outputter:_init ()
local fname = self:getOutputFilename("pdf")
local fname = self:getOutputFilename()
local surface = cairolgi.PdfSurface.create(fname == "-" and "/dev/stdout" or fname, SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
cr = cairolgi.Context.create(surface)
move = cr.move_to
Expand Down
3 changes: 2 additions & 1 deletion outputters/debug.lua
Expand Up @@ -24,6 +24,7 @@ end

local outputter = pl.class(base)
outputter._name = "debug"
outputter.extension = "debug"

-- The outputter init can't actually initialize output (as logical as it might
-- have seemed) because that requires a page size which we don't know yet.
Expand All @@ -32,7 +33,7 @@ outputter._name = "debug"
function outputter:_ensureInit ()
if not started then
started = true -- keep this before self:_writeline or it will be a race condition!
local fname = self:getOutputFilename("debug")
local fname = self:getOutputFilename()
outfile = fname == "-" and io.stdout or io.open(fname, "w+")
if SILE.documentState.paperSize then
self:_writeline("Set paper size ", SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])
Expand Down
8 changes: 1 addition & 7 deletions outputters/dummy.lua
Expand Up @@ -2,12 +2,6 @@ local base = require("outputters.base")

local outputter = pl.class(base)
outputter._name = "dummy"

-- Most of the base outputter functions are just empty prototypes, but for the
-- few that actually do something override them...

local _dummy = function () end

outputter.getOutputFilename = _dummy
outputter.extension = "dummy"

return outputter
3 changes: 2 additions & 1 deletion outputters/libtexpdf.lua
Expand Up @@ -20,6 +20,7 @@ local _font

local outputter = pl.class(base)
outputter._name = "libtexpdf"
outputter.extension = "pdf"

-- The outputter init can't actually initialize output (as logical as it might
-- have seemed) because that requires a page size which we don't know yet.
Expand All @@ -28,7 +29,7 @@ outputter._name = "libtexpdf"
function outputter:_ensureInit ()
if not started then
local w, h = SILE.documentState.paperSize[1], SILE.documentState.paperSize[2]
local fname = self:getOutputFilename("pdf")
local fname = self:getOutputFilename()
pdf.init(fname == "-" and "/dev/stdout" or fname, w, h, SILE.full_version)
pdf.beginpage()
started = true
Expand Down
3 changes: 2 additions & 1 deletion outputters/podofo.lua
Expand Up @@ -19,6 +19,7 @@ local podofoFaces = {}

local outputer = pl.class(base)
outputer._name = "podofo"
outputter.extension = "pdf"

function outputer._init (_)
document = pdf.PdfMemDocument()
Expand All @@ -38,7 +39,7 @@ end

function outputer:finish ()
painter:FinishPage()
local fname = self:getOutputFilename("pdf")
local fname = self:getOutputFilename()
document:Write(fname == "-" and "/dev/stdout" or fname)
end

Expand Down
3 changes: 2 additions & 1 deletion outputters/text.lua
Expand Up @@ -8,14 +8,15 @@ local started = false

local outputter = pl.class(base)
outputter._name = "text"
outputter.extension = "txt"

-- The outputter init can't actually initialize output (as logical as it might
-- have seemed) because that requires a page size which we don't know yet.
-- function outputter:_init () end

function outputter:_ensureInit ()
if not outfile then
local fname = self:getOutputFilename("text")
local fname = self:getOutputFilename()
outfile = fname == "-" and io.stdout or io.open(fname, "w+")
end
end
Expand Down
11 changes: 0 additions & 11 deletions tests/absmin.expected

This file was deleted.

0 comments on commit 79bbccd

Please sign in to comment.