From eb33ef58fb3919ce1642985436886ce2a447d8d2 Mon Sep 17 00:00:00 2001 From: Will Robertson Date: Wed, 22 Nov 2017 21:40:20 +1030 Subject: [PATCH] manifest: general fixups and sorts-out 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 --- l3build.dtx | 8 +++---- l3build.lua | 69 +++++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/l3build.dtx b/l3build.dtx index bafda454..4bdac7e4 100644 --- a/l3build.dtx +++ b/l3build.dtx @@ -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.} @@ -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} \\ @@ -1218,7 +1218,7 @@ % These are source files generating the package files. % ]], % files = {"*.dtx","*.ins"}, -% extractfiledescr = true, +% extractfiledesc = true, % }, % ... % } @@ -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} diff --git a/l3build.lua b/l3build.lua index dff295aa..c76bcd9a 100644 --- a/l3build.lua +++ b/l3build.lua @@ -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 @@ -218,7 +223,6 @@ 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", @@ -226,7 +230,6 @@ files included here will also be installed for processing such as testing. These files are typeset using LaTeX to produce the PDF documentation for the package. ]], files = {typesetfiles,typesetsourcefiles,typesetdemofiles}, - extractfiledescr = true, }, { name = "Documentation files", @@ -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", @@ -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", @@ -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 @@ -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") @@ -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 @@ -2537,7 +2537,7 @@ function writemanifest() f:close() print("*******************************************") - print("Manifest written to " .. manifestoptions.filename .. ".") + print("Manifest written to " .. manifestfile .. ".") print("*******************************************") end @@ -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 @@ -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 @@ -2606,12 +2609,10 @@ 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")) @@ -2619,7 +2620,7 @@ function extract_descriptions(file_list,this_file) 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