Chromium Code Reviews| Index: testing/android/generate_native_test.py |
| diff --git a/testing/android/generate_native_test.py b/testing/android/generate_native_test.py |
| index f65c841bc8e88fc217644538ed9531679cf824cf..55d23a4ab8b6346a227b181315439ca043d67f87 100755 |
| --- a/testing/android/generate_native_test.py |
| +++ b/testing/android/generate_native_test.py |
| @@ -22,9 +22,9 @@ import subprocess |
| import sys |
| # cmd_helper.py is under ../../build/android/ |
| -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', |
| - '..', 'build', 'android')) |
| -import cmd_helper # pylint: disable=F0401 |
| +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', |
| + '..', 'build', 'android'))) |
| +import cmd_helper # pylint: disable=F0401 |
| class NativeTestApkGenerator(object): |
| @@ -39,9 +39,9 @@ class NativeTestApkGenerator(object): |
| # Files or directories we need to copy to create a complete apk test shell. |
| _SOURCE_FILES = ['AndroidManifest.xml', |
| 'native_test_apk.xml', |
| - 'res', # res/values/strings.xml |
| - 'java', # .../ChromeNativeTestActivity.java |
| - ] |
| + 'res', # res/values/strings.xml |
| + 'java', # .../ChromeNativeTestActivity.java |
| + ] |
| # Files in the destion directory that have a "replaceme" string |
| # which should be replaced by the basename of the shared library. |
| @@ -54,13 +54,12 @@ class NativeTestApkGenerator(object): |
| def __init__(self, native_library, jars, output_directory, target_abi): |
| self._native_library = native_library |
| self._jars = jars |
| - self._output_directory = output_directory |
| + self._output_directory = os.path.abspath(output_directory) |
| self._target_abi = target_abi |
| self._root_name = None |
| if self._native_library: |
| self._root_name = self._LibraryRoot() |
| - logging.warn('root name: %s' % self._root_name) |
| - |
| + logging.warn('root name: %s', self._root_name) |
| def _LibraryRoot(self): |
| """Return a root name for a shared library. |
| @@ -79,28 +78,18 @@ class NativeTestApkGenerator(object): |
| def _CopyTemplateFiles(self): |
| """Copy files needed to build a new apk. |
| - TODO(jrg): add more smarts so we don't change file timestamps if |
| - the files don't change? |
| + Uses rsync to avoid unnecessary io. |
| """ |
| - srcdir = os.path.dirname(os.path.realpath( __file__)) |
| - if not os.path.exists(self._output_directory): |
| - os.makedirs(self._output_directory) |
| - for f in self._SOURCE_FILES: |
| - src = os.path.join(srcdir, f) |
| - dest = os.path.join(self._output_directory, f) |
| - if os.path.isfile(src): |
| - if os.path.exists(dest): |
| - os.remove(dest) |
| - logging.warn('%s --> %s' % (src, dest)) |
| - shutil.copyfile(src, dest) |
| - else: # directory |
| - if os.path.exists(dest): |
| - # One more sanity check since we're deleting a directory... |
| - if not '/out/' in dest: |
| - raise Exception('Unbelievable output directory; bailing for safety') |
| - shutil.rmtree(dest) |
| - logging.warn('%s --> %s' % (src, dest)) |
| - shutil.copytree(src, dest) |
| + srcdir = os.path.abspath(os.path.dirname(__file__)) |
| + destdir = self._output_directory |
| + if not os.path.exists(destdir): |
| + os.makedirs(destdir) |
| + elif not '/out/' in destdir: |
| + raise Exception('Unbelievable output directory; bailing for safety') |
| + logging.warning('rsync %s --> %s', self._SOURCE_FILES, destdir) |
| + logging.info(cmd_helper.GetCmdOutput( |
|
Isaac (away)
2012/06/24 20:08:06
Note the --delete flag might be too strong -- it c
|
| + ['rsync', '-aRv', '--delete', '--exclude', '.svn'] + |
| + self._SOURCE_FILES + [destdir], cwd=srcdir)) |
| def _ReplaceStrings(self): |
| """Replace 'replaceme' strings in generated files with a root libname. |
| @@ -114,17 +103,17 @@ class NativeTestApkGenerator(object): |
| dest = os.path.join(self._output_directory, f) |
| contents = open(dest).read() |
| contents = contents.replace('replaceme', self._root_name) |
| - dest = dest.replace('replaceme', self._root_name) # update the filename! |
| - open(dest, "w").write(contents) |
| + dest = dest.replace('replaceme', self._root_name) # update the filename! |
| + open(dest, 'w').write(contents) |
| def _CopyLibraryAndJars(self): |
| - """Copy the shlib and jars into the apk source tree (if relevant)""" |
| + """Copy the shlib and jars into the apk source tree (if relevant).""" |
| if self._native_library: |
| destdir = os.path.join(self._output_directory, 'libs/' + self._target_abi) |
| if not os.path.exists(destdir): |
| os.makedirs(destdir) |
| dest = os.path.join(destdir, os.path.basename(self._native_library)) |
| - logging.warn('strip %s --> %s' % (self._native_library, dest)) |
| + logging.warn('strip %s --> %s', self._native_library, dest) |
| strip = os.environ['STRIP'] |
| cmd_helper.RunCmd( |
| [strip, '--strip-unneeded', self._native_library, '-o', dest]) |
| @@ -134,7 +123,7 @@ class NativeTestApkGenerator(object): |
| os.makedirs(destdir) |
| for jar in self._jars: |
| dest = os.path.join(destdir, os.path.basename(jar)) |
| - logging.warn('%s --> %s' % (jar, dest)) |
| + logging.warn('%s --> %s', jar, dest) |
| shutil.copyfile(jar, dest) |
| def CreateBundle(self, ant_compile): |
| @@ -162,7 +151,7 @@ class NativeTestApkGenerator(object): |
| (stdout, _) = p.communicate() |
| logging.warn(stdout) |
| if p.returncode != 0: |
| - logging.error('Ant return code %d' % p.returncode) |
| + logging.error('Ant return code %d', p.returncode) |
| sys.exit(p.returncode) |
| def CompileAndroidMk(self): |
| @@ -189,9 +178,9 @@ def main(argv): |
| parser.add_option('--app_abi', default='armeabi', |
| help='ABI for native shared library') |
| parser.add_option('--ant-compile', action='store_true', |
| - help='If specified, build the generated apk with ant. ' |
| - 'Otherwise assume compiling within the Android ' |
| - 'source tree using Android.mk.') |
| + help=('If specified, build the generated apk with ant. ' |
| + 'Otherwise assume compiling within the Android ' |
| + 'source tree using Android.mk.')) |
| parser.add_option('--ant-args', |
| help='extra args for ant') |