diff options
author | ilevy@chromium.org <ilevy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-27 03:53:53 +0000 |
---|---|---|
committer | ilevy@chromium.org <ilevy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-27 03:53:53 +0000 |
commit | e3b43aa5364353b70ac23a1c879df4a119fdae7f (patch) | |
tree | 90dd834638bea025577c63843904d19349250c3a /testing | |
parent | 0c9ba8108da9d7c4624cd54359f169065efe018c (diff) | |
download | chromium_src-e3b43aa5364353b70ac23a1c879df4a119fdae7f.zip chromium_src-e3b43aa5364353b70ac23a1c879df4a119fdae7f.tar.gz chromium_src-e3b43aa5364353b70ac23a1c879df4a119fdae7f.tar.bz2 |
Use rsync to copy android testing directories
- excluding .svn directories, which were being pushed onto phones
- should also allow us to avoid unnecessary io
pylint cleanup of this file
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10662010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'testing')
-rwxr-xr-x | testing/android/generate_native_test.py | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/testing/android/generate_native_test.py b/testing/android/generate_native_test.py index f65c841..6a6173d 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. @@ -76,31 +75,22 @@ class NativeTestApkGenerator(object): else: return None - def _CopyTemplateFiles(self): + def _CopyTemplateFilesAndClearDir(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. This call also clears outstanding + files in the directory. """ - 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( + ['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 +104,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 +124,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): @@ -142,7 +132,7 @@ class NativeTestApkGenerator(object): if not ant_compile: self._SOURCE_FILES.append('Android.mk') self._REPLACEME_FILES.append('Android.mk') - self._CopyTemplateFiles() + self._CopyTemplateFilesAndClearDir() self._ReplaceStrings() self._CopyLibraryAndJars() @@ -162,7 +152,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 +179,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') |