| OLD | NEW | 
|   1 # Copyright 2013 The Chromium Authors. All rights reserved. |   1 # Copyright 2013 The Chromium Authors. All rights reserved. | 
|   2 # Use of this source code is governed by a BSD-style license that can be |   2 # Use of this source code is governed by a BSD-style license that can be | 
|   3 # found in the LICENSE file. |   3 # found in the LICENSE file. | 
|   4  |   4  | 
|   5 import fnmatch |   5 import fnmatch | 
|   6 import os |   6 import os | 
 |   7 import pipes | 
|   7 import shlex |   8 import shlex | 
|   8 import shutil |   9 import shutil | 
 |  10 import subprocess | 
 |  11 import sys | 
 |  12 import traceback | 
|   9  |  13  | 
|  10  |  14  | 
|  11 def MakeDirectory(dir_path): |  15 def MakeDirectory(dir_path): | 
|  12   try: |  16   try: | 
|  13     os.makedirs(dir_path) |  17     os.makedirs(dir_path) | 
|  14   except OSError: |  18   except OSError: | 
|  15     pass |  19     pass | 
|  16  |  20  | 
|  17  |  21  | 
|  18 def DeleteDirectory(dir_path): |  22 def DeleteDirectory(dir_path): | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  44 def ParseGypList(gyp_string): |  48 def ParseGypList(gyp_string): | 
|  45   # The ninja generator doesn't support $ in strings, so use ## to |  49   # The ninja generator doesn't support $ in strings, so use ## to | 
|  46   # represent $. |  50   # represent $. | 
|  47   # TODO(cjhopman): Remove when |  51   # TODO(cjhopman): Remove when | 
|  48   # https://code.google.com/p/gyp/issues/detail?id=327 |  52   # https://code.google.com/p/gyp/issues/detail?id=327 | 
|  49   # is addressed. |  53   # is addressed. | 
|  50   gyp_string = gyp_string.replace('##', '$') |  54   gyp_string = gyp_string.replace('##', '$') | 
|  51   return shlex.split(gyp_string) |  55   return shlex.split(gyp_string) | 
|  52  |  56  | 
|  53  |  57  | 
 |  58 # This can be used in most cases like subprocess.check_call. The output, | 
 |  59 # particularly when the command fails, better highlights the command's failure. | 
 |  60 # This call will directly exit on a failure in the subprocess so that no python | 
 |  61 # stacktrace is printed after the output of the failed command. | 
 |  62 def CheckCallDie(args, cwd=None): | 
 |  63   if not cwd: | 
 |  64     cwd = os.getcwd() | 
 |  65  | 
 |  66   child = subprocess.Popen(args, | 
 |  67       stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd) | 
 |  68  | 
 |  69   stdout, _ = child.communicate() | 
 |  70  | 
 |  71   if child.returncode: | 
 |  72     stacktrace = traceback.extract_stack() | 
 |  73     print >> sys.stderr, ''.join(traceback.format_list(stacktrace)) | 
 |  74     # A user should be able to simply copy and paste the command that failed | 
 |  75     # into their shell. | 
 |  76     copyable_command = ' '.join(map(pipes.quote, args)) | 
 |  77     copyable_command = ('( cd ' + os.path.abspath(cwd) + '; ' | 
 |  78         + copyable_command + ' )') | 
 |  79     print >> sys.stderr, 'Command failed:', copyable_command, '\n' | 
 |  80  | 
 |  81     if stdout: | 
 |  82       print stdout, | 
 |  83  | 
 |  84     # Directly exit to avoid printing stacktrace. | 
 |  85     sys.exit(child.returncode) | 
 |  86  | 
 |  87   else: | 
 |  88     if stdout: | 
 |  89       print stdout, | 
 |  90  | 
| OLD | NEW |