summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/data-tmp.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
committerKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
commit824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch)
treeabfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/data-tmp.lua
parent689aefb0727676ed3cddf331337b4be226495e72 (diff)
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/data-tmp.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/data-tmp.lua95
1 files changed, 58 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/context/base/data-tmp.lua b/Master/texmf-dist/tex/context/base/data-tmp.lua
index 6e235dd3466..525698d1e86 100644
--- a/Master/texmf-dist/tex/context/base/data-tmp.lua
+++ b/Master/texmf-dist/tex/context/base/data-tmp.lua
@@ -24,7 +24,9 @@ luatools with a recache feature.</p>
local format, lower, gsub, concat = string.format, string.lower, string.gsub, table.concat
local serialize, serializetofile = table.serialize, table.tofile
-local mkdirs, isdir = dir.mkdirs, lfs.isdir
+local mkdirs, isdir, isfile = dir.mkdirs, lfs.isdir, lfs.isfile
+local addsuffix, is_writable, is_readable = file.addsuffix, file.is_writable, file.is_readable
+local formatters = string.formatters
local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end)
local trace_cache = false trackers.register("resolvers.cache", function(v) trace_cache = v end)
@@ -37,7 +39,7 @@ local resolvers = resolvers
-- intermezzo
local directive_cleanup = false directives.register("system.compile.cleanup", function(v) directive_cleanup = v end)
-local directive_strip = true directives.register("system.compile.strip", function(v) directive_strip = v end)
+local directive_strip = false directives.register("system.compile.strip", function(v) directive_strip = v end)
local compile = utilities.lua.compile
@@ -49,8 +51,10 @@ end
-- end of intermezzo
-caches = caches or { }
-local caches = caches
+caches = caches or { }
+local caches = caches
+
+local luasuffixes = utilities.lua.suffixes
caches.base = caches.base or "luatex-cache"
caches.more = caches.more or "context"
@@ -78,19 +82,19 @@ local function identify()
cachepath = file.collapsepath(cachepath)
local valid = isdir(cachepath)
if valid then
- if file.is_readable(cachepath) then
+ if is_readable(cachepath) then
readables[#readables+1] = cachepath
- if not writable and file.is_writable(cachepath) then
+ if not writable and is_writable(cachepath) then
writable = cachepath
end
end
elseif not writable and caches.force then
local cacheparent = file.dirname(cachepath)
- if file.is_writable(cacheparent) and true then -- we go on anyway (needed for mojca's kind of paths)
+ if is_writable(cacheparent) and true then -- we go on anyway (needed for mojca's kind of paths)
if not caches.ask or io.ask(format("\nShould I create the cache path %s?",cachepath), "no", { "yes", "no" }) == "yes" then
mkdirs(cachepath)
- if isdir(cachepath) and file.is_writable(cachepath) then
- report_caches("created: %s",cachepath)
+ if isdir(cachepath) and is_writable(cachepath) then
+ report_caches("path %a created",cachepath)
writable = cachepath
readables[#readables+1] = cachepath
end
@@ -111,8 +115,8 @@ local function identify()
cachepath = resolvers.resolve(cachepath)
cachepath = resolvers.cleanpath(cachepath)
local valid = isdir(cachepath)
- if valid and file.is_readable(cachepath) then
- if not writable and file.is_writable(cachepath) then
+ if valid and is_readable(cachepath) then
+ if not writable and is_writable(cachepath) then
readables[#readables+1] = cachepath
writable = cachepath
break
@@ -149,9 +153,9 @@ local function identify()
-- end
if trace_cache then
for i=1,#readables do
- report_caches("using readable path '%s' (order %s)",readables[i],i)
+ report_caches("using readable path %a (order %s)",readables[i],i)
end
- report_caches("using writable path '%s'",writable)
+ report_caches("using writable path %a",writable)
end
identify = function()
return writable, readables
@@ -166,10 +170,10 @@ function caches.usedpaths()
for i=1,#readables do
local readable = readables[i]
if usedreadables[i] or readable == writable then
- result[#result+1] = format("readable: '%s' (order %s)",readable,i)
+ result[#result+1] = formatters["readable: %a (order %s)"](readable,i)
end
end
- result[#result+1] = format("writable: '%s'",writable)
+ result[#result+1] = formatters["writable: %a"](writable)
return result
else
return writable
@@ -181,12 +185,11 @@ function caches.configfiles()
end
function caches.hashed(tree)
- tree = gsub(tree,"\\$","/")
- tree = gsub(tree,"/+$","")
+ tree = gsub(tree,"[\\/]+$","")
tree = lower(tree)
local hash = md5.hex(tree)
if trace_cache or trace_locating then
- report_caches("hashing tree %s, hash %s",tree,hash)
+ report_caches("hashing tree %a, hash %a",tree,hash)
end
return hash
end
@@ -202,7 +205,7 @@ end
local r_cache, w_cache = { }, { } -- normally w in in r but who cares
-local function getreadablepaths(...) -- we can optimize this as we have at most 2 tags
+local function getreadablepaths(...)
local tags = { ... }
local hash = concat(tags,"/")
local done = r_cache[hash]
@@ -245,7 +248,7 @@ function caches.getfirstreadablefile(filename,...)
for i=1,#rd do
local path = rd[i]
local fullname = file.join(path,filename)
- if file.is_readable(fullname) then
+ if is_readable(fullname) then
usedreadables[i] = true
return fullname, path
end
@@ -266,7 +269,7 @@ function caches.define(category,subcategory) -- for old times sake
end
function caches.setluanames(path,name)
- return path .. "/" .. name .. ".tma", path .. "/" .. name .. ".tmc"
+ return format("%s/%s.%s",path,name,luasuffixes.tma), format("%s/%s.%s",path,name,luasuffixes.tmc)
end
function caches.loaddata(readables,name)
@@ -276,7 +279,20 @@ function caches.loaddata(readables,name)
for i=1,#readables do
local path = readables[i]
local tmaname, tmcname = caches.setluanames(path,name)
- local loader = loadfile(tmcname) or loadfile(tmaname)
+ local loader = false
+ if isfile(tmcname) then
+ loader = loadfile(tmcname)
+ end
+ if not loader and isfile(tmaname) then
+ -- in case we have a different engine
+ utilities.lua.compile(tmaname,tmcname)
+ if isfile(tmcname) then
+ loader = loadfile(tmcname)
+ end
+ if not loader then
+ loader = loadfile(tmaname)
+ end
+ end
if loader then
loader = loader()
collectgarbage("step")
@@ -288,11 +304,15 @@ end
function caches.is_writable(filepath,filename)
local tmaname, tmcname = caches.setluanames(filepath,filename)
- return file.is_writable(tmaname)
+ return is_writable(tmaname)
end
local saveoptions = { compact = true }
+-- add some point we will only use the internal bytecode compiler and
+-- then we can flag success in the tma so that it can trigger a compile
+-- if the other engine
+
function caches.savedata(filepath,filename,data,raw)
local tmaname, tmcname = caches.setluanames(filepath,filename)
local reduce, simplify = true, true
@@ -318,9 +338,9 @@ end
function caches.loadcontent(cachename,dataname)
local name = caches.hashed(cachename)
- local full, path = caches.getfirstreadablefile(name ..".lua","trees")
+ local full, path = caches.getfirstreadablefile(addsuffix(name,luasuffixes.lua),"trees")
local filename = file.join(path,name)
- local blob = loadfile(filename .. ".luc") or loadfile(filename .. ".lua")
+ local blob = loadfile(addsuffix(filename,luasuffixes.luc)) or loadfile(addsuffix(filename,luasuffixes.lua))
if blob then
local data = blob()
if data and data.content then
@@ -328,20 +348,20 @@ function caches.loadcontent(cachename,dataname)
if data.version == resolvers.cacheversion then
content_state[#content_state+1] = data.uuid
if trace_locating then
- report_resolvers("loading '%s' for '%s' from '%s'",dataname,cachename,filename)
+ report_resolvers("loading %a for %a from %a",dataname,cachename,filename)
end
return data.content
else
- report_resolvers("skipping '%s' for '%s' from '%s' (version mismatch)",dataname,cachename,filename)
+ report_resolvers("skipping %a for %a from %a (version mismatch)",dataname,cachename,filename)
end
else
- report_resolvers("skipping '%s' for '%s' from '%s' (datatype mismatch)",dataname,cachename,filename)
+ report_resolvers("skipping %a for %a from %a (datatype mismatch)",dataname,cachename,filename)
end
elseif trace_locating then
- report_resolvers("skipping '%s' for '%s' from '%s' (no content)",dataname,cachename,filename)
+ report_resolvers("skipping %a for %a from %a (no content)",dataname,cachename,filename)
end
elseif trace_locating then
- report_resolvers("skipping '%s' for '%s' from '%s' (invalid file)",dataname,cachename,filename)
+ report_resolvers("skipping %a for %a from %a (invalid file)",dataname,cachename,filename)
end
end
@@ -355,11 +375,12 @@ end
function caches.savecontent(cachename,dataname,content)
local name = caches.hashed(cachename)
- local full, path = caches.setfirstwritablefile(name ..".lua","trees")
+ local full, path = caches.setfirstwritablefile(addsuffix(name,luasuffixes.lua),"trees")
local filename = file.join(path,name) -- is full
- local luaname, lucname = filename .. ".lua", filename .. ".luc"
+ local luaname = addsuffix(filename,luasuffixes.lua)
+ local lucname = addsuffix(filename,luasuffixes.luc)
if trace_locating then
- report_resolvers("preparing '%s' for '%s'",dataname,cachename)
+ report_resolvers("preparing %a for %a",dataname,cachename)
end
local data = {
type = dataname,
@@ -373,20 +394,20 @@ function caches.savecontent(cachename,dataname,content)
local ok = io.savedata(luaname,serialize(data,true))
if ok then
if trace_locating then
- report_resolvers("category '%s', cachename '%s' saved in '%s'",dataname,cachename,luaname)
+ report_resolvers("category %a, cachename %a saved in %a",dataname,cachename,luaname)
end
if utilities.lua.compile(luaname,lucname) then
if trace_locating then
- report_resolvers("'%s' compiled to '%s'",dataname,lucname)
+ report_resolvers("%a compiled to %a",dataname,lucname)
end
return true
else
if trace_locating then
- report_resolvers("compiling failed for '%s', deleting file '%s'",dataname,lucname)
+ report_resolvers("compiling failed for %a, deleting file %a",dataname,lucname)
end
os.remove(lucname)
end
elseif trace_locating then
- report_resolvers("unable to save '%s' in '%s' (access error)",dataname,luaname)
+ report_resolvers("unable to save %a in %a (access error)",dataname,luaname)
end
end