summaryrefslogtreecommitdiff
path: root/tools/buildman/test.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-03-18 18:42:45 +0300
committerTom Rini <trini@konsulko.com>2020-04-11 04:21:06 +0300
commit925f6adfa53c2a80a1d7ce731e628cded13f5363 (patch)
tree936dab0a376597af9a3a815ccf0c345184928be6 /tools/buildman/test.py
parent7beb43c9807159463ad6dd2a29517d4cee1e7478 (diff)
downloadu-boot-925f6adfa53c2a80a1d7ce731e628cded13f5363.tar.xz
buildman: Be more selective about which directories to remove
At present buildman removes any directory it doesn't intend to write output into. This is overly expansive since if the output directory happens to be somewhere with existing files, they may be removed. Using an existing directory for buildman is not a good practice, but since the result might be catastrophic, it is best to guard against it. A previous commit[1] fixed this by refusing to write to a subdirectory of the current directory, assumed to have U-Boot source code. But we can do better by only removing directories that look like the ones buildman creates. Update the code to do this and add a test. Signed-off-by: Simon Glass <sjg@chromium.org> [1] 409fc029c40 tools: buildman: Don't use the working dir as build dir
Diffstat (limited to 'tools/buildman/test.py')
-rw-r--r--tools/buildman/test.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index acd862b3b0..2aaedf44ac 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -22,6 +22,7 @@ import commit
import terminal
import test_util
import toolchain
+import tools
use_network = True
@@ -469,6 +470,25 @@ class TestBuild(unittest.TestCase):
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()