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

Side by Side Diff: tools/find_run_binary.py

Issue 156173005: Create a common utility for finding and running binaries in out/ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Lint Created 6 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/tests/base_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Module that finds and runs a binary by looking in the likely locations."""
7
8
9 import os
10 import subprocess
11 import sys
12
13
14 def run_command(args):
15 """Runs a program from the command line and returns stdout.
16
17 Args:
18 args: Command line to run, as a list of string parameters. args[0] is the
19 binary to run.
20
21 Returns:
22 stdout from the program, as a single string.
23
24 Raises:
25 Exception: the program exited with a nonzero return code.
26 """
27 proc = subprocess.Popen(args,
28 stdout=subprocess.PIPE,
29 stderr=subprocess.PIPE)
30 (stdout, stderr) = proc.communicate()
31 if proc.returncode is not 0:
32 raise Exception('command "%s" failed: %s' % (args, stderr))
33 return stdout
34
35
36 def find_path_to_program(program):
37 """Returns path to an existing program binary.
38
39 Args:
40 program: Basename of the program to find (e.g., 'render_pictures').
41
42 Returns:
43 Absolute path to the program binary, as a string.
44
45 Raises:
46 Exception: unable to find the program binary.
47 """
48 trunk_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
49 os.pardir))
50 possible_paths = [os.path.join(trunk_path, 'out', 'Release', program),
51 os.path.join(trunk_path, 'out', 'Debug', program),
52 os.path.join(trunk_path, 'out', 'Release',
53 program + '.exe'),
54 os.path.join(trunk_path, 'out', 'Debug',
55 program + '.exe')]
56 for try_path in possible_paths:
57 if os.path.isfile(try_path):
58 return try_path
59 raise Exception('cannot find %s in paths %s; maybe you need to '
60 'build %s?' % (program, possible_paths, program))
61
OLDNEW
« no previous file with comments | « no previous file | tools/tests/base_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698