Introduce a DirMaker class that disassembles the path up to '/' and stores all
directories in a list. That list is in creation order and pre-existing
directories are ignored, i.e. creating the two paths
'/usr/share/foo/bar/baz' and '/usr/share/foo/bar/boo' is stored as
[ '/usr/share/foo',
'/usr/share/foo/bar',
'/usr/share/foo/bar/baz',
'/usr/share/foo/bar/boo' ]
This is on the assumption that /usr/share already existed.
After all files have been installed, the list of created directories is
appended in reverse order to the install log. The uninstall script then
triggers rmdir on all directories.
If a custom install script drops files into the directories, removing those
will fail. This matches the current expectation, see the existing warning
"Remember that files created by custom scripts have not been removed."
Unfortunately, this makes the behavior on uninstall inconsistent. Assuming a
non-existing prefix,
ninja install && ninja uninstall
removes all traces of the install.
However,
ninja install && ninja install && ninja uninstall
removes the files only, not the directories as they already existed.
This could be fixed by just unconditionally removing any (emtpy) directories
that we drop files into, at the risk of removing system directories if empty.
For example, one could imagine /etc/foo.conf.d/ to be removed in that case if
it is empty.
https://github.com/mesonbuild/meson/issues/2032