Skip to content

Commit

Permalink
manifest: general fixups and sorts-out
Browse files Browse the repository at this point in the history
global vs local options per group are more coherent 

but realised that setting your own manifestgroup is impossible without hardcoding all variables

also check if no descriptions need to printed not to use a table
  • Loading branch information
wspr committed Nov 22, 2017
1 parent a3088d5 commit eb33ef5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
8 changes: 4 additions & 4 deletions l3build.dtx
Expand Up @@ -149,12 +149,12 @@
\luavarset{typesetcmds} {""} {Instructions to be passed to \TeX{} when doing typesetting.}
\luavarset{versionform} {""} {Nature of version strings for auto-replacement.}
\luavarset{recordstatus} {false} {Include error level(s) from test run(s) in TLG files?}
\luavarset{manifestfile} {"MANIFEST.md"} {Filename to use for the manifest file.}
\luavarset{manifestoptions} {} {Table for controlling the \texttt{manifest} output file.}
}
\allluavars

% not typeset in the table
\luavarset{manifestoptions.filename} {"MANIFEST.md"} {Filename to use for the manifest file.}
\luavarset{manifestoptions.groupdescription}{true} {Whether to include description text within each group of files.}
\luavarset{manifestoptions.extractfiledesc} {false} {Whether to include a one-line description of each file extracted from the file itself.}
\luavarset{manifestoptions.linenumber} {2} {If extracting by line, which line to use.}
Expand Down Expand Up @@ -1194,7 +1194,7 @@
% \begin{center}
% \begin{tabular}{ll}
% \toprule
% Entry & Default \\
% Entry & Default & Notes \\
% \midrule
% \var{filename} & \luavar{manifestoptions.filename} \\
% \var{groupdescription} & \luavar{manifestoptions.groupdescription} \\
Expand All @@ -1218,7 +1218,7 @@
% These are source files generating the package files.
% ]],
% files = {"*.dtx","*.ins"},
% extractfiledescr = true,
% extractfiledesc = true,
% },
% ...
% }
Expand All @@ -1236,7 +1236,7 @@
% \var{exclude} & Files to exclude (default |{exclude}|) \\
% \var{dir} & The directory to search (default |maindir|) \\
% \var{rename} & An array with a |gsub| redefinition for the filename \\
% \var{extractfiledescr} & Whether to extract file descriptions from these files, and how (default |false|) \\
% \var{extractfiledesc} & Whether to extract file descriptions from these files, and how (default |false|) \\
% \bottomrule
% \end{tabular}
% \end{center}
Expand Down
69 changes: 35 additions & 34 deletions l3build.lua
Expand Up @@ -190,21 +190,26 @@ psext = psext or ".ps"
tlgext = tlgext or ".tlg"
-- Manifest options
manifestoptionsdefaults = {
filename = "MANIFEST.md" ,
manifestfile = "MANIFEST.md"
private_manifest_defaults = {
groupdescription = true ,
extractfiledesc = false , -- or 'line' or 'file', or false to turn off
linenumber = 2 , -- for extractfiledesc = 'line'
matchstr = "%%%S%s+(.*)" ,
-- e.g. for file matching: "\\section{(.-)}"
extractfiledesc = false ,
extractoptions = {
linenumber = 2 ,
matchstr = "%%%S%s+(.*)" ,
-- e.g. for first section title instead, remove `linenumber` for file matching, then matchstr = "\\section{(.-)}"
},
sortfileswithin = "glob" , -- or 'group'
rename = false ,
dir = maindir ,
exclude = {excludefiles},
}
-- set either global defaults...
manifestoptions = manifestoptions or manifestoptionsdefaults
manifestoptions = manifestoptions or private_manifest_defaults
-- ... or individual defaults if not specified by the user
for ii,vv in pairs(manifestoptionsdefaults) do
for ii,vv in pairs(private_manifest_defaults) do
manifestoptions[ii] = manifestoptions[ii] or vv
end
Expand All @@ -218,15 +223,13 @@ process which generates the installation files of the package. Additional
files included here will also be installed for processing such as testing.
]],
files = {sourcefiles},
extractfiledescr = true,
},
{
name = "Typeset documentation source files",
description = [[
These files are typeset using LaTeX to produce the PDF documentation for the package.
]],
files = {typesetfiles,typesetsourcefiles,typesetdemofiles},
extractfiledescr = true,
},
{
name = "Documentation files",
Expand All @@ -236,7 +239,6 @@ Generally they will be additional input files for the typeset
documentation files listed above.
]],
files = {docfiles},
extractfiledescr = true,
},
{
name = "Text files",
Expand Down Expand Up @@ -265,14 +267,12 @@ documentation files listed above.
name = "Support files needed for unpacking, typesetting, or checking",
files = {unpacksuppfiles,typesetsuppfiles,checksuppfiles},
dir = supportdir,
extractfiledescr = true,
},
{
name = "Checking-specific support files",
files = {"*.*"},
exclude = {{".",".."},excludefiles},
dir = testsuppdir,
extractfiledescr = true,
},
{
name = "Test files",
Expand Down Expand Up @@ -2471,17 +2471,17 @@ function writemanifest()
for ii,vv in ipairs(manifestgroups) do
file_lists[ii] = vv
-- defaults
file_lists[ii].rename = file_lists[ii].rename or nil
file_lists[ii].dir = file_lists[ii].dir or maindir
file_lists[ii].exclude = file_lists[ii].exclude or {excludefiles}
file_lists[ii].extractfiledescr = file_lists[ii].extractfiledescr or false
-- copy global options locally
for kk,_ in pairs(private_manifest_defaults) do
file_lists[ii][kk] = file_lists[ii][kk] or manifestoptions[kk]
end
-- initialisation for internal data
file_lists[ii].N = 0
file_lists[ii].matches = {}
file_lists[ii].N = 0
file_lists[ii].ND = 0
file_lists[ii].matches = {}
file_lists[ii].file_order = {}
file_lists[ii].descr = {}
file_lists[ii].descr = {}
end
-- create all matching files
Expand All @@ -2490,7 +2490,7 @@ function writemanifest()
end
-- write the manifest file
local f = assert(io.open(manifestoptions.filename, "w"))
local f = assert(io.open(manifestfile, "w"))
f:write("# Manifest for " .. module .. "\n\n")
f:write("This file is automatically generated with `texlua build.lua manifest`.\n")
Expand All @@ -2499,11 +2499,11 @@ function writemanifest()
f:write("\n## " .. file_lists[ii].name .. "\n\n")
if manifestoptions.groupdescription and file_lists[ii].description then
if file_lists[ii].groupdescription and file_lists[ii].description then
f:write(file_lists[ii].description .. "\n")
end
if manifestoptions.extractfiledesc and file_lists[ii].extractfiledescr then
if not(file_lists[ii].rename) and file_lists[ii].extractfiledesc and file_lists[ii].ND > 0 then
-- file descriptions: create ascii table (compat. w/ Github markdown)
-- calculate maximum field lengths for pretty ascii table
Expand Down Expand Up @@ -2537,7 +2537,7 @@ function writemanifest()
f:close()
print("*******************************************")
print("Manifest written to " .. manifestoptions.filename .. ".")
print("Manifest written to " .. manifestfile .. ".")
print("*******************************************")
end
Expand Down Expand Up @@ -2567,7 +2567,7 @@ function build_manifest(file_list)
for _,this_glob in ipairs(glob_list) do
local these_files = filelist(file_list.dir,this_glob)
if manifestoptions.sortfileswithin == "glob" then
if file_list.sortfileswithin == "glob" then
table.sort(these_files)
end
Expand All @@ -2586,13 +2586,16 @@ function build_manifest(file_list)
file_list.file_order[file_list.N] = this_file -- store the file order
end
if file_list.extractfiledescr and manifestoptions.extractfiledesc then
if not(file_list.rename) and file_list.extractfiledesc then
file_list = extract_descriptions(file_list,this_file)
if file_list.descr[this_file] and file_list.descr[this_file] ~= "" then
file_list.ND = file_list.ND+1 -- track # matched files
end
end
end
end
if manifestoptions.sortfileswithin == "group" then
if file_list.sortfileswithin == "group" then
table.sort(file_list.file_order)
end
Expand All @@ -2606,20 +2609,18 @@ end
function extract_descriptions(file_list,this_file)
local end_read_loop = 1
local read_string = ""
if manifestoptions.extractfiledesc == "line" then
end_read_loop = manifestoptions.linenumber
local read_string = "*all"
if manifestoptions.extractoptions.linenumber then
end_read_loop = manifestoptions.extractoptions.linenumber
read_string = "*line"
elseif manifestoptions.extractfiledesc == "file" then
read_string = "*all"
end
local fopen = assert(io.open(file_list.dir .. "/" .. this_file, "r"))
for ii = 1, end_read_loop do
t = fopen:read(read_string)
end
fopen:close()
file_list.descr[this_file] = string.match(t,manifestoptions.matchstr)
file_list.descr[this_file] = string.match(t,manifestoptions.extractoptions.matchstr)
return file_list
Expand Down

0 comments on commit eb33ef5

Please sign in to comment.