Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into docs-c05-revamping
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 25, 2023
2 parents 78c2892 + d09efb8 commit 3d1fa4d
Show file tree
Hide file tree
Showing 25 changed files with 280 additions and 191 deletions.
8 changes: 4 additions & 4 deletions .cirrus.yml
Expand Up @@ -15,13 +15,13 @@ task:
fingerprint_script: cat Makefile-fonts
luarocks_cache:
folder: /usr/local/lib/luarocks
fingerprint_script: cat sile-dev-1.rockspec
fingerprint_script: cat sile.rockspec.in
luarocks_lua_cache:
folder: /usr/local/share/lua
fingerprint_script: cat sile-dev-1.rockspec
fingerprint_script: cat sile.rockspec.in
luarocks_lib_cache:
folder: /usr/local/lib/lua
fingerprint_script: cat sile-dev-1.rockspec
fingerprint_script: cat sile.rockspec.in
dependencies_script:
- pkg install -y autoconf automake fontconfig GentiumPlus git gmake harfbuzz libtool pkgconf png
- pkg install -y lua54 lua54-lpeg lua54-luafilesystem lua54-luarocks lua54-luasec lua54-luasocket
Expand All @@ -46,7 +46,7 @@ task:
- ./bootstrap.sh
configure_script: |
./configure MAKE=gmake \
--enable-developer LUAROCKS=false LUACHECK=false BUSTED=false \
--enable-developer LUAROCKS=false LUACHECK=false BUSTED=false NIX=false \
--disable-font-variations \
--with-system-luarocks \
--without-manual
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
path: |
lua_modules
key: luarocks-${{ hashFiles('Makefile-luarocks', 'sile-dev-1.rockspec') }}
key: luarocks-${{ hashFiles('Makefile-luarocks', 'sile.rockspec.in') }}
- name: Fetch tags
run: |
git fetch --prune --tags ||:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
path: |
lua_modules
key: luarocks-luajit-${{ hashFiles('Makefile-luarocks', 'sile-dev-1.rockspec') }}
key: luarocks-luajit-${{ hashFiles('Makefile-luarocks', 'sile.rockspec.in') }}
- name: Fetch tags
run: |
git fetch --prune --tags ||:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
run: |
./bootstrap.sh
./configure \
--enable-developer LUACHECK=false \
--enable-developer LUACHECK=false NIX=false \
--disable-font-variations \
--without-system-luarocks \
--with-luajit \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
path: |
lua_modules
key: luarocks-${{ matrix.luaVersion[0] }}-${{ hashFiles('Makefile-luarocks', 'sile-dev-1.rockspec') }}
key: luarocks-${{ matrix.luaVersion[0] }}-${{ hashFiles('Makefile-luarocks', 'sile.rockspec.in') }}
- name: Fetch tags
run: |
git fetch --prune --tags ||:
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
run: |
./bootstrap.sh
./configure \
--enable-developer LUACHECK=false \
--enable-developer LUACHECK=false NIX=false \
--disable-font-variations \
--without-system-luarocks \
--with${{ startsWith(matrix.luaVersion[0], '5') && 'out' || '' }}-luajit \
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -76,6 +76,7 @@ tags
Makefile-distfiles
documentation/*.pdf
gource.webm
*.rockspec
.fonts/*
.sources/*
/sile
Expand All @@ -87,6 +88,7 @@ sile.1
*.so
core/version.lua
core/features.lua
core/pathsetup.lua

# Nix symlink to builds
/result
2 changes: 2 additions & 0 deletions .luacheckrc
Expand Up @@ -26,6 +26,8 @@ globals = {
"luautf8",
"pl",
"fluent",
"extendSilePath",
"executablePath",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
}
Expand Down
2 changes: 2 additions & 0 deletions .luarc.json
Expand Up @@ -7,6 +7,8 @@
"luautf8",
"pl",
"fluent",
"extendSilePath",
"executablePath",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
],
Expand Down
13 changes: 5 additions & 8 deletions Makefile.am
Expand Up @@ -50,7 +50,7 @@ _MANUAL = $(MANUAL)
endif

nobase_dist_pkgdata_DATA = $(SILEDATA) $(LUALIBRARIES)
nobase_nodist_pkgdata_DATA = core/features.lua core/version.lua $(LUAMODULES)
nobase_nodist_pkgdata_DATA = core/features.lua core/pathsetup.lua core/version.lua $(LUAMODULES)
dist_man_MANS = sile.1
dist_doc_DATA = README.md CHANGELOG.md
dist_pdf_DATA = $(_MANUAL)
Expand All @@ -60,11 +60,11 @@ EXTRA_DIST = spec tests documentation sile-dev-1.rockspec fontconfig.conf
EXTRA_DIST += Makefile-distfiles
EXTRA_DIST += build-aux/action-updater.js build-aux/decore-automake.sh build-aux/git-version-gen build-aux/list-dist-files.sh
EXTRA_DIST += Dockerfile build-aux/docker-bootstrap.sh build-aux/docker-fontconfig.conf hooks/build
EXTRA_DIST += default.nix flake.nix flake.lock libtexpdf.git-rev shell.nix
EXTRA_DIST += default.nix flake.nix flake.lock shell.nix
EXTRA_DIST += package.json # imported by both Nix and Docker
EXTRA_DIST += $(MANUAL)

BUILT_SOURCES = .version core/features.lua core/version.lua Makefile-distfiles
BUILT_SOURCES = .version core/features.lua core/pathsetup.lua core/version.lua Makefile-distfiles

CLEANFILES = $(bin_SCRIPTS) $(dist_man_MANS) $(BUILT_SOURCES) $(DEPFILES) $(ACTUALS) $(TESTPDFS) $(MANUAL) $(_BUILT_SUBDIRS) .version-prev

Expand All @@ -85,9 +85,6 @@ _BRANCH_REF != $(AWK) '{print ".git/" $$2}' .git/HEAD 2>/dev/null ||:
cmp -s "$@" "$@-prev" || ( autoreconf configure.ac --force && build-aux/decore-automake.sh ); \
fi

libtexpdf.git-rev: $(_BRANCH_REF)
$(GIT) submodule status -- libtexpdf | $(AWK) '{ print $$1 }' > $@

dist-hook: $(MANUAL)
cd $(distdir)
printf "$(VERSION)" > .tarball-version
Expand Down Expand Up @@ -130,8 +127,8 @@ sile-%.md: CHANGELOG.md
update_libtexpdf:
$(GIT) diff-index --quiet --cached HEAD || exit 1 # die if anything already staged
$(GIT) submodule update --init --remote -- libtexpdf
$(GIT) submodule status -- libtexpdf | $(AWK) '{ print $$1 }' > libtexpdf.git-rev
$(GIT) add -- libtexpdf libtexpdf.git-rev
$(NIX) flake lock --override-input libtexpdf-src github:sile-typesetter/libtexpdf/$(shell $(GIT) submodule status -- libtexpdf | awk '{print $$1}')
$(GIT) add -- libtexpdf flake.lock
$(GIT) diff-index --quiet --cached HEAD || $(GIT) commit -m "chore(build): Pin latest libtexpdf library submodule"

DEPDIR := .deps
Expand Down
2 changes: 1 addition & 1 deletion build-aux/list-dist-files.sh.in
Expand Up @@ -7,7 +7,7 @@ finder () {
}

printf '%s' "SILEDATA ="
finder core -name '*.lua' -not -name '*_spec.lua' -not -name 'version.lua'
finder core -name '*.lua' -not -name '*_spec.lua' -not -name 'version.lua' -not -name 'features.lua' -not -name 'pathsetup.lua'
finder classes inputters languages outputters packages shapers typesetters pagebuilders -name '*.lua' -not -name '*_spec.lua'
finder classes i18n packages -name '*.ftl'
finder packages -name '*.svg'
Expand Down
7 changes: 6 additions & 1 deletion configure.ac
Expand Up @@ -200,6 +200,7 @@ AM_COND_IF([DEPENDENCY_CHECKS], [
AX_PROGVAR([busted])
AX_PROGVAR([luacheck])
AX_PROGVAR([luarocks])
AX_PROGVAR([nix])
AX_PROGVAR([perl])
])
Expand Down Expand Up @@ -245,11 +246,15 @@ adl_RECURSIVE_EVAL(["${libdir}/${TRANSFORMED_PACKAGE_NAME}"], [SILE_LIB_PATH])
AC_DEFINE_UNQUOTED([SILE_LIB_PATH],["${SILE_LIB_PATH}"],[Path for SILE libraries])
AC_SUBST([SILE_LIB_PATH])

AC_SUBST([ROCKSPECWARNING], ["DO NOT EDIT! Modify template sile.rockspec.in"])
AC_SUBST([ROCKREV], [1])

AX_SUBST_MAN_DATE

AC_CONFIG_FILES([build-aux/list-dist-files.sh], [chmod +x build-aux/list-dist-files.sh])
AC_CONFIG_FILES([Makefile src/Makefile sile.1 core/features.lua core/version.lua])
AC_CONFIG_FILES([Makefile src/Makefile sile.1 core/features.lua core/pathsetup.lua core/version.lua])
AC_CONFIG_FILES([sile tests/regressions.pl], [chmod +x sile tests/regressions.pl])
AC_CONFIG_FILES([sile-dev-1.rockspec:sile.rockspec.in])

AC_ARG_PROGRAM

Expand Down
24 changes: 14 additions & 10 deletions core/cli.lua
Expand Up @@ -15,7 +15,7 @@ cli.parseArguments = function ()
changed to .pdf. Additional input or output formats can be handled by requiring a
module that adds support for them first.
]])
cliargs:splat("INPUT", "input document, by default in SIL or XML format")
cliargs:splat("INPUTS", "input document(s), by default in SIL or XML format", nil, 999)
cliargs:option("-b, --backend=VALUE", "choose an alternative output backend")
cliargs:option("-c, --class=VALUE", "override default document class")
cliargs:option("-d, --debug=VALUE", "show debug information for tagged aspects of SILE’s operation", {})
Expand All @@ -42,16 +42,20 @@ cli.parseArguments = function ()
local code = parse_err:match("^Usage:") and 0 or 1
os.exit(code)
end
if opts.INPUT then
if opts.INPUT == "STDIO" then
opts.INPUT = "-"
if opts.INPUTS then
local has_input_filename = false
pl.tablex.foreachi(opts.INPUTS, function (v, k)
if v == "STDIO" then
opts.INPUTS[k] = "-"
elseif not has_input_filename then
has_input_filename = true
end
end)
if not has_input_filename and not opts.output then
SU.error("Unable to derive an output filename (perhaps because input is a STDIO stream).\n"..
" Please use --output to set one explicitly.")
end
SILE.input.filename = opts.INPUT
-- Turn slashes around in the event we get passed a path from a Windows shell
local filename = opts.INPUT:gsub("\\", "/")
-- Strip extension
SILE.masterFilename = string.match(filename, "(.+)%..-$") or filename
SILE.masterDir = SILE.masterFilename:match("(.-)[^%/]+$")
SILE.input.filenames = opts.INPUTS
end
if opts.backend then
SILE.backend = opts.backend
Expand Down
72 changes: 72 additions & 0 deletions core/pathsetup.lua.in
@@ -0,0 +1,72 @@
local executable = debug.getinfo(3, "S").source
local luaversion = _VERSION:match("%d+%.%d+")

-- Normalize possibly dirty Lua path formatting shortcut: /./ → /
-- Even leafo/gh-actions-luarocks takes this shortcut which inhibits duplicate cleanup
package.path = package.path:gsub("/%./", "/")
package.cpath = package.cpath:gsub("/%./", "/")

local function prepend_and_dedup (segment, path)
local escaped = segment:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]','%%%1') -- copied from pl.utils.escape() which we can't load yet
local striped = path:gsub(("^%s"):format(escaped), ""):gsub((";%s"):format(escaped), "")
return ("%s;%s"):format(segment, striped)
end

local function prependPath (path)
package.path = prepend_and_dedup(path .. "/?/init.lua", package.path)
package.path = prepend_and_dedup(path .. "/?.lua", package.path)
end

local function prependCPath (path)
package.cpath = prepend_and_dedup(path .. "/?.@SHARED_LIB_EXT@", package.cpath)
end

local function extendPaths (path, ours)
prependCPath(path)
prependPath(path)
if ours then
prependPath(path .. "/lua-libraries")
if "@SYSTEM_LUAROCKS_FALSE@" == "" then -- see ./configure --with[out]-system-luarocks
prependCPath(path .. "/lua_modules/lib/lua/" .. luaversion)
prependPath(path .. "/lua_modules/share/lua/" .. luaversion)
end
else
prependCPath(path .. "/sile")
prependPath(path .. "/sile")
end
end

-- Facilitate loading SILE classes & packages from system LuaRocks
-- Also weed out CWD relative paths, we add them in a different order later
local luapath = {}
local extpath = {}
for path in package.path:gmatch("[^;]+") do
table.insert(extpath, tostring(path:gsub("%?", "sile/?")))
table.insert(luapath, path)
end
package.path = table.concat(luapath, ";")

extendPaths("@SILE_PATH@", true)
extendPaths("@SILE_LIB_PATH@", true)

package.path = table.concat(extpath, ";") .. ";" .. package.path

local pathvar = os.getenv("SILE_PATH")
if pathvar then
for path in string.gmatch(pathvar, "[^;]+") do
if not path:match("^./") and path:len() >= 1 then
extendPaths(path)
end
end
end

local cwd = executable:gsub("(.*)(/.*)", "%1")
if cwd:match("^@") then -- Consider "ours" for the sake of Nix Flake
extendPaths(".", true)
else
if cwd ~= "./" then extendPaths(cwd) end
extendPaths(".")
end

_G.extendSilePath = extendPaths
_G.executablePath = executable
39 changes: 35 additions & 4 deletions core/sile.lua
Expand Up @@ -29,6 +29,9 @@ fluent = require("fluent")()
-- Includes for _this_ scope
local lfs = require("lfs")

-- Developer tooling profiler
local ProFi

SILE.utilities = require("core.utilities")
SU = SILE.utilities -- regrettable global alias

Expand Down Expand Up @@ -59,7 +62,7 @@ SILE.rawHandlers = {}
-- needed for a user to use a SILE-as-a-library verion to produce documents
-- programatically.
SILE.input = {
filename = "",
filenames = {},
evaluates = {},
evaluateAfters = {},
includes = {},
Expand Down Expand Up @@ -131,6 +134,14 @@ SILE.init = function ()
SILE.outputter = SILE.outputters.dummy()
end
SILE.pagebuilder = SILE.pagebuilders.base()
io.stdout:setvbuf("no")
if SU.debugging("profile") then
ProFi = require("ProFi")
ProFi:start()
end
if SILE.makeDeps then
SILE.makeDeps:add(_G.executablePath)
end
runEvals(SILE.input.evaluates, "evaluate")
end

Expand Down Expand Up @@ -280,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 filename:gsub("STDIN", "-") == SILE.input.filename and SILE.inputter then
if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename and SILE.inputter then
inputter = SILE.inputter
else
format = format or detectFormat(doc, filename)
Expand All @@ -290,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 filename:gsub("STDIN", "-") == SILE.input.filename then
if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename then
SILE.inputter = inputter
end
end
Expand All @@ -304,8 +315,21 @@ function SILE.processFile (filename, format, options)
local doc
if filename == "-" then
filename = "STDIN"
SILE.masterFilename = "STDIN"
doc = io.stdin:read("*a")
else
-- 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
end
if SILE.masterFilename and not SILE.masterDir then
SILE.masterDir = SILE.masterFilename:match("(.-)[^%/]+$")
end
if SILE.masterDir and SILE.masterDir:len() >= 1 then
_G.extendSilePath(SILE.masterDir)
end
filename = SILE.resolveFile(filename)
if not filename then
SU.error("Could not find file")
Expand Down Expand Up @@ -356,7 +380,7 @@ function SILE.resolveFile (filename, pathprefix)
candidates[#candidates+1] = "?"
-- Iterate through the directory of the master file, the SILE_PATH variable, and the current directory
-- Check for prefixed paths first, then the plain path in that fails
if SILE.masterFilename then
if SILE.masterDir then
for path in SU.gtoke(SILE.masterDir..";"..tostring(os.getenv("SILE_PATH")), ";") do
if path.string and path.string ~= "nil" then
if pathprefix then candidates[#candidates+1] = pl.path.join(path.string, pathprefix, "?") end
Expand Down Expand Up @@ -437,6 +461,13 @@ function SILE.finish ()
if not SILE.quiet then
io.stderr:write("\n")
end
if SU.debugging("profile") then
ProFi:stop()
ProFi:writeReport(SILE.masterFilename..'.profile.txt')
end
if SU.debugging("versions") then
SILE.shaper:debugVersions()
end
end

-- Internal libraries that run core SILE functions on load
Expand Down

0 comments on commit 3d1fa4d

Please sign in to comment.