| 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..768d79b034b0da19c0a9031a63e34a256e6b4f45 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()
|
| @@ -41,7 +39,10 @@ def BuildOptions():
|
| default=False, action="store_true")
|
| result.add_option("--target_os",
|
| action="store", type="string",
|
| - help="Which os to run the executable on")
|
| + help="Which os to run the executable on. Current choice is android")
|
| + result.add_option("--abi",
|
| + action="store", type="string",
|
| + help="Desired ABI for android target OS. armeabi-v7a or x86")
|
| return result
|
|
|
|
|
| @@ -52,25 +53,19 @@ def ProcessOptions(options):
|
| if not options.output_bin:
|
| sys.stderr.write('--output_bin not specified\n')
|
| return False
|
| + if options.abi and not options.target_os == 'android':
|
| + sys.stderr.write('--abi requires --target_os android\n')
|
| + return False
|
| 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 +97,31 @@ def RunOnAndroid(options):
|
|
|
| filesToPush.append((executable, android_executable))
|
|
|
| - command = ' '.join(script_args)
|
| + abi = options.abi or 'x86'
|
| + # We know we're run in the runtime directory, and we know the relative path
|
| + # to the tools we want to execute:
|
| + device = utils.RunCommand(
|
| + ["tools/android_finder.py", "--bootstrap", "--abi", abi, '--verbose'],
|
| + errStream=sys.stderr)
|
| +
|
| + 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 +153,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
|
|
|