From 56d99fef8a1ec03daa1921aab018ebf104c64c99 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 00:33:39 +0100 Subject: [scripts] add early draft of import helper --- scripts/mkimport | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 scripts/mkimport (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport new file mode 100644 index 0000000..f0e7410 --- /dev/null +++ b/scripts/mkimport @@ -0,0 +1,321 @@ +#!/usr/bin/env texlua +------------------------------------------------------------------------------- +-- FILE: mkimport.lua +-- USAGE: ./mkimport.lua +-- DESCRIPTION: check luaotfload imports against Context +-- REQUIREMENTS: luatex, the lualibs package, Context MkIV +-- AUTHOR: Philipp Gesang (Phg), +-- VERSION: 42 +-- CREATED: 2014-12-08 22:36:15+0100 +------------------------------------------------------------------------------- +-- + +------------------------------------------------------------------------------- +--- PURPOSE +--- +--- - Facilitate detecting changes in the fontloader source. +--- - Assist in updating source code and (partially) automate importing. +--- - Account for files in the plain fontloader distribution, alert in case of +--- additions or deletions. +--- +------------------------------------------------------------------------------- + +kpse.set_program_name "luatex" + +local lfs = require "lfs" +local md5 = require "md5" + +require "lualibs" + +local ioloaddata = io.loaddata +local iowrite = io.write +local md5sumhexa = md5.sumhexa +local stringformat = string.format + +------------------------------------------------------------------------------- +-- config +------------------------------------------------------------------------------- + +local context_root = "/home/phg/context/tex/texmf-context" +local our_prefix = "fontloader" +local fontloader_subdir = "src/fontloader" + +local paths = { + context = "tex/context/base", + fontloader = "tex/generic/context/luatex", +} + +local prefixes = { + context = nil, + fontloader = "luatex", +} + +------------------------------------------------------------------------------- +-- helpers +------------------------------------------------------------------------------- + +local die = function (...) + io.stderr:write "[fatal error]: " + io.stderr:write (stringformat (...)) + io.stderr:write "\naborting.\n" + os.exit (1) +end + +local emphasis = function (txt) + return stringformat("\x1b[1m%s\x1b[0m", txt) +end + +local msg = function (...) + iowrite (stringformat (...)) + iowrite "\n" +end + +local good_tag = stringformat("[\x1b[1;30;%dmgood\x1b[0m] · ", 42) +local bad_tag = stringformat("[\x1b[1;30;%dmBAD\x1b[0m] · ", 41) +local alert_tag = stringformat("[\x1b[1;%dmalert\x1b[0m] · " , 36) + +local good = function (...) + local msg = (stringformat (...)) + iowrite (good_tag) + iowrite (msg) + iowrite "\n" +end + +local bad = function (...) + local msg = (stringformat (...)) + iowrite (bad_tag) + iowrite (msg) + iowrite "\n" +end + +local attention = function (...) + local msg = (stringformat (...)) + iowrite (alert_tag) + iowrite (msg) + iowrite "\n" +end + +------------------------------------------------------------------------------- +-- definitions +------------------------------------------------------------------------------- + +--- Accounting of upstream files. There are different categories: +--- +--- · *essential*: Files required at runtime. +--- · *merged*: Files merged into the fontloader package. +--- · *ignored*: Lua files not merged, but part of the format. +--- · *tex*: TeX code, i.e. format and examples. +--- · *lualibs*: Files merged, but also provided by the Lualibs package. + +local imports = { + fontloader = { + { name = "basics-gen" , ours = nil , kind = "essential" }, + { name = "basics-nod" , ours = nil , kind = "merged" }, + { name = "basics" , ours = nil , kind = "tex" }, + { name = "fonts-cbk" , ours = nil , kind = "merged" }, + { name = "fonts-def" , ours = nil , kind = "merged" }, + { name = "fonts-demo-vf-1" , ours = nil , kind = "ignored" }, + { name = "fonts-enc" , ours = nil , kind = "merged" }, + { name = "fonts-ext" , ours = nil , kind = "merged" }, + { name = "fonts-inj" , ours = nil , kind = "merged" }, + { name = "fonts-lua" , ours = nil , kind = "merged" }, + { name = "fonts-merged" , ours = "fontloader" , kind = "essential" }, + { name = "fonts-ota" , ours = nil , kind = "merged" }, + { name = "fonts-otn" , ours = nil , kind = "merged" }, + { name = "fonts" , ours = nil , kind = "merged" }, + { name = "fonts" , ours = nil , kind = "tex" }, + { name = "fonts-syn" , ours = nil , kind = "ignored" }, + { name = "fonts-tfm" , ours = nil , kind = "merged" }, + { name = "languages" , ours = nil , kind = "ignored" }, + { name = "languages" , ours = nil , kind = "tex" }, + { name = "math" , ours = nil , kind = "ignored" }, + { name = "math" , ours = nil , kind = "tex" }, + { name = "mplib" , ours = nil , kind = "ignored" }, + { name = "mplib" , ours = nil , kind = "tex" }, + { name = "plain" , ours = nil , kind = "tex" }, + { name = "preprocessor" , ours = nil , kind = "ignored" }, + { name = "preprocessor" , ours = nil , kind = "tex" }, + { name = "preprocessor-test" , ours = nil , kind = "tex" }, + { name = "swiglib" , ours = nil , kind = "ignored" }, + { name = "swiglib" , ours = nil , kind = "tex" }, + { name = "swiglib-test" , ours = nil , kind = "ignored" }, + { name = "swiglib-test" , ours = nil , kind = "tex" }, + { name = "test" , ours = nil , kind = "tex" }, + }, --[[ [fontloader] ]] + context = { --=> all merged + { name = "data-con" , ours = "data-con" , kind = "merged" }, + { name = "font-afk" , ours = "font-afk" , kind = "merged" }, + { name = "font-afm" , ours = "font-afm" , kind = "merged" }, + { name = "font-cid" , ours = "font-cid" , kind = "merged" }, + { name = "font-con" , ours = "font-con" , kind = "merged" }, + { name = "font-def" , ours = "font-def" , kind = "merged" }, + { name = "font-ini" , ours = "font-ini" , kind = "merged" }, + { name = "font-map" , ours = "font-map" , kind = "merged" }, + { name = "font-otb" , ours = "font-otb" , kind = "merged" }, + { name = "font-otf" , ours = "font-otf" , kind = "merged" }, + { name = "font-oti" , ours = "font-oti" , kind = "merged" }, + { name = "font-otp" , ours = "font-otp" , kind = "merged" }, + { name = "font-tfm" , ours = "font-tfm" , kind = "merged" }, + { name = "l-boolean" , ours = "l-boolean" , kind = "lualibs" }, + { name = "l-file" , ours = "l-file" , kind = "lualibs" }, + { name = "l-function" , ours = "l-function" , kind = "lualibs" }, + { name = "l-io" , ours = "l-io" , kind = "lualibs" }, + { name = "l-lpeg" , ours = "l-lpeg" , kind = "lualibs" }, + { name = "l-lua" , ours = "l-lua" , kind = "lualibs" }, + { name = "l-math" , ours = "l-math" , kind = "lualibs" }, + { name = "l-string" , ours = "l-string" , kind = "lualibs" }, + { name = "l-table" , ours = "l-table" , kind = "lualibs" }, + { name = "util-str" , ours = "util-str" , kind = "lualibs" }, + }, --[[ [context] ]] +} --[[ [imports] ]] + +local hash_file = function (fname) + if not lfs.isfile (fname) then + die ("cannot find %s.", fname) + end + local raw = ioloaddata (fname) + if not raw then + die ("cannot read from %s.", fname) + end + return md5sumhexa (raw) +end + +local derive_category_path = function (cat) + local subpath = paths[cat] or die ("category " .. cat .. " unknown") + local location = file.join (context_root, subpath) + if not lfs.isdir (location) then + die ("invalid base path defined for category " + .. cat .. " at " .. location) + end + return location +end + +local derive_fullname = function (cat, name, kind) + local tmp = prefixes[cat] + tmp = tmp and tmp .. "-" .. name or name + return tmp .. (kind == "tex" and ".tex" or ".lua") +end + +local derive_ourname = function (name) + return our_prefix .. "-" .. name .. ".lua" +end + +local is_readable = function (f) + local fh = io.open (f, "r") + if fh then + fh:close() + return true + end + return false +end + +local summarize_news = function (status) + local ni = #status.import + local nc = #status.create + local ng = #status.good + local nm = #status.missing + + msg "-----------------------------------------------------------------" + msg ("Summary: Inspected %d files.", ni + nc + ng + nm) + msg "-----------------------------------------------------------------" + if ng > 0 then good ("%d are up to date", ng) end + if ni > 0 then attention ("%d changed" , ni) end + if nc > 0 then attention ("%d new" , nc) end + if nm > 0 then bad ("%d missing" , nm) end + msg "-----------------------------------------------------------------" + + if nm == 0 and nc == 0 and ni == 0 then + return 0 + end + + return -1 +end + +local news = function () + local status = { + import = { }, + good = { }, + create = { }, + missing = { }, + } + + for cat, entries in next, imports do + local location = derive_category_path (cat) + local nfiles = #entries + + for i = 1, nfiles do + local def = entries[i] + local name = def.name + local ours = def.ours + local kind = def.kind + local fullname = derive_fullname (cat, name, kind) + local fullpath = file.join (location, fullname) + local ourname = derive_ourname (ours or name) + local ourpath = file.join (fontloader_subdir, ourname) -- relative + local imported = false + + if not is_readable (fullpath) then + bad ("source for file %s not found at %s", + emphasis (ourname), + emphasis (fullpath)) + status.missing[#status.missing + 1] = ourname + else + --- Source file exists and is readable. + if not lfs.isdir (fontloader_subdir) then + die ("path for fontloader tree (" + .. fontloader_subdir .. ") is not a directory") + end + if is_readable (ourpath) then imported = true end + local src_hash = hash_file (fullpath) + local dst_hash = imported and hash_file (ourpath) + local same = src_hash == dst_hash -- same! + + if same then + good ("file %s unchanged", emphasis (ourname)) + status.good[#status.good + 1] = ourname + elseif not dst_hash then + attention ("new file %s requires import from %s", + emphasis (ourname), + emphasis (fullpath)) + status.create[#status.create + 1] = ourname + else --- src and dst exist but differ + attention ("file %s requires import", emphasis (ourname)) + status.import[#status.import + 1] = ourname + end + end + + end + end + + return summarize_news (status) +end + +local job_kind = table.mirrored { + news = news, + import = function () end, + tell = function () end, +} + +------------------------------------------------------------------------------- +-- functionality +------------------------------------------------------------------------------- + +--- job_kind -> bool +local check_job = function (j) + return job_kind[j] +end + +------------------------------------------------------------------------------- +-- entry point +------------------------------------------------------------------------------- + +local main = function () + local job = arg[1] or "news" + local runner = check_job (job) + if not runner then die ("invalid job type “" .. job .. "”.") end + return runner(arg) +end + +os.exit (main ()) + +--- vim:ft=lua:ts=2:et:sw=2 -- cgit v1.2.3 From 7080c45e3d7fc651606f86fea7cbd670b4f0ad4f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 07:53:06 +0100 Subject: [import] implement file lookup --- scripts/mkimport | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index f0e7410..4f6875d 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -108,6 +108,7 @@ end --- · *lualibs*: Files merged, but also provided by the Lualibs package. local imports = { + fontloader = { { name = "basics-gen" , ours = nil , kind = "essential" }, { name = "basics-nod" , ours = nil , kind = "merged" }, @@ -142,6 +143,7 @@ local imports = { { name = "swiglib-test" , ours = nil , kind = "tex" }, { name = "test" , ours = nil , kind = "tex" }, }, --[[ [fontloader] ]] + context = { --=> all merged { name = "data-con" , ours = "data-con" , kind = "merged" }, { name = "font-afk" , ours = "font-afk" , kind = "merged" }, @@ -196,8 +198,9 @@ local derive_fullname = function (cat, name, kind) return tmp .. (kind == "tex" and ".tex" or ".lua") end -local derive_ourname = function (name) - return our_prefix .. "-" .. name .. ".lua" +local derive_ourname = function (name, kind) + local suffix = kind == "tex" and ".tex" or ".lua" + return our_prefix .. "-" .. name .. suffix end local is_readable = function (f) @@ -288,11 +291,44 @@ local news = function () end return summarize_news (status) -end +end --[[ [local news = function ()] ]] + +local get_file_definition = function (name, ourname, kind) + kind = kind or "lua" + for cat, defs in next, imports do + local fullname = derive_fullname (cat, name, kind) + local ndefs = #defs + for i = 1, ndefs do + local def = defs[i] + local dname = def.name + local dours = def.ours or def.name + local dkind = def.kind + + --- test properties + if derive_ourname (dours, dkind) == ourname then return def end + if derive_fullname (cat, dname, dkind) == fullname then return def end + if dours == ourname then return def end + if dname == fullname then return def end + end + end + --- search unsuccessful +end --[[ [local get_file_definition = function (name, ourname, kind)] ]] + +local import_file = function (name, kind) + local ourname = derive_ourname (name) + local def = get_file_definition (name, ourname, kind) + if not def then die ("unable to find a definition matching " .. name) end +end --[[ [local import_file = function (name, kind)] ]] + +local import = function (arg) + if #arg > 1 then + return import_file (arg[2]) + end +end --[[ [local import = function (arg)] ]] local job_kind = table.mirrored { news = news, - import = function () end, + import = import, tell = function () end, } -- cgit v1.2.3 From 7f02fde8764b58fadf93ea9d778ad05a42d28abb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 22:00:50 +0100 Subject: [import] add single file importing routine --- scripts/mkimport | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 4f6875d..2ac1549 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -55,7 +55,7 @@ local prefixes = { ------------------------------------------------------------------------------- local die = function (...) - io.stderr:write "[fatal error]: " + io.stderr:write "[\x1b[1;30;41mfatal error\x1b[0m]: " io.stderr:write (stringformat (...)) io.stderr:write "\naborting.\n" os.exit (1) @@ -305,19 +305,32 @@ local get_file_definition = function (name, ourname, kind) local dkind = def.kind --- test properties - if derive_ourname (dours, dkind) == ourname then return def end - if derive_fullname (cat, dname, dkind) == fullname then return def end - if dours == ourname then return def end - if dname == fullname then return def end + if derive_ourname (dours, dkind) == ourname then return def, cat end + if derive_fullname (cat, dname, dkind) == fullname then return def, cat end + if dours == ourname then return def, cat end + if dname == fullname then return def, cat end end end --- search unsuccessful end --[[ [local get_file_definition = function (name, ourname, kind)] ]] -local import_file = function (name, kind) - local ourname = derive_ourname (name) - local def = get_file_definition (name, ourname, kind) +local import_file = function (name, kind, def, cat) + local expected_ourname = derive_ourname (name) + if not def or not cat then + def, cat = get_file_definition (name, expected_ourname, kind) + end + if not def then die ("unable to find a definition matching " .. name) end + if not cat then die ("missing category for file " .. name .. " -- WTF‽") end + + local dname = def.name + local dours = def.ours + local dkind = def.kind + local srcdir = derive_category_path (cat) + local src = file.join (srcdir, derive_fullname (cat, dname, kind)) + local dst = file.join (fontloader_subdir, expected_ourname) + file.copy (src, dst) + return (hash_file (src) == hash_file (dst)) and 0 or 1 end --[[ [local import_file = function (name, kind)] ]] local import = function (arg) @@ -338,7 +351,7 @@ local job_kind = table.mirrored { --- job_kind -> bool local check_job = function (j) - return job_kind[j] + return job_kind[j] or die ("invalid job type “" .. job .. "”.") end ------------------------------------------------------------------------------- @@ -348,7 +361,6 @@ end local main = function () local job = arg[1] or "news" local runner = check_job (job) - if not runner then die ("invalid job type “" .. job .. "”.") end return runner(arg) end -- cgit v1.2.3 From 7d03847cddef515e6cbbe8afc3e9b663371e57cd Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 22:34:54 +0100 Subject: [import] implement automated batch import Already being used for the next update commit. --- scripts/mkimport | 91 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 11 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 2ac1549..8e22690 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -70,9 +70,10 @@ local msg = function (...) iowrite "\n" end -local good_tag = stringformat("[\x1b[1;30;%dmgood\x1b[0m] · ", 42) -local bad_tag = stringformat("[\x1b[1;30;%dmBAD\x1b[0m] · ", 41) -local alert_tag = stringformat("[\x1b[1;%dmalert\x1b[0m] · " , 36) +local good_tag = stringformat("[\x1b[1;30;%dmgood\x1b[0m] · ", 42) +local bad_tag = stringformat("[\x1b[1;30;%dmBAD\x1b[0m] · ", 41) +local alert_tag = stringformat("[\x1b[1;%dmalert\x1b[0m] · " , 36) +local status_tag = stringformat("[\x1b[0;%dmstatus\x1b[0m] · " , 36) local good = function (...) local msg = (stringformat (...)) @@ -95,6 +96,13 @@ local attention = function (...) iowrite "\n" end +local status = function (...) + local msg = (stringformat (...)) + iowrite (status_tag) + iowrite (msg) + iowrite "\n" +end + ------------------------------------------------------------------------------- -- definitions ------------------------------------------------------------------------------- @@ -314,6 +322,34 @@ local get_file_definition = function (name, ourname, kind) --- search unsuccessful end --[[ [local get_file_definition = function (name, ourname, kind)] ]] +local import_imported = 0 +local import_skipped = 1 +local import_failed = 2 +local import_created = 3 + +local import_status = { + [import_imported] = "imported", + [import_skipped ] = "skipped", + [import_failed ] = "failed", + [import_created ] = "created", +} + +local summarize_status = function (counters) + local imported = counters[import_imported] or 0 + local skipped = counters[import_skipped ] or 0 + local created = counters[import_created ] or 0 + local failed = counters[import_failed ] or 0 + local sum = imported + skipped + created + failed + if sum < 1 then die ("garbage total of imported files: %s", sum) end + status ("-----------------------------------------------------------------") + status (" RESULT: %d files processed", sum) + status ("-----------------------------------------------------------------") + if created > 0 then status ("created: %d (%d %%)", created , created * 100 / sum) end + if imported > 0 then status ("imported: %d (%d %%)", imported, imported * 100 / sum) end + if skipped > 0 then status ("skipped: %d (%d %%)", skipped , skipped * 100 / sum) end + status ("-----------------------------------------------------------------") +end + local import_file = function (name, kind, def, cat) local expected_ourname = derive_ourname (name) if not def or not cat then @@ -323,20 +359,53 @@ local import_file = function (name, kind, def, cat) if not def then die ("unable to find a definition matching " .. name) end if not cat then die ("missing category for file " .. name .. " -- WTF‽") end - local dname = def.name - local dours = def.ours - local dkind = def.kind - local srcdir = derive_category_path (cat) - local src = file.join (srcdir, derive_fullname (cat, dname, kind)) - local dst = file.join (fontloader_subdir, expected_ourname) + local dname = def.name + local dours = def.ours + local dkind = def.kind + local srcdir = derive_category_path (cat) + local fullname = derive_fullname (cat, dname, kind) + local ourname = derive_ourname (dname, kind) + local src = file.join (srcdir, fullname) + local dst = file.join (fontloader_subdir, ourname) + local new = not lfs.isfile (dst) + if not new and hash_file (src) == hash_file (dst) then + status ("file %s is unchanged, skipping", fullname) + return import_skipped + end + status ("importing file %s", fullname) file.copy (src, dst) - return (hash_file (src) == hash_file (dst)) and 0 or 1 + if hash_file (src) == hash_file (dst) then + if new then return import_created end + return import_imported end + return import_failed end --[[ [local import_file = function (name, kind)] ]] local import = function (arg) if #arg > 1 then - return import_file (arg[2]) + local name = arg[2] or die ("invalid filename " .. tostring (arg[2])) + local stat = import_file (name) + if stat == import_failed then + die ("failed to import file " .. name) + end + status ("import status for file %s: %s", name, import_status[stat]) + end + --- Multiple files + local statcount = { } -- import status codes -> size_t + for cat, defs in next, imports do + local ndefs = #defs + for i = 1, ndefs do + local def = defs[i] + local stat = import_file (def.name, def.kind, def, cat) + if stat == import_failed then + die (stringformat ("import failed at file %d of %d (%s)", + i, ndefs, def.name)) + end + statcount[stat] = statcount[stat] or 0 + statcount[stat] = statcount[stat] + 1 + end end + summarize_status (statcount) + return 0 end --[[ [local import = function (arg)] ]] local job_kind = table.mirrored { -- cgit v1.2.3 From 9f614b56bf48ebdd59e81e9e3e874b8f25bb174f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 22:41:09 +0100 Subject: [import] prefer enumerations instead of strings --- scripts/mkimport | 120 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 57 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 8e22690..1ee695b 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -115,67 +115,73 @@ end --- · *tex*: TeX code, i.e. format and examples. --- · *lualibs*: Files merged, but also provided by the Lualibs package. +local kind_essential = 0 +local kind_merged = 1 +local kind_tex = 2 +local kind_ignored = 3 +local kind_lualibs = 4 + local imports = { fontloader = { - { name = "basics-gen" , ours = nil , kind = "essential" }, - { name = "basics-nod" , ours = nil , kind = "merged" }, - { name = "basics" , ours = nil , kind = "tex" }, - { name = "fonts-cbk" , ours = nil , kind = "merged" }, - { name = "fonts-def" , ours = nil , kind = "merged" }, - { name = "fonts-demo-vf-1" , ours = nil , kind = "ignored" }, - { name = "fonts-enc" , ours = nil , kind = "merged" }, - { name = "fonts-ext" , ours = nil , kind = "merged" }, - { name = "fonts-inj" , ours = nil , kind = "merged" }, - { name = "fonts-lua" , ours = nil , kind = "merged" }, - { name = "fonts-merged" , ours = "fontloader" , kind = "essential" }, - { name = "fonts-ota" , ours = nil , kind = "merged" }, - { name = "fonts-otn" , ours = nil , kind = "merged" }, - { name = "fonts" , ours = nil , kind = "merged" }, - { name = "fonts" , ours = nil , kind = "tex" }, - { name = "fonts-syn" , ours = nil , kind = "ignored" }, - { name = "fonts-tfm" , ours = nil , kind = "merged" }, - { name = "languages" , ours = nil , kind = "ignored" }, - { name = "languages" , ours = nil , kind = "tex" }, - { name = "math" , ours = nil , kind = "ignored" }, - { name = "math" , ours = nil , kind = "tex" }, - { name = "mplib" , ours = nil , kind = "ignored" }, - { name = "mplib" , ours = nil , kind = "tex" }, - { name = "plain" , ours = nil , kind = "tex" }, - { name = "preprocessor" , ours = nil , kind = "ignored" }, - { name = "preprocessor" , ours = nil , kind = "tex" }, - { name = "preprocessor-test" , ours = nil , kind = "tex" }, - { name = "swiglib" , ours = nil , kind = "ignored" }, - { name = "swiglib" , ours = nil , kind = "tex" }, - { name = "swiglib-test" , ours = nil , kind = "ignored" }, - { name = "swiglib-test" , ours = nil , kind = "tex" }, - { name = "test" , ours = nil , kind = "tex" }, + { name = "basics-gen" , ours = nil , kind = kind_essential }, + { name = "basics-nod" , ours = nil , kind = kind_merged }, + { name = "basics" , ours = nil , kind = kind_tex }, + { name = "fonts-cbk" , ours = nil , kind = kind_merged }, + { name = "fonts-def" , ours = nil , kind = kind_merged }, + { name = "fonts-demo-vf-1" , ours = nil , kind = kind_ignored }, + { name = "fonts-enc" , ours = nil , kind = kind_merged }, + { name = "fonts-ext" , ours = nil , kind = kind_merged }, + { name = "fonts-inj" , ours = nil , kind = kind_merged }, + { name = "fonts-lua" , ours = nil , kind = kind_merged }, + { name = "fonts-merged" , ours = "fontloader" , kind = kind_essential }, + { name = "fonts-ota" , ours = nil , kind = kind_merged }, + { name = "fonts-otn" , ours = nil , kind = kind_merged }, + { name = "fonts" , ours = nil , kind = kind_merged }, + { name = "fonts" , ours = nil , kind = kind_tex }, + { name = "fonts-syn" , ours = nil , kind = kind_ignored }, + { name = "fonts-tfm" , ours = nil , kind = kind_merged }, + { name = "languages" , ours = nil , kind = kind_ignored }, + { name = "languages" , ours = nil , kind = kind_tex }, + { name = "math" , ours = nil , kind = kind_ignored }, + { name = "math" , ours = nil , kind = kind_tex }, + { name = "mplib" , ours = nil , kind = kind_ignored }, + { name = "mplib" , ours = nil , kind = kind_tex }, + { name = "plain" , ours = nil , kind = kind_tex }, + { name = "preprocessor" , ours = nil , kind = kind_ignored }, + { name = "preprocessor" , ours = nil , kind = kind_tex }, + { name = "preprocessor-test" , ours = nil , kind = kind_tex }, + { name = "swiglib" , ours = nil , kind = kind_ignored }, + { name = "swiglib" , ours = nil , kind = kind_tex }, + { name = "swiglib-test" , ours = nil , kind = kind_ignored }, + { name = "swiglib-test" , ours = nil , kind = kind_tex }, + { name = "test" , ours = nil , kind = kind_tex }, }, --[[ [fontloader] ]] context = { --=> all merged - { name = "data-con" , ours = "data-con" , kind = "merged" }, - { name = "font-afk" , ours = "font-afk" , kind = "merged" }, - { name = "font-afm" , ours = "font-afm" , kind = "merged" }, - { name = "font-cid" , ours = "font-cid" , kind = "merged" }, - { name = "font-con" , ours = "font-con" , kind = "merged" }, - { name = "font-def" , ours = "font-def" , kind = "merged" }, - { name = "font-ini" , ours = "font-ini" , kind = "merged" }, - { name = "font-map" , ours = "font-map" , kind = "merged" }, - { name = "font-otb" , ours = "font-otb" , kind = "merged" }, - { name = "font-otf" , ours = "font-otf" , kind = "merged" }, - { name = "font-oti" , ours = "font-oti" , kind = "merged" }, - { name = "font-otp" , ours = "font-otp" , kind = "merged" }, - { name = "font-tfm" , ours = "font-tfm" , kind = "merged" }, - { name = "l-boolean" , ours = "l-boolean" , kind = "lualibs" }, - { name = "l-file" , ours = "l-file" , kind = "lualibs" }, - { name = "l-function" , ours = "l-function" , kind = "lualibs" }, - { name = "l-io" , ours = "l-io" , kind = "lualibs" }, - { name = "l-lpeg" , ours = "l-lpeg" , kind = "lualibs" }, - { name = "l-lua" , ours = "l-lua" , kind = "lualibs" }, - { name = "l-math" , ours = "l-math" , kind = "lualibs" }, - { name = "l-string" , ours = "l-string" , kind = "lualibs" }, - { name = "l-table" , ours = "l-table" , kind = "lualibs" }, - { name = "util-str" , ours = "util-str" , kind = "lualibs" }, + { name = "data-con" , ours = "data-con" , kind = kind_merged }, + { name = "font-afk" , ours = "font-afk" , kind = kind_merged }, + { name = "font-afm" , ours = "font-afm" , kind = kind_merged }, + { name = "font-cid" , ours = "font-cid" , kind = kind_merged }, + { name = "font-con" , ours = "font-con" , kind = kind_merged }, + { name = "font-def" , ours = "font-def" , kind = kind_merged }, + { name = "font-ini" , ours = "font-ini" , kind = kind_merged }, + { name = "font-map" , ours = "font-map" , kind = kind_merged }, + { name = "font-otb" , ours = "font-otb" , kind = kind_merged }, + { name = "font-otf" , ours = "font-otf" , kind = kind_merged }, + { name = "font-oti" , ours = "font-oti" , kind = kind_merged }, + { name = "font-otp" , ours = "font-otp" , kind = kind_merged }, + { name = "font-tfm" , ours = "font-tfm" , kind = kind_merged }, + { name = "l-boolean" , ours = "l-boolean" , kind = kind_lualibs }, + { name = "l-file" , ours = "l-file" , kind = kind_lualibs }, + { name = "l-function" , ours = "l-function" , kind = kind_lualibs }, + { name = "l-io" , ours = "l-io" , kind = kind_lualibs }, + { name = "l-lpeg" , ours = "l-lpeg" , kind = kind_lualibs }, + { name = "l-lua" , ours = "l-lua" , kind = kind_lualibs }, + { name = "l-math" , ours = "l-math" , kind = kind_lualibs }, + { name = "l-string" , ours = "l-string" , kind = kind_lualibs }, + { name = "l-table" , ours = "l-table" , kind = kind_lualibs }, + { name = "util-str" , ours = "util-str" , kind = kind_lualibs }, }, --[[ [context] ]] } --[[ [imports] ]] @@ -203,11 +209,11 @@ end local derive_fullname = function (cat, name, kind) local tmp = prefixes[cat] tmp = tmp and tmp .. "-" .. name or name - return tmp .. (kind == "tex" and ".tex" or ".lua") + return tmp .. (kind == kind_tex and ".tex" or ".lua") end local derive_ourname = function (name, kind) - local suffix = kind == "tex" and ".tex" or ".lua" + local suffix = kind == kind_tex and ".tex" or ".lua" return our_prefix .. "-" .. name .. suffix end -- cgit v1.2.3 From c6d79f40c1fd9ba9401b0f4edc688f29144048df Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 22:54:52 +0100 Subject: [import] classify essential and non-essential files into appropriate subdirectories Simplifies writing make rules ;) --- scripts/mkimport | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 1ee695b..f211c2f 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -214,7 +214,8 @@ end local derive_ourname = function (name, kind) local suffix = kind == kind_tex and ".tex" or ".lua" - return our_prefix .. "-" .. name .. suffix + local subdir = kind == kind_essential and "runtime" or "misc" + return subdir, our_prefix .. "-" .. name .. suffix end local is_readable = function (f) @@ -267,8 +268,8 @@ local news = function () local kind = def.kind local fullname = derive_fullname (cat, name, kind) local fullpath = file.join (location, fullname) - local ourname = derive_ourname (ours or name) - local ourpath = file.join (fontloader_subdir, ourname) -- relative + local subdir, ourname = derive_ourname (ours or name) + local ourpath = file.join (fontloader_subdir, subdir, ourname) -- relative local imported = false if not is_readable (fullpath) then @@ -319,7 +320,8 @@ local get_file_definition = function (name, ourname, kind) local dkind = def.kind --- test properties - if derive_ourname (dours, dkind) == ourname then return def, cat end + local subdir, derived = derive_ourname (dours, dkind) + if derived == ourname then return def, cat end if derive_fullname (cat, dname, dkind) == fullname then return def, cat end if dours == ourname then return def, cat end if dname == fullname then return def, cat end @@ -370,14 +372,19 @@ local import_file = function (name, kind, def, cat) local dkind = def.kind local srcdir = derive_category_path (cat) local fullname = derive_fullname (cat, dname, kind) - local ourname = derive_ourname (dname, kind) + local subdir, ourname = derive_ourname (dname, kind) + local ourpath = file.join (fontloader_subdir, subdir) local src = file.join (srcdir, fullname) - local dst = file.join (fontloader_subdir, ourname) + local dst = file.join (ourpath, ourname) local new = not lfs.isfile (dst) if not new and hash_file (src) == hash_file (dst) then status ("file %s is unchanged, skipping", fullname) return import_skipped end + if not (lfs.isdir (ourpath) or not lfs.mkdirs (ourpath)) then + die ("failed to create directory %s for file %s", + ourpath, ourname) + end status ("importing file %s", fullname) file.copy (src, dst) if hash_file (src) == hash_file (dst) then -- cgit v1.2.3 From 0c443eae5ad75d999e0c41d42d5ab3530024a611 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 22:57:46 +0100 Subject: [import] fix error message --- scripts/mkimport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index f211c2f..8622d5e 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -433,7 +433,7 @@ local job_kind = table.mirrored { --- job_kind -> bool local check_job = function (j) - return job_kind[j] or die ("invalid job type “" .. job .. "”.") + return job_kind[j] or die ("invalid job type “%s”.", j) end ------------------------------------------------------------------------------- -- cgit v1.2.3 From ff9c47695c00c96ade844f4b2644fca5e1f96be1 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 23:03:24 +0100 Subject: [import] fix destination path building in import procedure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit D’oh! --- scripts/mkimport | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 8622d5e..fe9f4b4 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -268,7 +268,7 @@ local news = function () local kind = def.kind local fullname = derive_fullname (cat, name, kind) local fullpath = file.join (location, fullname) - local subdir, ourname = derive_ourname (ours or name) + local subdir, ourname = derive_ourname (ours or name, kind) local ourpath = file.join (fontloader_subdir, subdir, ourname) -- relative local imported = false @@ -368,11 +368,11 @@ local import_file = function (name, kind, def, cat) if not cat then die ("missing category for file " .. name .. " -- WTF‽") end local dname = def.name - local dours = def.ours + local dours = def.ours or dname local dkind = def.kind local srcdir = derive_category_path (cat) local fullname = derive_fullname (cat, dname, kind) - local subdir, ourname = derive_ourname (dname, kind) + local subdir, ourname = derive_ourname (dours, kind) local ourpath = file.join (fontloader_subdir, subdir) local src = file.join (srcdir, fullname) local dst = file.join (ourpath, ourname) -- cgit v1.2.3 From c8808efcf8bd69b6038627f92298818d9028c088 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 9 Dec 2014 23:07:13 +0100 Subject: [import] unify appearance --- scripts/mkimport | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index fe9f4b4..1b4dc39 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -70,6 +70,12 @@ local msg = function (...) iowrite "\n" end +local separator_string = string.rep ("-", 79) +local separator = function () + iowrite (separator_string) + iowrite "\n" +end + local good_tag = stringformat("[\x1b[1;30;%dmgood\x1b[0m] · ", 42) local bad_tag = stringformat("[\x1b[1;30;%dmBAD\x1b[0m] · ", 41) local alert_tag = stringformat("[\x1b[1;%dmalert\x1b[0m] · " , 36) @@ -233,14 +239,14 @@ local summarize_news = function (status) local ng = #status.good local nm = #status.missing - msg "-----------------------------------------------------------------" + separator () msg ("Summary: Inspected %d files.", ni + nc + ng + nm) - msg "-----------------------------------------------------------------" + separator () if ng > 0 then good ("%d are up to date", ng) end if ni > 0 then attention ("%d changed" , ni) end if nc > 0 then attention ("%d new" , nc) end if nm > 0 then bad ("%d missing" , nm) end - msg "-----------------------------------------------------------------" + separator () if nm == 0 and nc == 0 and ni == 0 then return 0 @@ -349,13 +355,13 @@ local summarize_status = function (counters) local failed = counters[import_failed ] or 0 local sum = imported + skipped + created + failed if sum < 1 then die ("garbage total of imported files: %s", sum) end - status ("-----------------------------------------------------------------") + separator () status (" RESULT: %d files processed", sum) - status ("-----------------------------------------------------------------") + separator () if created > 0 then status ("created: %d (%d %%)", created , created * 100 / sum) end if imported > 0 then status ("imported: %d (%d %%)", imported, imported * 100 / sum) end if skipped > 0 then status ("skipped: %d (%d %%)", skipped , skipped * 100 / sum) end - status ("-----------------------------------------------------------------") + separator () end local import_file = function (name, kind, def, cat) -- cgit v1.2.3 From 9a778b19fbfd69dc7bee8b88b8640ebf2451047e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Dec 2014 08:07:41 +0100 Subject: [import] add preliminary file inspection --- scripts/mkimport | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 1b4dc39..a748459 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -45,6 +45,17 @@ local paths = { fontloader = "tex/generic/context/luatex", } +local subdirs = { + "runtime", + "misc" +} + +local searchdirs = { + --- order is important! + fontloader_subdir, + context_root +} + local prefixes = { context = nil, fontloader = "luatex", @@ -427,10 +438,42 @@ local import = function (arg) return 0 end --[[ [local import = function (arg)] ]] +local tell = function (arg) + local target = arg[2] + if not target then die "no filename given" end + + local look_for + --- pick a file + if lfs.isfile (target) then --- absolute path given + look_for = target + goto found + else + --- search in local tree + for i = 1, #searchdirs do + local root = searchdirs[i] + for j = 1, #subdirs do + local dir = file.join (searchdirs[i], subdirs[j]) + local file = file.join (dir, target) + if lfs.isfile (file) then + look_for = file + goto found + end + end + end + end + + if not look_for then + die ("file %s not found in any of the search locations", target) + end + +::found:: + status ("found file %s at %s", target, look_for) +end + local job_kind = table.mirrored { news = news, import = import, - tell = function () end, + tell = tell, } ------------------------------------------------------------------------------- -- cgit v1.2.3 From 27a805594949ffb973d0055380cb354b043e1d0f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 10 Dec 2014 08:10:12 +0100 Subject: [import] add stub for usage message --- scripts/mkimport | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index a748459..651ff04 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -438,7 +438,7 @@ local import = function (arg) return 0 end --[[ [local import = function (arg)] ]] -local tell = function (arg) +local search = function (arg) local target = arg[2] if not target then die "no filename given" end @@ -462,18 +462,30 @@ local tell = function (arg) end end - if not look_for then - die ("file %s not found in any of the search locations", target) - end +::fail:: + if not look_for then return end ::found:: status ("found file %s at %s", target, look_for) + return look_for +end + +local tell = function (target) + local location = search (target) + if not location then + die ("file %s not found in any of the search locations", target) + end +end + +local help = function () + die "not implemented :/" end local job_kind = table.mirrored { news = news, import = import, tell = tell, + help = help, } ------------------------------------------------------------------------------- @@ -490,7 +502,7 @@ end ------------------------------------------------------------------------------- local main = function () - local job = arg[1] or "news" + local job = arg[1] or "help" local runner = check_job (job) return runner(arg) end -- cgit v1.2.3 From 4d9430560ea1c8d02b5737a6d0bc7115d1f4b72e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Dec 2014 22:06:29 +0100 Subject: [import] add usage message --- scripts/mkimport | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 651ff04..7d6f984 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -478,7 +478,14 @@ local tell = function (target) end local help = function () - die "not implemented :/" + iowrite "usage: mkinfo []\n" + iowrite "\n" + iowrite "Where is one of\n" + iowrite " help Print this help message\n" + iowrite " tell Display information about a file’s integration\n" + iowrite " news Check Context for updated files\n" + iowrite " import Update with files from Context\n" + iowrite "\n" end local job_kind = table.mirrored { -- cgit v1.2.3 From 3bacb6622d08679935e2746b2b8480d258bc0032 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Dec 2014 22:28:55 +0100 Subject: [import] extend tell search --- scripts/mkimport | 80 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 14 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 7d6f984..ac8e8fa 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -223,14 +223,19 @@ local derive_category_path = function (cat) return location end +local derive_suffix = function (kind) + if kind == kind_tex then return ".tex" end + return ".lua" +end + local derive_fullname = function (cat, name, kind) local tmp = prefixes[cat] tmp = tmp and tmp .. "-" .. name or name - return tmp .. (kind == kind_tex and ".tex" or ".lua") + return tmp .. derive_suffix (kind) end local derive_ourname = function (name, kind) - local suffix = kind == kind_tex and ".tex" or ".lua" + local suffix = derive_suffix (kind) local subdir = kind == kind_essential and "runtime" or "misc" return subdir, our_prefix .. "-" .. name .. suffix end @@ -438,6 +443,56 @@ local import = function (arg) return 0 end --[[ [local import = function (arg)] ]] +local search_paths = function (target) + for i = 1, #searchdirs do + local root = searchdirs[i] + for j = 1, #subdirs do + local dir = file.join (searchdirs[i], subdirs[j]) + local file = file.join (dir, target) + if lfs.isfile (file) then return file end + end + end + return false +end + +local search_defs = function (target) + for cat, defs in next, imports do + local ndefs = #defs + for i = 1, ndefs do + local def = defs[i] + + local dname = def.name + if target == dname then + local found = search_paths (target .. derive_suffix (def.kind)) + if found then return found end + end + + local dfull = dname .. derive_suffix (def.kind) + if target == dfull then + local found = search_paths (dfull) + if found then return found end + end + + local dours = def.ours + if dours then + + local _, ourname = derive_ourname (dours, kind) + if target == dours then + local found = search_paths (ourname) + if found then return found end + end + + if target == ourname then + local found = search_paths (ourname) + if found then return found end + end + end + + end + end + return false +end + local search = function (arg) local target = arg[2] if not target then die "no filename given" end @@ -448,18 +503,15 @@ local search = function (arg) look_for = target goto found else - --- search in local tree - for i = 1, #searchdirs do - local root = searchdirs[i] - for j = 1, #subdirs do - local dir = file.join (searchdirs[i], subdirs[j]) - local file = file.join (dir, target) - if lfs.isfile (file) then - look_for = file - goto found - end - end - end + + --- search as file name in local tree + look_for = search_paths (target) + if look_for then goto found end + + --- seach the definitions + look_for = search_defs (target) + if look_for then goto found end + end ::fail:: -- cgit v1.2.3 From 57aa7e07532a85c34b7588350122830579f8df51 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Dec 2014 23:00:39 +0100 Subject: [import] implement tell output --- scripts/mkimport | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index ac8e8fa..43d76fd 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -138,6 +138,14 @@ local kind_tex = 2 local kind_ignored = 3 local kind_lualibs = 4 +local kind_name = { + [0] = "essential", + [1] = "merged" , + [2] = "tex" , + [3] = "ignored" , + [4] = "lualibs" , +} + local imports = { fontloader = { @@ -228,6 +236,18 @@ local derive_suffix = function (kind) return ".lua" end +local pfxlen +local strip_prefix = function (fname) + if not pfxlen then pfxlen = #our_prefix end + if #fname <= pfxlen + 2 then + --- too short to accomodate prefix + basename + return + end + if string.sub (fname, 1, pfxlen) == our_prefix then + return string.sub (fname, pfxlen + 2) + end +end + local derive_fullname = function (cat, name, kind) local tmp = prefixes[cat] tmp = tmp and tmp .. "-" .. name or name @@ -240,6 +260,13 @@ local derive_ourname = function (name, kind) return subdir, our_prefix .. "-" .. name .. suffix end +local format_file_definition = function (def) + return stringformat ("name = \"%s\", kind = \"%s\"", + def.name, + kind_name[def.kind] or def.kind) + .. (def.ours and (", ours = \"" .. def.ours .. "\"") or "") +end + local is_readable = function (f) local fh = io.open (f, "r") if fh then @@ -493,10 +520,7 @@ local search_defs = function (target) return false end -local search = function (arg) - local target = arg[2] - if not target then die "no filename given" end - +local search = function (target) local look_for --- pick a file if lfs.isfile (target) then --- absolute path given @@ -518,15 +542,63 @@ local search = function (arg) if not look_for then return end ::found:: - status ("found file %s at %s", target, look_for) return look_for end -local tell = function (target) +local find_matching_def = function (location) + local basename = file.basename (location) + if not basename then die ("corrupt path %s", location) end + local barename = file.removesuffix (basename) + local pfxless = strip_prefix (barename) + local kind = file.suffix (pfxless) or "lua" + for cat, defs in next, imports do + for _, def in next, defs do + local dname = def.name + local dours = def.ours + if dname == pfxless + or dname == barename + -- dname == basename -- can’t happen for lack of suffix + or dours == pfxless + or dours == barename + then + return cat, def + end + end + end + return false +end + +local describe = function (target, location) + --- Map files to import definitions + separator () + status ("found file %s at %s", target, location) + local cat, def = find_matching_def (location) + if not cat or not def then + die ("file %s not found in registry", location) + end + + local dname = def.name + local dkind = def.kind + local subdir, ourname = derive_ourname (dname, dkind) + separator () + status ("category %s", cat) + status ("kind %s", kind_name[dkind]) + status ("in Context %s", derive_fullname (cat, def.name, def.kind)) + status ("in Luaotfload %s", ourname) + separator () + return 0 +end + +local tell = function (arg) + local target = arg[2] + if not target then die "no filename given" end + local location = search (target) if not location then die ("file %s not found in any of the search locations", target) end + + return describe (target, location) end local help = function () -- cgit v1.2.3 From 16a45555ad3677155ea097a8153cf7e266879e13 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Dec 2014 23:17:12 +0100 Subject: [import] include Luatex-Fonts path in tell lookup --- scripts/mkimport | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index 43d76fd..c25459b 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -40,7 +40,7 @@ local context_root = "/home/phg/context/tex/texmf-context" local our_prefix = "fontloader" local fontloader_subdir = "src/fontloader" -local paths = { +local origin_paths = { context = "tex/context/base", fontloader = "tex/generic/context/luatex", } @@ -222,7 +222,7 @@ local hash_file = function (fname) end local derive_category_path = function (cat) - local subpath = paths[cat] or die ("category " .. cat .. " unknown") + local subpath = origin_paths[cat] or die ("category " .. cat .. " unknown") local location = file.join (context_root, subpath) if not lfs.isdir (location) then die ("invalid base path defined for category " @@ -470,15 +470,29 @@ local import = function (arg) return 0 end --[[ [local import = function (arg)] ]] +local find_in_path = function (root, subdir, target) + local file = file.join (root, subdir, target) + if lfs.isfile (file) then + return file + end +end + local search_paths = function (target) for i = 1, #searchdirs do local root = searchdirs[i] + for j = 1, #subdirs do - local dir = file.join (searchdirs[i], subdirs[j]) - local file = file.join (dir, target) - if lfs.isfile (file) then return file end + local found = find_in_path (root, subdirs[j], target) + if found then return found end end + end + + local found = find_in_path (context_root, origin_paths.context, target) + if found then return found end + + local found = find_in_path (context_root, origin_paths.fontloader, target) + if found then return found end return false end @@ -494,8 +508,9 @@ local search_defs = function (target) if found then return found end end - local dfull = dname .. derive_suffix (def.kind) - if target == dfull then + local dkind = def.kind + local dfull = derive_fullname (cat, dname, dkind) + if derive_fullname (cat, target, dkind) == dfull then local found = search_paths (dfull) if found then return found end end @@ -503,7 +518,7 @@ local search_defs = function (target) local dours = def.ours if dours then - local _, ourname = derive_ourname (dours, kind) + local _, ourname = derive_ourname (dours, dkind) if target == dours then local found = search_paths (ourname) if found then return found end -- cgit v1.2.3 From f5180e94891872433c3c1ef068d5557c5969c993 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Dec 2014 23:25:49 +0100 Subject: [import] consider prefix variants when searching --- scripts/mkimport | 76 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 30 deletions(-) (limited to 'scripts/mkimport') diff --git a/scripts/mkimport b/scripts/mkimport index c25459b..132d026 100644 --- a/scripts/mkimport +++ b/scripts/mkimport @@ -36,9 +36,10 @@ local stringformat = string.format -- config ------------------------------------------------------------------------------- -local context_root = "/home/phg/context/tex/texmf-context" -local our_prefix = "fontloader" -local fontloader_subdir = "src/fontloader" +local context_root = "/home/phg/context/tex/texmf-context" +local our_prefix = "fontloader" +local luatex_fonts_prefix = "luatex" +local fontloader_subdir = "src/fontloader" local origin_paths = { context = "tex/context/base", @@ -236,15 +237,17 @@ local derive_suffix = function (kind) return ".lua" end -local pfxlen -local strip_prefix = function (fname) - if not pfxlen then pfxlen = #our_prefix end - if #fname <= pfxlen + 2 then +local pfxlen = { } +local strip_prefix = function (fname, prefix) + prefix = prefix or our_prefix + if not pfxlen[prefix] then pfxlen[prefix] = #prefix end + local len = pfxlen[prefix] + if #fname <= len + 2 then --- too short to accomodate prefix + basename return end - if string.sub (fname, 1, pfxlen) == our_prefix then - return string.sub (fname, pfxlen + 2) + if string.sub (fname, 1, len) == prefix then + return string.sub (fname, len + 2) end end @@ -497,39 +500,52 @@ local search_paths = function (target) end local search_defs = function (target) + local variants = { target, --[[ unstripped ]] } + local tmp + tmp = strip_prefix (target) + if tmp then variants[#variants + 1] = tmp end + tmp = strip_prefix (target, luatex_fonts_prefix) + if tmp then variants[#variants + 1] = tmp end + + local nvariants = #variants + for cat, defs in next, imports do local ndefs = #defs for i = 1, ndefs do local def = defs[i] - local dname = def.name - if target == dname then - local found = search_paths (target .. derive_suffix (def.kind)) - if found then return found end - end - - local dkind = def.kind - local dfull = derive_fullname (cat, dname, dkind) - if derive_fullname (cat, target, dkind) == dfull then - local found = search_paths (dfull) - if found then return found end - end + for i = 1, nvariants do + local variant = variants[i] - local dours = def.ours - if dours then - - local _, ourname = derive_ourname (dours, dkind) - if target == dours then - local found = search_paths (ourname) + local dname = def.name + if variant == dname then + local found = search_paths (variant .. derive_suffix (def.kind)) if found then return found end end - if target == ourname then - local found = search_paths (ourname) + local dkind = def.kind + local dfull = derive_fullname (cat, dname, dkind) + if derive_fullname (cat, variant, dkind) == dfull then + local found = search_paths (dfull) if found then return found end end - end + local dours = def.ours + if dours then + + local _, ourname = derive_ourname (dours, dkind) + if variant == dours then + local found = search_paths (ourname) + if found then return found end + end + + if variant == ourname then + local found = search_paths (ourname) + if found then return found end + end + end + + end end end return false -- cgit v1.2.3