From 759131e6c87517b56a433dccde29658dbe6df023 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 12 Jul 2023 18:50:03 +0300 Subject: [PATCH] fix(core): Make masterFilename actually a filename Process the basename when that's specifically what we need rather than making it a basename initially and not having the extension information when we need it. --- classes/base.lua | 6 +++--- core/makedeps.lua | 2 +- core/sile.lua | 11 +++++------ documentation/c10-classdesign.sil | 2 +- outputters/base.lua | 2 +- packages/tableofcontents/init.lua | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/classes/base.lua b/classes/base.lua index e91b2feec..7cd902029 100644 --- a/classes/base.lua +++ b/classes/base.lua @@ -575,9 +575,9 @@ function class:finish () end SILE.typesetter:runHooks("pageend") -- normally run by the typesetter self:endPage() - if SILE.typesetter then - assert(SILE.typesetter:isQueueEmpty(), "queues not empty") - end + if SILE.typesetter then + assert(SILE.typesetter:isQueueEmpty(), "queues not empty") + end SILE.outputter:finish() self:runHooks("finish") end diff --git a/core/makedeps.lua b/core/makedeps.lua index 41718b6da..be2345c5a 100644 --- a/core/makedeps.lua +++ b/core/makedeps.lua @@ -25,7 +25,7 @@ local makeDeps = { write = function (self) self:add_modules() if type(self.filename) ~= "string" then - self.filename = SILE.masterFilename .. ".d" + self.filename = pl.path.splitext(SILE.masterFilename) .. ".d" end local depfile, err = io.open(self.filename, "w") if not depfile then return SU.error(err) end diff --git a/core/sile.lua b/core/sile.lua index eb9471610..75d10f800 100644 --- a/core/sile.lua +++ b/core/sile.lua @@ -291,7 +291,7 @@ function SILE.processString (doc, format, filename, options) -- a specific inputter to use, use it at the exclusion of all content type -- detection local inputter - if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename and SILE.inputter then + if filename and pl.path.normcase(pl.path.normpath(filename)) == pl.path.normcase(SILE.masterFilename) and SILE.inputter then inputter = SILE.inputter else format = format or detectFormat(doc, filename) @@ -301,7 +301,7 @@ function SILE.processString (doc, format, filename, options) inputter = SILE.inputters[format](options) -- If we did content detection *and* this is the master file, save the -- inputter for posterity and postambles - if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename then + if filename and pl.path.normcase(filename) == SILE.masterFilename then SILE.inputter = inputter end end @@ -321,11 +321,10 @@ function SILE.processFile (filename, format, options) -- Turn slashes around in the event we get passed a path from a Windows shell filename = filename:gsub("\\", "/") if not SILE.masterFilename then - -- Strip extension - SILE.masterFilename = string.match(filename, "(.+)%..-$") or filename + SILE.masterFilename = pl.path.normpath(filename) end if SILE.masterFilename and not SILE.masterDir then - SILE.masterDir = SILE.masterFilename:match("(.-)[^%/]+$") + SILE.masterDir = pl.path.dirname(SILE.masterFilename) end if SILE.masterDir and SILE.masterDir:len() >= 1 then _G.extendSilePath(SILE.masterDir) @@ -463,7 +462,7 @@ function SILE.finish () end if SU.debugging("profile") then ProFi:stop() - ProFi:writeReport(SILE.masterFilename..'.profile.txt') + ProFi:writeReport(pl.path.splitext(SILE.masterFilename) .. '.profile.txt') end if SU.debugging("versions") then SILE.shaper:debugVersions() diff --git a/documentation/c10-classdesign.sil b/documentation/c10-classdesign.sil index 6038fdf11..ad3909290 100644 --- a/documentation/c10-classdesign.sil +++ b/documentation/c10-classdesign.sil @@ -496,7 +496,7 @@ Here is a function to be called by the \code{finish} output routine: function package.writeToc (_) -- (Simplified from the actual implementation.) local tocdata = pl.pretty.write(SILE.scratch.tableofcontents) - local tocfile, err = io.open(SILE.masterFilename .. '.toc', "w") + local tocfile, err = io.open(pl.path.splitext(SILE.masterFilename) .. '.toc', "w") if not tocfile then return SU.error(err) end tocfile:write("return " .. tocdata) tocfile:close() diff --git a/outputters/base.lua b/outputters/base.lua index b130f4b10..387fc28eb 100644 --- a/outputters/base.lua +++ b/outputters/base.lua @@ -39,7 +39,7 @@ function outputter:getOutputFilename () if SILE.outputFilename then fname = SILE.outputFilename elseif SILE.masterFilename then - fname = SILE.masterFilename + fname = pl.path.splitext(SILE.masterFilename) if self.extension then fname = fname .. "." .. self.extension end diff --git a/packages/tableofcontents/init.lua b/packages/tableofcontents/init.lua index 0fb8bd667..d87c73cfe 100644 --- a/packages/tableofcontents/init.lua +++ b/packages/tableofcontents/init.lua @@ -19,7 +19,7 @@ end function package.writeToc (_) local tocdata = pl.pretty.write(SILE.scratch.tableofcontents) - local tocfile, err = io.open(SILE.masterFilename .. '.toc', "w") + local tocfile, err = io.open(pl.path.splitext(SILE.masterFilename) .. '.toc', "w") if not tocfile then return SU.error(err) end tocfile:write("return " .. tocdata) tocfile:close() @@ -34,7 +34,7 @@ function package.readToc (_) -- already loaded return SILE.scratch._tableofcontents end - local tocfile, _ = io.open(SILE.masterFilename .. '.toc') + local tocfile, _ = io.open(pl.path.splitext(SILE.masterFilename) .. '.toc') if not tocfile then return false -- No TOC yet end