Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: testing/android/generate_native_test.py

Issue 10408091: Chromium support of running DumpRenderTree as an apk on Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and move out net dependency from testing/android Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/test/test_support_android.cc ('k') | testing/android/native_test.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # On Android we build unit test bundles as shared libraries. To run 6 # On Android we build unit test bundles as shared libraries. To run
7 # tests, we launch a special "test runner" apk which loads the library 7 # tests, we launch a special "test runner" apk which loads the library
8 # then jumps into it. Since java is required for many tests 8 # then jumps into it. Since java is required for many tests
9 # (e.g. PathUtils.java), a "pure native" test bundle is inadequate. 9 # (e.g. PathUtils.java), a "pure native" test bundle is inadequate.
10 # 10 #
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 [strip, '--strip-unneeded', self._native_library, '-o', dest]) 130 [strip, '--strip-unneeded', self._native_library, '-o', dest])
131 if self._jars: 131 if self._jars:
132 destdir = os.path.join(self._output_directory, 'libs') 132 destdir = os.path.join(self._output_directory, 'libs')
133 if not os.path.exists(destdir): 133 if not os.path.exists(destdir):
134 os.makedirs(destdir) 134 os.makedirs(destdir)
135 for jar in self._jars: 135 for jar in self._jars:
136 dest = os.path.join(destdir, os.path.basename(jar)) 136 dest = os.path.join(destdir, os.path.basename(jar))
137 logging.warn('%s --> %s' % (jar, dest)) 137 logging.warn('%s --> %s' % (jar, dest))
138 shutil.copyfile(jar, dest) 138 shutil.copyfile(jar, dest)
139 139
140 def CreateBundle(self): 140 def CreateBundle(self, ant_compile):
141 """Create the apk bundle source and assemble components.""" 141 """Create the apk bundle source and assemble components."""
142 if not ant_compile:
143 self._SOURCE_FILES.append('Android.mk')
144 self._REPLACEME_FILES.append('Android.mk')
142 self._CopyTemplateFiles() 145 self._CopyTemplateFiles()
143 self._ReplaceStrings() 146 self._ReplaceStrings()
144 self._CopyLibraryAndJars() 147 self._CopyLibraryAndJars()
145 148
146 def Compile(self, ant_args): 149 def Compile(self, ant_args):
147 """Build the generated apk with ant. 150 """Build the generated apk with ant.
148 151
149 Args: 152 Args:
150 ant_args: extra args to pass to ant 153 ant_args: extra args to pass to ant
151 """ 154 """
152 cmd = ['ant'] 155 cmd = ['ant']
153 if ant_args: 156 if ant_args:
154 cmd.append(ant_args) 157 cmd.append(ant_args)
155 cmd.extend(['-buildfile', 158 cmd.extend(['-buildfile',
156 os.path.join(self._output_directory, 'native_test_apk.xml')]) 159 os.path.join(self._output_directory, 'native_test_apk.xml')])
157 logging.warn(cmd) 160 logging.warn(cmd)
158 p = subprocess.Popen(cmd, stderr=subprocess.STDOUT) 161 p = subprocess.Popen(cmd, stderr=subprocess.STDOUT)
159 (stdout, _) = p.communicate() 162 (stdout, _) = p.communicate()
160 logging.warn(stdout) 163 logging.warn(stdout)
161 if p.returncode != 0: 164 if p.returncode != 0:
162 logging.error('Ant return code %d' % p.returncode) 165 logging.error('Ant return code %d' % p.returncode)
163 sys.exit(p.returncode) 166 sys.exit(p.returncode)
164 167
168 def CompileAndroidMk(self):
169 """Build the generated apk within Android source tree using Android.mk."""
170 try:
171 import compile_android_mk # pylint: disable=F0401
172 except:
173 raise AssertionError('Not in Android source tree. '
174 'Please use --ant-compile.')
175 compile_android_mk.CompileAndroidMk(self._native_library,
176 self._output_directory)
177
165 178
166 def main(argv): 179 def main(argv):
167 parser = optparse.OptionParser() 180 parser = optparse.OptionParser()
168 parser.add_option('--verbose', 181 parser.add_option('--verbose',
169 help='Be verbose') 182 help='Be verbose')
170 parser.add_option('--native_library', 183 parser.add_option('--native_library',
171 help='Full name of native shared library test bundle') 184 help='Full name of native shared library test bundle')
172 parser.add_option('--jars', 185 parser.add_option('--jars',
173 help='Space separated list of jars to be included') 186 help='Space separated list of jars to be included')
174 parser.add_option('--output', 187 parser.add_option('--output',
175 help='Output directory for generated files.') 188 help='Output directory for generated files.')
176 parser.add_option('--app_abi', default='armeabi', 189 parser.add_option('--app_abi', default='armeabi',
177 help='ABI for native shared library') 190 help='ABI for native shared library')
178 parser.add_option('--ant-compile', action='store_true', 191 parser.add_option('--ant-compile', action='store_true',
179 help='If specified, build the generated apk with ant') 192 help='If specified, build the generated apk with ant. '
193 'Otherwise assume compiling within the Android '
194 'source tree using Android.mk.')
180 parser.add_option('--ant-args', 195 parser.add_option('--ant-args',
181 help='extra args for ant') 196 help='extra args for ant')
182 197
183 options, _ = parser.parse_args(argv) 198 options, _ = parser.parse_args(argv)
184 199
185 # It is not an error to specify no native library; the apk should 200 # It is not an error to specify no native library; the apk should
186 # still be generated and build. It will, however, print 201 # still be generated and build. It will, however, print
187 # NATIVE_LOADER_FAILED when run. 202 # NATIVE_LOADER_FAILED when run.
188 if not options.output: 203 if not options.output:
189 raise Exception('No output directory specified for generated files') 204 raise Exception('No output directory specified for generated files')
190 205
191 if options.verbose: 206 if options.verbose:
192 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') 207 logging.basicConfig(level=logging.DEBUG, format=' %(message)s')
193 208
194 # Remove all quotes from the jars string 209 # Remove all quotes from the jars string
195 jar_list = [] 210 jar_list = []
196 if options.jars: 211 if options.jars:
197 jar_list = options.jars.replace('"', '').split() 212 jar_list = options.jars.replace('"', '').split()
213
214 # Ignore --ant-compile when building with Android source.
215 if 'ANDROID_BUILD_TOP' in os.environ:
216 options.ant_compile = False
217
198 ntag = NativeTestApkGenerator(native_library=options.native_library, 218 ntag = NativeTestApkGenerator(native_library=options.native_library,
199 jars=jar_list, 219 jars=jar_list,
200 output_directory=options.output, 220 output_directory=options.output,
201 target_abi=options.app_abi) 221 target_abi=options.app_abi)
202 ntag.CreateBundle() 222 ntag.CreateBundle(options.ant_compile)
223
203 if options.ant_compile: 224 if options.ant_compile:
204 ntag.Compile(options.ant_args) 225 ntag.Compile(options.ant_args)
226 else:
227 ntag.CompileAndroidMk()
205 228
206 logging.warn('COMPLETE.') 229 logging.warn('COMPLETE.')
207 230
208 if __name__ == '__main__': 231 if __name__ == '__main__':
209 sys.exit(main(sys.argv)) 232 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/test/test_support_android.cc ('k') | testing/android/native_test.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698