if self.commits:
commit = self.commits[commit_upto]
subject = commit.subject.translate(trans_valid_chars)
+ # See _GetOutputSpaceRemovals() which parses this name
commit_dir = ('%02d_of_%02d_g%s_%s' % (commit_upto + 1,
self.commit_count, commit.hash, subject[:20]))
elif not self.no_subdirs:
for thread in range(max_threads):
self._PrepareThread(thread, setup_git)
- def _PrepareOutputSpace(self):
+ def _GetOutputSpaceRemovals(self):
"""Get the output directories ready to receive files.
- We delete any output directories which look like ones we need to
- create. Having left over directories is confusing when the user wants
- to check the output manually.
+ Figure out what needs to be deleted in the output directory before it
+ can be used. We only delete old buildman directories which have the
+ expected name pattern. See _GetOutputDir().
+
+ Returns:
+ List of full paths of directories to remove
"""
if not self.commits:
return
to_remove = []
for dirname in glob.glob(os.path.join(self.base_dir, '*')):
if dirname not in dir_list:
- to_remove.append(dirname)
+ leaf = dirname[len(self.base_dir) + 1:]
+ m = re.match('[0-9]+_of_[0-9]+_g[0-9a-f]+_.*', leaf)
+ if m:
+ to_remove.append(dirname)
+ return to_remove
+
+ def _PrepareOutputSpace(self):
+ """Get the output directories ready to receive files.
+
+ We delete any output directories which look like ones we need to
+ create. Having left over directories is confusing when the user wants
+ to check the output manually.
+ """
+ to_remove = self._GetOutputSpaceRemovals()
if to_remove:
Print('Removing %d old build directories' % len(to_remove),
newline=False)
import terminal
import test_util
import toolchain
+import tools
use_network = True
self.assertEqual('HOSTCC=clang CC=clang',
tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
+ def testPrepareOutputSpace(self):
+ def _Touch(fname):
+ tools.WriteFile(os.path.join(base_dir, fname), b'')
+
+ base_dir = tempfile.mkdtemp()
+
+ # Add various files that we want removed and left alone
+ to_remove = ['01_of_22_g0982734987_title', '102_of_222_g92bf_title',
+ '01_of_22_g2938abd8_title']
+ to_leave = ['something_else', '01-something.patch', '01_of_22_another']
+ for name in to_remove + to_leave:
+ _Touch(name)
+
+ build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
+ build.commits = self.commits
+ build.commit_count = len(commits)
+ result = set(build._GetOutputSpaceRemovals())
+ expected = set([os.path.join(base_dir, f) for f in to_remove])
+ self.assertEqual(expected, result)
if __name__ == "__main__":
unittest.main()