Skip to content

Commit

Permalink
Merge c7d7253 into dff4557
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Apr 27, 2023
2 parents dff4557 + c7d7253 commit 232302e
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 153 deletions.
6 changes: 3 additions & 3 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 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
2 changes: 1 addition & 1 deletion .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
2 changes: 1 addition & 1 deletion .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
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
4 changes: 2 additions & 2 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 @@ -64,7 +64,7 @@ EXTRA_DIST += default.nix flake.nix flake.lock libtexpdf.git-rev 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 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
6 changes: 5 additions & 1 deletion configure.ac
Expand Up @@ -245,11 +245,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
5 changes: 0 additions & 5 deletions core/cli.lua
Expand Up @@ -47,11 +47,6 @@ cli.parseArguments = function ()
opts.INPUT = "-"
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("(.-)[^%/]+$")
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
32 changes: 31 additions & 1 deletion 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 @@ -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 @@ -306,6 +317,18 @@ function SILE.processFile (filename, format, options)
filename = "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 +379,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 +460,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
30 changes: 24 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions sile-dev-1.rockspec

This file was deleted.

0 comments on commit 232302e

Please sign in to comment.