summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/l3build/l3build-clean.lua
blob: 226650b478d8d3e33de17986665a7b0cc7faa2e3 (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
--[[

File l3build-clean.lua Copyright (C) 2018,2020,2021 The LaTeX Project

It may be distributed and/or modified under the conditions of the
LaTeX Project Public License (LPPL), either version 1.3c of this
license or (at your option) any later version.  The latest version
of this license is in the file

   http://www.latex-project.org/lppl.txt

This file is part of the "l3build bundle" (The Work in LPPL)
and all files in that bundle must be distributed together.

-----------------------------------------------------------------------

The development version of the bundle can be found at

   https://github.com/latex3/l3build

for those people who are interested.

--]]

local pairs   = pairs
local ipairs  = ipairs
local insert  = table.insert

-- Remove all generated files
function clean()
  -- To make sure that distribdir never contains any stray subdirs,
  -- it is entirely removed then recreated rather than simply deleting
  -- all of the files
  local errorlevel =  rmdir(distribdir)
                    + mkdir(distribdir)
                    + cleandir(localdir)
                    + cleandir(testdir)
                    + cleandir(typesetdir)
                    + cleandir(unpackdir)

  if errorlevel ~= 0 then return errorlevel end

  for _,dir in pairs(remove_duplicates({maindir,sourcefiledir,docfiledir})) do
    local clean_list  = {}
    local flags = {}
    for _,glob in pairs(cleanfiles) do
      for _,p in ipairs(tree(dir,glob)) do
        insert(clean_list, p.src)
        flags[p.src] = true
      end
    end
    for _,glob in pairs(sourcefiles) do
      for _,p in ipairs(tree(dir,glob)) do
        flags[p.src] = nil
      end
    end
    for i = #clean_list, 1, -1 do
      local p_src = clean_list[i]
      if flags[p_src] then
        errorlevel = rm(dir,p_src)
        if errorlevel ~= 0 then
          return errorlevel
        end
      end
    end
  end

  return 0
end

function bundleclean()
  local errorlevel = call(modules, "clean")
  for _,i in ipairs(cleanfiles) do
    errorlevel = rm(currentdir, i) + errorlevel
  end
  return  errorlevel
        + rmdir(ctandir)
        + rmdir(tdsdir)
end