aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/find_run_binary.py
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-07 18:41:49 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-07 18:41:49 +0000
commit164052e9cef7b1b6d64860f52176a4413b23fc5c (patch)
treeb48d77c6400ad897c662248104418c34a18fdf7c /tools/find_run_binary.py
parente6af4fb34bd780ff24e0e967a8dc73639ccc2a9d (diff)
Create a common utility for finding and running binaries in out/
NOTRY=true BUG=skia:2019 R=epoger@google.com Author: rmistry@google.com Review URL: https://codereview.chromium.org/156173005 git-svn-id: http://skia.googlecode.com/svn/trunk@13367 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/find_run_binary.py')
-rw-r--r--tools/find_run_binary.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/find_run_binary.py b/tools/find_run_binary.py
new file mode 100644
index 0000000000..f71a808666
--- /dev/null
+++ b/tools/find_run_binary.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+# Copyright (c) 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Module that finds and runs a binary by looking in the likely locations."""
+
+
+import os
+import subprocess
+import sys
+
+
+def run_command(args):
+ """Runs a program from the command line and returns stdout.
+
+ Args:
+ args: Command line to run, as a list of string parameters. args[0] is the
+ binary to run.
+
+ Returns:
+ stdout from the program, as a single string.
+
+ Raises:
+ Exception: the program exited with a nonzero return code.
+ """
+ proc = subprocess.Popen(args,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (stdout, stderr) = proc.communicate()
+ if proc.returncode is not 0:
+ raise Exception('command "%s" failed: %s' % (args, stderr))
+ return stdout
+
+
+def find_path_to_program(program):
+ """Returns path to an existing program binary.
+
+ Args:
+ program: Basename of the program to find (e.g., 'render_pictures').
+
+ Returns:
+ Absolute path to the program binary, as a string.
+
+ Raises:
+ Exception: unable to find the program binary.
+ """
+ trunk_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
+ os.pardir))
+ possible_paths = [os.path.join(trunk_path, 'out', 'Release', program),
+ os.path.join(trunk_path, 'out', 'Debug', program),
+ os.path.join(trunk_path, 'out', 'Release',
+ program + '.exe'),
+ os.path.join(trunk_path, 'out', 'Debug',
+ program + '.exe')]
+ for try_path in possible_paths:
+ if os.path.isfile(try_path):
+ return try_path
+ raise Exception('cannot find %s in paths %s; maybe you need to '
+ 'build %s?' % (program, possible_paths, program))
+