Index: runtime/tools/create_snapshot_bin.py |
diff --git a/runtime/tools/create_snapshot_bin.py b/runtime/tools/create_snapshot_bin.py |
index 9d6460fdfe3da75a039e32c527cca5b5c12b47d2..461df64d0a0388024dc4572f8bc99932b0b089de 100755 |
--- a/runtime/tools/create_snapshot_bin.py |
+++ b/runtime/tools/create_snapshot_bin.py |
@@ -9,17 +9,15 @@ |
import getopt |
import optparse |
import os |
-from os.path import abspath, basename, dirname, join |
-import string |
-import subprocess |
+from os.path import basename, join |
import sys |
-import tempfile |
import utils |
HOST_OS = utils.GuessOS() |
HOST_CPUS = utils.GuessCpus() |
- |
+DEBUG = False |
+VERBOSE = False |
def BuildOptions(): |
result = optparse.OptionParser() |
@@ -55,22 +53,13 @@ def ProcessOptions(options): |
return True |
-def RunHost(command): |
- print "command %s" % command |
- pipe = subprocess.Popen(args=command, |
- shell=True, |
- stdout=subprocess.PIPE, |
- stderr=subprocess.PIPE) |
- out, error = pipe.communicate() |
- if (pipe.returncode != 0): |
- print out, error |
- print "command failed" |
- print "(Command was: '", ' '.join(command), "')" |
- raise Exception("Failed") |
+def RunAdb(device, command): |
+ """Run a raw adb command.""" |
+ return utils.RunCommand(["adb", "-s", device] + command) |
-def RunTarget(command): |
- RunHost("adb shell %s" % command) |
+def RunAdbShell(device, command): |
+ RunAdb(device, ['shell'] + command) |
def RunOnAndroid(options): |
@@ -102,20 +91,34 @@ def RunOnAndroid(options): |
filesToPush.append((executable, android_executable)) |
- command = ' '.join(script_args) |
+ abi = 'x86' |
+ # We know we're run in the runtime directory, and we know the relative path |
+ # to the tools we want to execute: |
+# try: |
Emily Fortuna
2012/08/28 16:49:14
Just remove code instead of commenting out
jackpal
2012/08/28 20:15:20
Done.
|
+ device = utils.RunCommand( |
+ ["tools/android_finder.py", "--bootstrap", "--abi", abi, '--verbose'], |
+ errStream=sys.stderr) |
+# except Exception as e: |
+# device = None |
+ |
+ if device == None: |
+ raise Exception("Could not find Android device for abi %s" % abi) |
+ |
+ device = device.strip() |
+ |
+ RunAdbShell(device, ["mkdir", android_workspace]) |
- RunHost("adb shell mkdir %s" % android_workspace) |
try: |
for src, dest in filesToPush: |
- RunHost("adb push '%s' '%s'" % (src, dest)) |
- RunTarget(command) |
+ RunAdb(device, ["push", src, dest]) |
+ RunAdbShell(device, script_args) |
for src, dest in filesToPull: |
- RunHost("adb pull '%s' '%s'" % (src, dest)) |
+ RunAdb(device, ["pull", src, dest]) |
finally: |
for src, dest in filesToPush: |
- RunHost("adb shell rm '%s'" % dest) |
+ RunAdbShell(device, ["rm", dest]) |
for src, dest in filesToPull: |
- RunHost("adb shell rm '%s'" % src) |
+ RunAdbShell(device, ["rm", src]) |
def Main(): |
@@ -147,25 +150,14 @@ def Main(): |
script_args.append(options.script) |
# Construct command line to execute the snapshot generator binary and invoke. |
- command = [ options.executable ] + script_args |
- if options.verbose: |
- print ' '.join(command) |
- |
if options.target_os == 'android': |
+ RunOnAndroid(options) |
+ else: |
+ command = [ options.executable ] + script_args |
try: |
- RunOnAndroid(options) |
+ utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, |
+ verbose=options.verbose, printErrorInfo=True) |
except Exception as e: |
- print "Could not run on Android: %s" % e |
- return -1 |
- else: |
- pipe = subprocess.Popen(command, |
- stdout=subprocess.PIPE, |
- stderr=subprocess.PIPE) |
- out, error = pipe.communicate() |
- if (pipe.returncode != 0): |
- print out, error |
- print "Snapshot generation failed" |
- print "(Command was: '", ' '.join(command), "')" |
return -1 |
return 0 |