Runs the specified command.
(command_line, working_dir, depot_tools_dir=None, output_file=None)
| 170 | |
| 171 | |
| 172 | def run(command_line, working_dir, depot_tools_dir=None, output_file=None): |
| 173 | """ Runs the specified command. """ |
| 174 | # add depot_tools to the path |
| 175 | env = os.environ |
| 176 | if not depot_tools_dir is None: |
| 177 | env['PATH'] = depot_tools_dir + os.pathsep + env['PATH'] |
| 178 | |
| 179 | sys.stdout.write('-------- Running "'+command_line+'" in "'+\ |
| 180 | working_dir+'"...'+"\n") |
| 181 | if not options.dryrun: |
| 182 | args = shlex.split(command_line.replace('\\', '\\\\')) |
| 183 | |
| 184 | if not output_file: |
| 185 | return subprocess.check_call( |
| 186 | args, cwd=working_dir, env=env, shell=(sys.platform == 'win32')) |
| 187 | try: |
| 188 | msg('Writing %s' % output_file) |
| 189 | with open(output_file, "w") as f: |
| 190 | return subprocess.check_call( |
| 191 | args, |
| 192 | cwd=working_dir, |
| 193 | env=env, |
| 194 | shell=(sys.platform == 'win32'), |
| 195 | stderr=subprocess.STDOUT, |
| 196 | stdout=f) |
| 197 | except subprocess.CalledProcessError: |
| 198 | msg('ERROR Run failed. See %s for output.' % output_file) |
| 199 | raise |
| 200 | |
| 201 | |
| 202 | def create_directory(path): |
no test coverage detected