data-use.lua /size: 6168 b    last modification: 2025-02-21 11:03
1if not modules then modules = { } end modules ['data-use'] = {
2    version   = 1.001,
3    comment   = "companion to luat-lib.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local format = string.format
10
11local trace_locating = false  trackers.register("resolvers.locating", function(v) trace_locating = v end)
12
13local report_mounts = logs.reporter("resolvers","mounts")
14
15local resolvers = resolvers
16local findfile  = resolvers.findfile
17
18-- -- This should mount a zip file so that we can run from zip files but I never went
19-- -- on with it. It's really old code, from right when we started with luatex and
20-- -- mkiv. Nowadays I'd use a lua specification file instead of a line based url.tmi,
21-- -- file so just to be modern I patched it but it's untested. This is a normally a
22-- -- startup-only feature.
23--
24-- do
25--
26--     local mounted = { }
27--
28--     function resolvers.automount(usecache)
29--         local mountpaths = resolvers.cleanpathlist(resolvers.expansion('TEXMFMOUNT'))
30--         if (not mountpaths or #mountpaths == 0) and usecache then
31--             mountpaths = caches.getreadablepaths("mount")
32--         end
33--         if mountpaths and #mountpaths > 0 then
34--             resolvers.starttiming()
35--             for k=1,#mountpaths do
36--                 local root = mountpaths[k]
37--                 local list = table.load("automount.lua")
38--                 if list then
39--                     local archives = list.archives
40--                     if archives then
41--                         for i=1,#archives do
42--                             local archive = archives[i]
43--                             local already = false
44--                             for i=1,#mounted do
45--                                 if archive == mounted[i] then
46--                                     already = true
47--                                     break
48--                                 end
49--                             end
50--                             if not already then
51--                                 mounted[#mounted+1] = archive
52--                                 resolvers.usezipfile(archive)
53--                             end
54--                         end
55--                     end
56--                 end
57--             end
58--             resolvers.stoptiming()
59--         end
60--     end
61--
62-- end
63
64-- status info
65
66statistics.register("used config file", function() return caches.configfiles() end)
67statistics.register("used cache path",  function() return caches.usedpaths() end)
68
69-- experiment (code will move)
70
71function statistics.savefmtstatus(texname,formatbanner,sourcefile,banner) -- texname == formatname
72    local enginebanner = status.banner
73    if formatbanner and enginebanner and sourcefile then
74        local luvname = file.replacesuffix(texname,"luv") -- utilities.lua.suffixes.luv
75        local luvdata = {
76            enginebanner  = enginebanner,
77            formatbanner  = formatbanner,
78            sourcehash    = md5.hex(io.loaddata(findfile(sourcefile)) or "unknown"),
79            sourcefile    = sourcefile,
80            luaversion    = LUAVERSION,
81            luaformat     = LUAFORMAT or 0,
82            formatid      = LUATEXFORMATID,
83            functionality = LUATEXFUNCTIONALITY,
84        }
85        io.savedata(luvname,table.serialize(luvdata,true))
86        lua.registerinitexfinalizer(function()
87            if jit then
88                logs.report("format banner","%s  lua: %s jit",banner,LUAVERSION)
89            else
90                logs.report("format banner","%s  lua: %s, format: %s",banner,LUAVERSION,LUAFORMAT)
91            end
92            logs.newline()
93        end, "show banner")
94    end
95end
96
97-- todo: check this at startup and return (say) 999 as signal that the run
98-- was aborted due to a wrong format in which case mtx-context can trigger
99-- a remake
100
101function statistics.checkfmtstatus(texname)
102    local enginebanner = status.banner
103    if enginebanner and texname then
104        local luvname = file.replacesuffix(texname,"luv") -- utilities.lua.suffixes.luv
105        if lfs.isfile(luvname) then
106            local luv = dofile(luvname)
107            if luv and luv.sourcefile then
108                local sourcehash = md5.hex(io.loaddata(findfile(luv.sourcefile)) or "unknown")
109                local luvbanner = luv.enginebanner or "?"
110                if luvbanner ~= enginebanner then
111                    return format("engine mismatch (luv: %s <> bin: %s)",luvbanner,enginebanner)
112                end
113                local luvhash = luv.sourcehash or "?"
114                if luvhash ~= sourcehash then
115                    return format("source mismatch (luv: %s <> bin: %s)",luvhash,sourcehash)
116                end
117                local luvluaversion = luv.luaversion or 0
118                local engluaversion = LUAVERSION or 0
119                if luvluaversion ~= engluaversion then
120                    return format("lua mismatch (luv: %s <> bin: %s)",luvluaversion,engluaversion)
121                end
122
123                local luvluaformat = luv.luaformat or 0
124                local engluaformat = LUAFORMAT or 0
125                if luvluaformat ~= engluaformat then
126                    return format("lua bytecode format mismatch (luv: %s <> bin: %s)",luvluaformat,engluaformat)
127                end
128
129                local luvfunctionality = luv.functionality or 0
130                local engfunctionality = status.development_id or 0
131                if luvfunctionality ~= engfunctionality then
132                    return format("functionality mismatch (luv: %s <> bin: %s)",luvfunctionality,engfunctionality)
133                end
134                local luvformatid = luv.formatid or 0
135                local engformatid = status.format_id or 0
136                if luvformatid ~= engformatid then
137                    return format("formatid mismatch (luv: %s <> bin: %s)",luvformatid,engformatid)
138                end
139            else
140                return "invalid status file"
141            end
142        else
143            return "missing status file"
144        end
145    end
146    return true
147end
148