Currently, lit creates a little "sandbox" for each test to use by doing two things:
- Creating a directory in the build folder for each test directory in the source tree.
- Within the folder in directory 1, creating a unique file prefix that can be appended to to create unique per-test filenames that an individual test can use.
No effort is made to clean these files up between test runs, which creates two problems.
First is that we just leak files. If a test changes, or gets removed, or moves to a different location, all the files remain in the old location. (Very) gradually this can contribute to out of disk space errors on build bots, but in general it's just bad practice.
More sinister is that leaked files from previous runs can lead to false positives in tests.
This patch makes lit clean up the output directory before each run. One existing design choice made this tricky: A tests' temporary folder is of the form <build-dir>/test/SourceDir/Output. We can't just rmtree the entire <build-dir>/test because there are some lit configuration files in there. So we would have to enumerate the top-level test directory deleting only certain ones.
To simplify this, I inverted the heirarchy, so that now it's <build-dir>/test/Output/SourceDir. this way we can just indiscriminately rmtree anything under Output without worrying about what it is.
A few tests on Windows show that the rmtree takes about 1.75 seconds with a full output tree, which is a negligible portion of the overall test suite run. On Linux I expect the rmtree to be even faster.
There is one test failure with this patch, in llvm-symbolizer.test. For some reason it's demangling symbols differently, which is quite bizarre. Still looking into this, but throwing up this patch early for high level comments.