summaryrefslogtreecommitdiffstats
path: root/tools/buildman/control.py
diff options
context:
space:
mode:
authorLothar Waßmann <LW@KARO-electronics.de>2018-04-08 05:14:11 -0600
committerSimon Glass <sjg@chromium.org>2018-05-16 00:25:19 -0600
commit409fc029c407291ac8c8d7fefa051a73912dc657 (patch)
treef3fbda45397d5cfeb2740650d85181c705568aad /tools/buildman/control.py
parent0315d6959fdd9d2a4d89016c311e9c8c8d239a10 (diff)
downloadu-boot-409fc029c407291ac8c8d7fefa051a73912dc657.tar.gz
u-boot-409fc029c407291ac8c8d7fefa051a73912dc657.tar.xz
u-boot-409fc029c407291ac8c8d7fefa051a73912dc657.zip
tools: buildman: Don't use the working dir as build dir
When the U-Boot base directory happens to have the same name as the branch that buildman is directed to use via the '-b' option and no output directory is specified with '-o', buildman happily starts removing the whole U-Boot sources eventually only stopped with the error message: OSError: [Errno 20] Not a directory: '../<branch-name>/boards.cfg Add a check to avoid this and also deal with the case where '-o' points to the source directory, or any subdirectory of it. Finally, tidy up the confusing logic for removing the old tree when using -b. This is only done when building a branch. Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de> Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Lothar Waßmann <LW@KARO-electronics.de>
Diffstat (limited to 'tools/buildman/control.py')
-rw-r--r--tools/buildman/control.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index c14b87842d..4ac4386db6 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -80,6 +80,28 @@ def ShowActions(series, why_selected, boards_selected, builder, options):
print ('Total boards to build for each commit: %d\n' %
len(why_selected['all']))
+def CheckOutputDir(output_dir):
+ """Make sure that the output directory is not within the current directory
+
+ If we try to use an output directory which is within the current directory
+ (which is assumed to hold the U-Boot source) we may end up deleting the
+ U-Boot source code. Detect this and print an error in this case.
+
+ Args:
+ output_dir: Output directory path to check
+ """
+ path = os.path.realpath(output_dir)
+ cwd_path = os.path.realpath('.')
+ while True:
+ if os.path.realpath(path) == cwd_path:
+ Print("Cannot use output directory '%s' since it is within the current directtory '%s'" %
+ (path, cwd_path))
+ sys.exit(1)
+ parent = os.path.dirname(path)
+ if parent == path:
+ break
+ path = parent
+
def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
clean_dir=False):
"""The main control code for buildman
@@ -251,9 +273,9 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
# output directory itself rather than any subdirectory.
if not options.no_subdirs:
output_dir = os.path.join(options.output_dir, dirname)
- if (clean_dir and output_dir != options.output_dir and
- os.path.exists(output_dir)):
- shutil.rmtree(output_dir)
+ if clean_dir and os.path.exists(output_dir):
+ shutil.rmtree(output_dir)
+ CheckOutputDir(output_dir)
builder = Builder(toolchains, output_dir, options.git_dir,
options.threads, options.jobs, gnu_make=gnu_make, checkout=True,
show_unknown=options.show_unknown, step=options.step,