From e13960240bdff0fe151499ada0fed07f677f056e Mon Sep 17 00:00:00 2001 From: Chris Sosa Date: Mon, 30 Aug 2010 22:37:28 -0700 Subject: [PATCH] Fix cleanup so we don't have to clobber as much when failures occur Change-Id: I120c49a38d2a17a2216296a68378fee7345f616a TBR=petkov Review URL: http://codereview.chromium.org/3255004 --- bin/cbuildbot.py | 5 +++-- lib/cros_build_lib.py | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/cbuildbot.py b/bin/cbuildbot.py index 103d5126de..86e498047b 100755 --- a/bin/cbuildbot.py +++ b/bin/cbuildbot.py @@ -216,6 +216,7 @@ def _FullCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES): def _IncrementalCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES): """Performs a checkout without clobbering previous checkout.""" + _UprevCleanup(buildroot, error_ok=True) RepoSync(buildroot, rw_checkout, retries) @@ -281,12 +282,12 @@ def _UprevPackages(buildroot, revisionfile, board): _UprevAllPackages(buildroot) -def _UprevCleanup(buildroot): +def _UprevCleanup(buildroot, error_ok=False): """Clean up after a previous uprev attempt.""" cwd = os.path.join(buildroot, 'src', 'scripts') RunCommand(['./cros_mark_as_stable', '--srcroot=..', '--tracking_branch="cros/master"', 'clean'], - cwd=cwd) + cwd=cwd, error_ok=error_ok) def _UprevPush(buildroot): diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py index 7b9b00da86..a0cd73c6ed 100644 --- a/lib/cros_build_lib.py +++ b/lib/cros_build_lib.py @@ -34,6 +34,7 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, stdout = None stderr = None stdin = None + output = '' # Modify defaults based on parameters. if redirect_stdout: stdout = subprocess.PIPE @@ -45,15 +46,21 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, if print_cmd: Info('RunCommand: %s' % ' '.join(cmd)) - proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, - stdout=stdout, stderr=stderr) - (output, error) = proc.communicate(input) - if exit_code: - return proc.returncode + try: + proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, + stdout=stdout, stderr=stderr) + (output, error) = proc.communicate(input) + if exit_code: + return proc.returncode - if not error_ok and proc.returncode: - raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) + - (error_message or error or output or '')) + if not error_ok and proc.returncode: + raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) + + (error_message or error or output or '')) + except Exception,e: + if not error_ok: + raise + else: + Warning(str(e)) return output