Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Unified Diff: build/android/pylib/build_utils.py

Issue 12913028: Output better error messages during build (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/process_resources.py ('k') | build/android/strip_library_for_apk.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/build_utils.py
diff --git a/build/android/pylib/build_utils.py b/build/android/pylib/build_utils.py
index 8849a77df69b7ea79876bfbbf308f390cc2f3a25..ce7ed9e80dd0ab2a3316527bba562e9897310602 100644
--- a/build/android/pylib/build_utils.py
+++ b/build/android/pylib/build_utils.py
@@ -4,8 +4,12 @@
import fnmatch
import os
+import pipes
import shlex
import shutil
+import subprocess
+import sys
+import traceback
def MakeDirectory(dir_path):
@@ -51,3 +55,36 @@ def ParseGypList(gyp_string):
return shlex.split(gyp_string)
+# This can be used in most cases like subprocess.check_call. The output,
+# particularly when the command fails, better highlights the command's failure.
+# This call will directly exit on a failure in the subprocess so that no python
+# stacktrace is printed after the output of the failed command.
+def CheckCallDie(args, cwd=None):
+ if not cwd:
+ cwd = os.getcwd()
+
+ child = subprocess.Popen(args,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd)
+
+ stdout, _ = child.communicate()
+
+ if child.returncode:
+ stacktrace = traceback.extract_stack()
+ print >> sys.stderr, ''.join(traceback.format_list(stacktrace))
+ # A user should be able to simply copy and paste the command that failed
+ # into their shell.
+ copyable_command = ' '.join(map(pipes.quote, args))
+ copyable_command = ('( cd ' + os.path.abspath(cwd) + '; '
+ + copyable_command + ' )')
+ print >> sys.stderr, 'Command failed:', copyable_command, '\n'
+
+ if stdout:
+ print stdout,
+
+ # Directly exit to avoid printing stacktrace.
+ sys.exit(child.returncode)
+
+ else:
+ if stdout:
+ print stdout,
+
« no previous file with comments | « build/android/process_resources.py ('k') | build/android/strip_library_for_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698