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 ast | 5 import ast |
6 import contextlib | 6 import contextlib |
7 import fnmatch | 7 import fnmatch |
8 import json | 8 import json |
9 import os | 9 import os |
10 import pipes | 10 import pipes |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 # A user should be able to simply copy and paste the command that failed | 145 # A user should be able to simply copy and paste the command that failed |
146 # into their shell. | 146 # into their shell. |
147 copyable_command = '( cd {}; {} )'.format(os.path.abspath(self.cwd), | 147 copyable_command = '( cd {}; {} )'.format(os.path.abspath(self.cwd), |
148 ' '.join(map(pipes.quote, self.args))) | 148 ' '.join(map(pipes.quote, self.args))) |
149 return 'Command failed: {}\n{}'.format(copyable_command, self.output) | 149 return 'Command failed: {}\n{}'.format(copyable_command, self.output) |
150 | 150 |
151 | 151 |
152 # This can be used in most cases like subprocess.check_output(). The output, | 152 # This can be used in most cases like subprocess.check_output(). The output, |
153 # particularly when the command fails, better highlights the command's failure. | 153 # particularly when the command fails, better highlights the command's failure. |
154 # If the command fails, raises a build_utils.CalledProcessError. | 154 # If the command fails, raises a build_utils.CalledProcessError. |
155 def CheckOutput(args, cwd=None, | 155 def CheckOutput(args, cwd=None, env=None, |
156 print_stdout=False, print_stderr=True, | 156 print_stdout=False, print_stderr=True, |
157 stdout_filter=None, | 157 stdout_filter=None, |
158 stderr_filter=None, | 158 stderr_filter=None, |
159 fail_func=lambda returncode, stderr: returncode != 0): | 159 fail_func=lambda returncode, stderr: returncode != 0): |
160 if not cwd: | 160 if not cwd: |
161 cwd = os.getcwd() | 161 cwd = os.getcwd() |
162 | 162 |
163 child = subprocess.Popen(args, | 163 child = subprocess.Popen(args, |
164 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) | 164 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env) |
165 stdout, stderr = child.communicate() | 165 stdout, stderr = child.communicate() |
166 | 166 |
167 if stdout_filter is not None: | 167 if stdout_filter is not None: |
168 stdout = stdout_filter(stdout) | 168 stdout = stdout_filter(stdout) |
169 | 169 |
170 if stderr_filter is not None: | 170 if stderr_filter is not None: |
171 stderr = stderr_filter(stderr) | 171 stderr = stderr_filter(stderr) |
172 | 172 |
173 if fail_func(child.returncode, stderr): | 173 if fail_func(child.returncode, stderr): |
174 raise CalledProcessError(cwd, args, stdout + stderr) | 174 raise CalledProcessError(cwd, args, stdout + stderr) |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 515 |
516 md5_check.CallAndRecordIfStale( | 516 md5_check.CallAndRecordIfStale( |
517 on_stale_md5, | 517 on_stale_md5, |
518 record_path=record_path, | 518 record_path=record_path, |
519 input_paths=input_paths, | 519 input_paths=input_paths, |
520 input_strings=input_strings, | 520 input_strings=input_strings, |
521 output_paths=output_paths, | 521 output_paths=output_paths, |
522 force=force, | 522 force=force, |
523 pass_changes=True) | 523 pass_changes=True) |
524 | 524 |
OLD | NEW |