From 00fd07c628af41b0709d25fd00805385be561459 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 3 Jul 2013 11:04:52 +0200 Subject: add cache directory hint to luaotfload-tool; manage paths more consistently --- luaotfload-basics-gen.lua | 4 ++-- luaotfload-database.lua | 18 +++++++++--------- luaotfload-merged.lua | 4 ++-- luaotfload-tool.lua | 39 +++++++++++++++++++-------------------- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/luaotfload-basics-gen.lua b/luaotfload-basics-gen.lua index 4a46fbb..a5da2fd 100644 --- a/luaotfload-basics-gen.lua +++ b/luaotfload-basics-gen.lua @@ -151,13 +151,13 @@ do -- quite like tex live or so - if cachepaths == "" then + if cachepaths == "$TEXMFCACHE" then cachepaths = kpse.expand_var('$TEXMFVAR') or "" end -- this also happened to be used - if cachepaths == "" then + if cachepaths == "$TEXMFVAR" then cachepaths = kpse.expand_var('$VARTEXMF') or "" end diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 338ffa6..c0aadaf 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -97,7 +97,8 @@ names.data = nil --- contains the loaded database names.lookups = nil --- contains the lookup cache names.path = { dir = "", --- db and cache directory - basename = "luaotfload-names.lua", --- db file name + basename = config.luaotfload.names_file + or "luaotfload-names.lua", path = "", --- full path to db file lookup_basename = "luaotfload-lookup-cache.lua", --- cache file name lookup_path = "", --- cache full path @@ -108,7 +109,7 @@ names.path = { -- uses TEXMFCACHE or TEXMFVAR as starting points. local writable_path if caches then - writable_path = caches.getwritablepath("names","") + writable_path = caches.getwritablepath "names" if not writable_path then luaotfload.error("Impossible to find a suitable writeable cache...") end @@ -2047,21 +2048,20 @@ end local getwritablecachepath = function ( ) --- fonts.handlers.otf doesn’t exist outside a Luatex run, --- so we have to improvise - local writable = caches.getwritablepath () + local writable = caches.getwritablepath + (config.luaotfload.cache_dir) if writable then - writable = writable .. "/fonts" - if lfsisdir (writable) then - return writable - end + return writable end end local getreadablecachepaths = function ( ) - local readables = caches.getreadablepaths () + local readables = caches.getreadablepaths + (config.luaotfload.cache_dir) local result = { } if readables then for i=1, #readables do - local readable = readables[i] .. "/fonts" + local readable = readables[i] if lfsisdir (readable) then result[#result+1] = readable end diff --git a/luaotfload-merged.lua b/luaotfload-merged.lua index 9d708bf..52c199a 100644 --- a/luaotfload-merged.lua +++ b/luaotfload-merged.lua @@ -3044,10 +3044,10 @@ if not caches.namespace or caches.namespace=="" or caches.namespace=="context" t end do local cachepaths=kpse.expand_var('$TEXMFCACHE') or "" - if cachepaths=="" then + if cachepaths=="" or cachepaths == "$TEXMFCACHE" then cachepaths=kpse.expand_var('$TEXMFVAR') or "" end - if cachepaths=="" then + if cachepaths=="" or cachepaths == "$TEXMFVAR" then cachepaths=kpse.expand_var('$VARTEXMF') or "" end if cachepaths=="" then diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 392be6e..a353b37 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -80,9 +80,13 @@ After support for querying the database was added, the latter appeared to be the more appropriate. --doc]]-- -config = config or { } -local config = config -config.luaotfload = config.luaotfload or { } +config = config or { } +local config = config +config.luaotfload = config.luaotfload or { } +config.luaotfload.names_dir = config.luaotfload.names_dir or "names" +config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts" +config.luaotfload.names_file = config.luaotfload.names_file + or "luaotfload-names.lua" do -- we don’t have file.basename and the likes yet, so inline parser ftw local slash = P"/" @@ -109,19 +113,6 @@ config.lualibs.load_extended = false require "lualibs" ---- prepare directories: the cache function in Luatex-Fonts ---- checks for writable directory only on startup, so everything ---- has to be laid out before we load basics-gen - -local cachepath = kpse.expand_var "$TEXMFVAR" -if not lfs.isdir(cachepath) then - dir.mkdirs(cachepath) - if not lfs.isdir(cachepath) then - texiowrite_nl(stringformat( - "ERROR could not create directory %s", cachepath)) - end -end - --[[doc-- \fileent{luatex-basics-gen.lua} calls functions from the \luafunction{texio.*} library; too much for our taste. @@ -144,8 +135,11 @@ local names = fonts.names local sanitize_string = names.sanitize_string -local db_src_out = names.path.dir.."/"..names.path.basename -local db_bin_out = file.replacesuffix(db_src_out, "luc") +--local db_src_out = names.path.dir.."/"..names.path.basename +local names_plain = file.join + (caches.getwritablepath (config.luaotfload.names_dir), + config.luaotfload.names_file) +local names_bin = file.replacesuffix (names_plain, "luc") local help_messages = { ["luaotfload-tool"] = [[ @@ -205,6 +199,9 @@ The font database will be saved to --cache= operate on font cache, where is “show”, “purge”, or “erase” +The font cache will be written to + %s + ]], mkluatexfontdb = [[ @@ -235,8 +232,10 @@ local help_msg = function ( ) or help_messages["luaotfload-tool"] texiowrite_nl(stringformat(template, config.luaotfload.self, - db_src_out, - db_bin_out)) + names_plain, + names_bin, + caches.getwritablepath + (config.luaotfload.cache_dir))) end local version_msg = function ( ) -- cgit v1.2.3