summaryrefslogtreecommitdiff
path: root/mkfilelist
blob: 756bfe096b3921a14874a7c3b71bde4fd48be7ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env texlua
-----------------------------------------------------------------------
--         FILE:  mkfilelist.lua
--        USAGE:  ./mkfilelist.lua 
--  DESCRIPTION:  part of the luaotfload package
-- REQUIREMENTS:  luatex, the lualibs package
--       AUTHOR:  Philipp Gesang (Phg), <phg42.2a@gmail.com>
--      VERSION:  1.0
--      CREATED:  2013-07-07 14:01:12+0200
-----------------------------------------------------------------------
--
-- This script generates a list of hashes that serves as the input
-- for the file integrity check (option --diagnose). md5 is all we can
-- assume in Luatex, so it’s really only a superficial test.

kpse.set_program_name "luatex"

local md5 = require "md5"

require "lualibs"

local stringformat = string.format
local md5sumhexa   = md5.sumhexa
local ioloaddata   = io.loaddata
local iosavedata   = io.savedata

-----------------------------------------------------------------------
-- settings
-----------------------------------------------------------------------

local filelist = "luaotfload-files.lua" --- result

local names = {
  --- only the runtime files and scripts
  "luaotfload-auxiliary.lua",
  "luaotfload-basics-gen.lua",
  "luaotfload-basics-nod.lua",
  "luaotfload-characters.lua",
  "luaotfload-colors.lua",
  "luaotfload-database.lua",
  "luaotfload-extralibs.lua",
  "luaotfload-features.lua",
  "luaotfload-fonts-cbk.lua",
  "luaotfload-fonts-def.lua",
  "luaotfload-fonts-enc.lua",
  "luaotfload-fonts-ext.lua",
  "luaotfload-fonts-lua.lua",
  "luaotfload-fonts-tfm.lua",
  "luaotfload-glyphlist.lua",
  "luaotfload-letterspace.lua",
  "luaotfload-loaders.lua",
  "luaotfload.lua",
  "luaotfload-merged.lua",
  "luaotfload-override.lua",
  "luaotfload-tool.lua",
  "luaotfload-typo-krn.lua",
  "mkcharacters",
  "mkfilelist",
  "mkglyphlist",
}

-----------------------------------------------------------------------
-- helpers
-----------------------------------------------------------------------

local die = function (...)
  io.stderr:write "[fatal error]: "
  io.stderr:write (stringformat (...))
  io.stderr:write "\naborting.\n"
  os.exit (1)
end

-----------------------------------------------------------------------
-- functionality
-----------------------------------------------------------------------

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 hash_all
hash_all = function (list, acc)
  if list == nil then
    return hash_all (table.fastcopy (names), { })
  end

  local fname = list[#list]
  list[#list] = nil
  if fname then
    local sum = hash_file (fname)
    acc[#acc+1] = { fname, sum }
    return hash_all (list, acc)
  end
  return acc
end

local main = function ()
  local hashes      = hash_all ()
  local serialized  = table.serialize (hashes, true)
  local success     = io.savedata (filelist, serialized)
  if success == false then
    die ("could not write to %s.", filelist)
  end
  return 0
end

return main ()