def main(argv): stdout = build_utils.CheckCallDie(['ant'] + argv[1:], suppress_output=True) stdout = stdout.decode("utf-8").strip().split('\n') for line in stdout: if line.strip() == 'BUILD SUCCESSFUL': break print(line)
def main(argv): parser = optparse.OptionParser() parser.add_option('--android-sdk-tools', help='Path to Android SDK tools.') parser.add_option('--apk-path', help='Path to .apk to install.') parser.add_option('--stamp', help='Path to touch on success.') options, _ = parser.parse_args() # TODO(cjhopman): Should this install to all devices/be configurable? install_cmd = [ os.path.join(options.android_sdk_tools, 'adb'), 'install', '-r', options.apk_path ] serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber() md5_stamp = '%s.%s.md5' % (options.apk_path, serial_number) md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[options.apk_path], command=install_cmd) if md5_checker.IsStale(): build_utils.CheckCallDie(install_cmd) md5_checker.Write() if options.stamp: build_utils.Touch(options.stamp)
def AlignApk(android_sdk_root, unaligned_path, final_path): align_cmd = [ os.path.join(android_sdk_root, 'tools', 'zipalign'), '-f', '4', # 4 bytes unaligned_path, final_path, ] build_utils.CheckCallDie(align_cmd)
def DoJavac(options): output_dir = options.output_dir src_dirs = build_utils.ParseGypList(options.src_dirs) java_files = build_utils.FindInDirectories(src_dirs, '*.java') if options.javac_includes: javac_includes = build_utils.ParseGypList(options.javac_includes) filtered_java_files = [] for f in java_files: for include in javac_includes: if fnmatch.fnmatch(f, include): filtered_java_files.append(f) break java_files = filtered_java_files # Compiling guava with certain orderings of input files causes a compiler # crash... Sorted order works, so use that. # See https://code.google.com/p/guava-libraries/issues/detail?id=950 java_files.sort() classpath = build_utils.ParseGypList(options.classpath) jar_inputs = [] for path in classpath: if os.path.exists(path + '.TOC'): jar_inputs.append(path + '.TOC') else: jar_inputs.append(path) javac_cmd = [ 'javac', '-g', '-source', '1.5', '-target', '1.5', '-classpath', ':'.join(classpath), '-d', output_dir, '-Xlint:unchecked', '-Xlint:deprecation', ] + java_files md5_stamp = '%s/javac.md5' % options.output_dir md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=java_files + jar_inputs, command=javac_cmd) if md5_checker.IsStale(): # Delete the classes directory. This ensures that all .class files in the # output are actually from the input .java files. For example, if a .java # file is deleted or an inner class is removed, the classes directory should # not contain the corresponding old .class file after running this action. build_utils.DeleteDirectory(output_dir) build_utils.MakeDirectory(output_dir) suppress_output = not options.chromium_code build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output) md5_checker.Write()
def AlignApk(zipalign_path, unaligned_path, final_path): align_cmd = [ zipalign_path, '-f', '4', # 4 bytes unaligned_path, final_path ] build_utils.CheckCallDie(align_cmd)
def Compile(): # Delete the classes directory. This ensures that all .class files in the # output are actually from the input .java files. For example, if a .java # file is deleted or an inner class is removed, the classes directory should # not contain the corresponding old .class file after running this action. build_utils.DeleteDirectory(output_dir) build_utils.MakeDirectory(output_dir) suppress_output = not options.chromium_code build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output)
def SignApk(keystore_path, unsigned_path, signed_path, alias, code): intermediate_path = unsigned_path + '.copy' shutil.copy(unsigned_path, intermediate_path) sign_cmd = [ 'jarsigner', '-sigalg', 'MD5withRSA', '-digestalg', 'SHA1', '-keystore', keystore_path, '-storepass', code, intermediate_path, alias ] build_utils.CheckCallDie(sign_cmd) shutil.move(intermediate_path, signed_path)
def CallJavap(classpath, classes): javap_cmd = [ 'javap', '-protected', # In reality both public & protected. # -verbose is required to get constant values (which can be inlined in # dependents). '-verbose', '-classpath', classpath ] + classes return build_utils.CheckCallDie(javap_cmd, suppress_output=True)
def DoDex(options, paths): dx_binary = os.path.join(options.android_sdk_root, 'platform-tools', 'dx') dex_cmd = [dx_binary, '--dex', '--output', options.dex_path] + paths record_path = '%s.md5.stamp' % options.dex_path md5_check.CallAndRecordIfStale( lambda: build_utils.CheckCallDie(dex_cmd, suppress_output=True), record_path=record_path, input_paths=paths, input_strings=dex_cmd) build_utils.Touch(options.dex_path)
def _RunInstrumentCommand(command, options, args, option_parser): """Instruments the classes/jar files using EMMA. Args: command: 'instrument_jar' or 'instrument_classes'. This distinguishes whether we copy the output from the created lib/ directory, or classes/ directory. options: optparse options dictionary. args: List of extra args from optparse. option_parser: optparse.OptionParser object. Returns: An exit code. """ if not (options.input_path and options.output_path and options.coverage_file and options.sources_file and options.sources and options.src_root and options.emma_jar): option_parser.error('All arguments are required.') coverage_file = os.path.join(os.path.dirname(options.output_path), options.coverage_file) sources_file = os.path.join(os.path.dirname(options.output_path), options.sources_file) temp_dir = tempfile.mkdtemp() try: cmd = ['java', '-cp', options.emma_jar, 'emma', 'instr', '-ip', options.input_path, '-ix', options.filter_string, '-d', temp_dir, '-out', coverage_file, '-m', 'fullcopy'] build_utils.CheckCallDie(cmd, suppress_output=True) if command == 'instrument_jar': for jar in os.listdir(os.path.join(temp_dir, 'lib')): shutil.copy(os.path.join(temp_dir, 'lib', jar), options.output_path) else: # 'instrument_classes' if os.path.isdir(options.output_path): shutil.rmtree(options.output_path, ignore_errors=True) shutil.copytree(os.path.join(temp_dir, 'classes'), options.output_path) finally: shutil.rmtree(temp_dir) _CreateSourcesFile(options.sources, sources_file, options.src_root) if options.stamp: build_utils.Touch(options.stamp) return 0
def main(): options = ParseArgs() android_jar = os.path.join(options.android_sdk, 'android.jar') aapt = os.path.join(options.android_sdk_tools, 'aapt') build_utils.MakeDirectory(options.R_dir) # Generate R.java. This R.java contains non-final constants and is used only # while compiling the library jar (e.g. chromium_content.jar). When building # an apk, a new R.java file with the correct resource -> ID mappings will be # generated by merging the resources from all libraries and the main apk # project. package_command = [ aapt, 'package', '-m', '-M', options.android_manifest, '--auto-add-overlay', '-I', android_jar, '--output-text-symbols', options.R_dir, '-J', options.R_dir ] res_dirs = shlex.split(options.res_dirs) for res_dir in res_dirs: package_command += ['-S', res_dir] if options.non_constant_id: package_command.append('--non-constant-id') if options.custom_package: package_command += ['--custom-package', options.custom_package] build_utils.CheckCallDie(package_command) # Crunch image resources. This shrinks png files and is necessary for 9-patch # images to display correctly. build_utils.MakeDirectory(options.crunch_output_dir) aapt_cmd = [ aapt, 'crunch', '-S', options.crunch_input_dir, '-C', options.crunch_output_dir ] build_utils.CheckCallDie(aapt_cmd, suppress_output=True) MoveImagesToNonMdpiFolders(options.crunch_output_dir) if options.stamp: build_utils.Touch(options.stamp)
def DoDex(options, paths): dx_binary = os.path.join(options.android_sdk_root, 'platform-tools', 'dx') dex_cmd = [dx_binary, '--dex', '--output', options.dex_path] + paths md5_stamp = '%s.md5' % options.dex_path md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=paths, command=dex_cmd) if md5_checker.IsStale(): build_utils.CheckCallDie(dex_cmd, suppress_output=True) else: build_utils.Touch(options.dex_path) md5_checker.Write()
def DoProguard(options): injars = options.input_path outjars = options.output_path classpath = build_utils.ParseGypList(options.classpath) classpath = list(set(classpath)) libraryjars = ':'.join(classpath) # proguard does its own dependency checking, which can be avoided by deleting # the output. if os.path.exists(options.output_path): os.remove(options.output_path) proguard_cmd = [ options.proguard_path, '-injars', injars, '-outjars', outjars, '-libraryjars', libraryjars, '@' + options.proguard_config ] build_utils.CheckCallDie(proguard_cmd)
def DoDex(options, paths): dx_binary = '' for dx_str in AddExeExtensions('dx'): dx_binary = Find(dx_str, options.android_sdk_root) if dx_binary: break dex_cmd = [dx_binary, '--dex', '--output', options.dex_path] + paths record_path = '%s.md5.stamp' % options.dex_path md5_check.CallAndRecordIfStale( lambda: build_utils.CheckCallDie(dex_cmd, suppress_output=True), record_path=record_path, input_paths=paths, input_strings=dex_cmd) build_utils.Touch(options.dex_path)
def DoGcc(options): build_utils.MakeDirectory(os.path.dirname(options.output)) gcc_cmd = [ 'gcc', # invoke host gcc. '-E', # stop after preprocessing. '-D', 'ANDROID', # Specify ANDROID define for pre-processor. '-x', 'c-header', # treat sources as C header files '-P', # disable line markers, i.e. '#line 309' '-I', options.include_path, '-o', options.output, options.template ] build_utils.CheckCallDie(gcc_cmd)
def DoJar(options): class_files = build_utils.FindInDirectory(options.classes_dir, '*.class') for exclude in build_utils.ParseGypList(options.excluded_classes): class_files = filter( lambda f: not fnmatch.fnmatch(f, exclude), class_files) jar_path = os.path.abspath(options.jar_path) # The paths of the files in the jar will be the same as they are passed in to # the command. Because of this, the command should be run in # options.classes_dir so the .class file paths in the jar are correct. jar_cwd = options.classes_dir class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files] jar_cmd = ['jar', 'cf0', jar_path] + class_files_rel record_path = '%s.md5.stamp' % options.jar_path md5_check.CallAndRecordIfStale( lambda: build_utils.CheckCallDie(jar_cmd, cwd=jar_cwd), record_path=record_path, input_paths=class_files, input_strings=jar_cmd) build_utils.Touch(options.jar_path)
def DoJar(options): class_files = build_utils.FindInDirectory(options.classes_dir, '*.class') for exclude in build_utils.ParseGypList(options.excluded_classes): class_files = filter( lambda f: not fnmatch.fnmatch(f, exclude), class_files) jar_path = os.path.abspath(options.jar_path) # The paths of the files in the jar will be the same as they are passed in to # the command. Because of this, the command should be run in # options.classes_dir so the .class file paths in the jar are correct. jar_cwd = options.classes_dir class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files] jar_cmd = ['jar', 'cf0', jar_path] + class_files_rel md5_stamp = '%s.md5' % options.jar_path md5_checker = md5_check.Md5Checker( stamp=md5_stamp, inputs=class_files, command=jar_cmd) if md5_checker.IsStale(): build_utils.CheckCallDie(jar_cmd, cwd=jar_cwd) else: build_utils.Touch(options.jar_path) md5_checker.Write()
def CallReadElf(library_or_executable): readelf_cmd = [_options.readelf, '-d', library_or_executable] return build_utils.CheckCallDie(readelf_cmd, suppress_output=True)
def CallReadElf(library_name): readelf_cmd = [_options.readelf, '-d', FullLibraryPath(library_name)] return build_utils.CheckCallDie(readelf_cmd, suppress_output=True)
def Install(): build_utils.CheckCallDie(install_cmd) RecordInstallMetadata(apk_package, metadata_path) build_utils.Touch(options.install_record)
def StripLibrary(android_strip, android_strip_args, library_path, output_path): if build_utils.IsTimeStale(output_path, [library_path]): strip_cmd = ([android_strip] + android_strip_args + ['-o', output_path, library_path]) build_utils.CheckCallDie(strip_cmd)