def DoPush(options): libraries = build_utils.ReadJson(options.libraries_json) device = build_device.GetBuildDeviceFromPath( options.build_device_configuration) if not device: return serial_number = device.GetSerialNumber() # A list so that it is modifiable in Push below. needs_directory = [True] for lib in libraries: device_path = os.path.join(options.device_dir, lib) host_path = os.path.join(options.libraries_dir, lib) def Push(): if needs_directory: device.RunShellCommand('mkdir -p ' + options.device_dir) needs_directory[:] = [] # = False device.PushChangedFiles(host_path, device_path) record_path = '%s.%s.push.md5.stamp' % (host_path, serial_number) md5_check.CallAndRecordIfStale(Push, record_path=record_path, input_paths=[host_path], input_strings=[device_path])
def main(): parser = optparse.OptionParser() parser.add_option('--android-sdk-tools', help='Android sdk build tools directory.') parser.add_option('--dex-path', help='Dex output path.') parser.add_option('--configuration-name', help='The build CONFIGURATION_NAME.') parser.add_option('--proguard-enabled', help='"true" if proguard is enabled.') parser.add_option('--proguard-enabled-input-path', help=('Path to dex in Release mode when proguard ' 'is enabled.')) parser.add_option('--no-locals', help='Exclude locals list from the dex file.') parser.add_option( '--excluded-paths-file', help='Path to a file containing a list of paths to exclude ' 'from the dex file.') options, paths = parser.parse_args() if (options.proguard_enabled == 'true' and options.configuration_name == 'Release'): paths = [options.proguard_enabled_input_path] if options.excluded_paths_file: exclude_paths = build_utils.ReadJson(options.excluded_paths_file) paths = [p for p in paths if not p in exclude_paths] DoDex(options, paths)
def build(self): if self._cmd: return self._cmd assert self._injars is not None assert self._outjar is not None assert self._configs is not None cmd = [ 'java', '-jar', self._proguard_jar_path, '-forceprocessing', ] if self._tested_apk_info_path: tested_apk_info = build_utils.ReadJson(self._tested_apk_info_path) self._configs += tested_apk_info['configs'] self._injars = [ p for p in self._injars if not p in tested_apk_info['inputs']] if not self._libraries: self._libraries = [] self._libraries += tested_apk_info['inputs'] self._mapping = tested_apk_info['mapping'] cmd += [ '-dontobfuscate', '-dontoptimize', '-dontshrink', '-dontskipnonpubliclibraryclassmembers', ] if self._mapping: cmd += [ '-applymapping', self._mapping, ] if self._libraries: cmd += [ '-libraryjars', ':'.join(self._libraries), ] cmd += [ '-injars', ':'.join(self._injars) ] for config_file in self._configs: cmd += ['-include', config_file] # The output jar must be specified after inputs. cmd += [ '-outjars', self._outjar, '-dump', self._outjar + '.dump', '-printseeds', self._outjar + '.seeds', '-printusage', self._outjar + '.usage', '-printmapping', self._outjar + '.mapping', ] if self._verbose: cmd.append('-verbose') self._cmd = cmd return self._cmd
def build(self): if self._cmd: return self._cmd assert self._injars is not None assert self._outjar is not None assert self._configs is not None cmd = [ 'java', '-jar', self._proguard_jar_path, '-forceprocessing', ] if self._tested_apk_info_path: tested_apk_info = build_utils.ReadJson(self._tested_apk_info_path) self._configs += tested_apk_info['configs'] for path in self._config_exclusions: self._configs.remove(path) if self._mapping: cmd += [ '-applymapping', self._mapping, ] if self._libraries: cmd += [ '-libraryjars', ':'.join(self._libraries), ] for optimization in self._disabled_optimizations: cmd += ['-optimizations', '!' + optimization] cmd += ['-injars', ':'.join(self._injars)] for config_file in self._configs: cmd += ['-include', config_file] # The output jar must be specified after inputs. cmd += [ '-outjars', self._outjar, '-printseeds', self._outjar + '.seeds', '-printusage', self._outjar + '.usage', '-printmapping', self._outjar + '.mapping', ] if self._verbose: cmd.append('-verbose') self._cmd = cmd return self._cmd
def HasInstallMetadataChanged(device, apk_package, metadata_path): """Checks if the metadata on the device for apk_package has changed.""" if not os.path.exists(metadata_path): return True try: expected_metadata = build_utils.ReadJson(metadata_path) except ValueError: # File is not json encoded. return True return expected_metadata != device.GetInstallMetadata(apk_package)
def CreateSymlinkScript(options): libraries = build_utils.ReadJson(options.libraries_json) link_cmd = ('rm $APK_LIBRARIES_DIR/%(lib_basename)s > /dev/null 2>&1 \n' 'ln -s $STRIPPED_LIBRARIES_DIR/%(lib_basename)s ' '$APK_LIBRARIES_DIR/%(lib_basename)s \n') script = '#!/bin/sh \n' for lib in libraries: script += link_cmd % {'lib_basename': lib} with open(options.script_host_path, 'w') as scriptfile: scriptfile.write(script)
def CreateLinks(options): libraries = build_utils.ReadJson(options.libraries_json) apk_package = apk_helper.GetPackageName(options.apk) adb = android_commands.AndroidCommands() serial_number = adb.Adb().GetSerialNumber() for lib in libraries: host_path = os.path.join(options.libraries_dir, lib) md5_stamp = '%s.%s.link.md5' % (host_path, serial_number) md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[host_path]) if md5_checker.IsStale(): link = '/data/data/' + apk_package + '/lib/' + lib target = options.target_dir + '/' + lib RunLinkCommand(adb, target, link) md5_checker.Write()
def main(): args = build_utils.ExpandFileArgs(sys.argv[1:]) parser = optparse.OptionParser() build_utils.AddDepfileOption(parser) parser.add_option('--android-sdk-tools', help='Android sdk build tools directory.') parser.add_option('--dex-path', help='Dex output path.') parser.add_option('--configuration-name', help='The build CONFIGURATION_NAME.') parser.add_option('--proguard-enabled', help='"true" if proguard is enabled.') parser.add_option('--proguard-enabled-input-path', help=('Path to dex in Release mode when proguard ' 'is enabled.')) parser.add_option('--no-locals', help='Exclude locals list from the dex file.') parser.add_option('--inputs', help='A list of additional input paths.') parser.add_option('--excluded-paths-file', help='Path to a file containing a list of paths to exclude ' 'from the dex file.') options, paths = parser.parse_args(args) required_options = ('android_sdk_tools',) build_utils.CheckOptions(options, parser, required=required_options) if (options.proguard_enabled == 'true' and options.configuration_name == 'Release'): paths = [options.proguard_enabled_input_path] if options.excluded_paths_file: exclude_paths = build_utils.ReadJson(options.excluded_paths_file) paths = [p for p in paths if not p in exclude_paths] if options.inputs: paths += build_utils.ParseGypList(options.inputs) DoDex(options, paths) if options.depfile: build_utils.WriteDepfile( options.depfile, paths + build_utils.GetPythonDependencies())
def DoPush(options): libraries = build_utils.ReadJson(options.libraries_json) adb = android_commands.AndroidCommands() serial_number = adb.Adb().GetSerialNumber() needs_directory = True for lib in libraries: device_path = os.path.join(options.device_dir, lib) host_path = os.path.join(options.libraries_dir, lib) md5_stamp = '%s.%s.push.md5' % (host_path, serial_number) md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[host_path]) if md5_checker.IsStale(): if needs_directory: adb.RunShellCommand('mkdir ' + options.device_dir) needs_directory = False adb.PushIfNeeded(host_path, device_path) md5_checker.Write()
def DoProguard(options): proguard = proguard_util.ProguardCmdBuilder(options.proguard_jar_path) proguard.outjar(options.obfuscated_jar_path) library_classpath = [options.android_sdk_jar] input_jars = build_utils.ParseGypList(options.input_jars_paths) exclude_paths = [] configs = build_utils.ParseGypList(options.proguard_configs) if options.tested_apk_obfuscated_jar_path: # configs should only contain the process_resources.py generated config. assert len(configs) == 1, ( 'test apks should not have custom proguard configs: ' + str(configs)) tested_jar_info = build_utils.ReadJson( options.tested_apk_obfuscated_jar_path + '.info') exclude_paths = tested_jar_info['inputs'] configs = tested_jar_info['configs'] proguard.is_test(True) proguard.mapping(options.tested_apk_obfuscated_jar_path + '.mapping') library_classpath.append(options.tested_apk_obfuscated_jar_path) proguard.libraryjars(library_classpath) proguard_injars = [p for p in input_jars if p not in exclude_paths] proguard.injars(proguard_injars) proguard.configs(configs) proguard.CheckOutput() this_info = { 'inputs': proguard_injars, 'configs': configs } build_utils.WriteJson( this_info, options.obfuscated_jar_path + '.info')
def ReadConfigurations(path): return build_utils.ReadJson(path)
def GetDepConfig(path): if not path in dep_config_cache: dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] return dep_config_cache[path]
def BuildConfig(self): """Reads and returns the project's .build_config JSON.""" if not self._build_config: path = os.path.join('gen', self.GradleSubdir() + '.build_config') self._build_config = build_utils.ReadJson(_RebasePath(path)) return self._build_config
def main(argv): options, _ = ParseArgs(argv) library_classpath = [options.android_sdk_jar] input_jars = build_utils.ParseGypList(options.input_jars_paths) dependency_class_filters = [ '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class' ] if options.testapp: build_utils.MergeZips(options.test_jar_path, input_jars, dependency_class_filters) if options.configuration_name == 'Release' and options.proguard_enabled: proguard_cmd = [ 'java', '-jar', options.proguard_jar_path, '-forceprocessing', '-libraryjars', ':'.join(library_classpath), '-dump', options.obfuscated_jar_path + '.dump', '-printseeds', options.obfuscated_jar_path + '.seeds', '-printusage', options.obfuscated_jar_path + '.usage', '-printmapping', options.obfuscated_jar_path + '.mapping', ] exclude_paths = [] configs = build_utils.ParseGypList(options.proguard_configs) if (options.tested_apk_obfuscated_jar_path and options.tested_apk_obfuscated_jar_path != '/'): # configs should only contain the process_resources.py generated config. assert len(configs) == 1, ( 'test apks should not have custom proguard configs: ' + str(configs)) tested_jar_info = build_utils.ReadJson( options.tested_apk_obfuscated_jar_path + '.info') exclude_paths = tested_jar_info['inputs'] configs = tested_jar_info['configs'] proguard_cmd += [ '-dontobfuscate', '-dontoptimize', '-dontshrink', '-dontskipnonpubliclibraryclassmembers', '-libraryjars', options.tested_apk_obfuscated_jar_path, '-applymapping', options.tested_apk_obfuscated_jar_path + '.mapping', ] proguard_injars = [p for p in input_jars if p not in exclude_paths] proguard_cmd += ['-injars', ':'.join(proguard_injars)] for config_file in configs: proguard_cmd += ['-include', config_file] # The output jar must be specified after inputs. proguard_cmd += ['-outjars', options.obfuscated_jar_path] build_utils.CheckOutput(proguard_cmd) this_info = {'inputs': proguard_injars, 'configs': configs} build_utils.WriteJson(this_info, options.obfuscated_jar_path + '.info') else: output_files = [ options.obfuscated_jar_path, options.obfuscated_jar_path + '.info', options.obfuscated_jar_path + '.dump', options.obfuscated_jar_path + '.seeds', options.obfuscated_jar_path + '.usage', options.obfuscated_jar_path + '.mapping' ] for f in output_files: if os.path.exists(f): os.remove(f) build_utils.Touch(f) if options.stamp: build_utils.Touch(options.stamp)
def main(argv): parser = optparse.OptionParser() build_utils.AddDepfileOption(parser) parser.add_option('--build-config', help='Path to build_config output.') parser.add_option('--type', help='Type of this target (e.g. android_library).') parser.add_option( '--possible-deps-configs', help='List of paths for dependency\'s build_config files. Some ' 'dependencies may not write build_config files. Missing build_config ' 'files are handled differently based on the type of this target.') # android_resources options parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') parser.add_option('--resources-zip', help='Path to target\'s resources zip.') parser.add_option('--r-text', help='Path to target\'s R.txt file.') parser.add_option('--package-name', help='Java package name for these resources.') parser.add_option('--android-manifest', help='Path to android manifest.') # android_assets options parser.add_option('--asset-sources', help='List of asset sources.') parser.add_option('--asset-renaming-sources', help='List of asset sources with custom destinations.') parser.add_option('--asset-renaming-destinations', help='List of asset custom destinations.') parser.add_option('--disable-asset-compression', action='store_true', help='Whether to disable asset compression.') # java library options parser.add_option('--jar-path', help='Path to target\'s jar output.') parser.add_option( '--supports-android', action='store_true', help='Whether this library supports running on the Android platform.') parser.add_option( '--requires-android', action='store_true', help='Whether this library requires running on the Android platform.') parser.add_option( '--bypass-platform-checks', action='store_true', help='Bypass checks for support/require Android platform.') # android library options parser.add_option('--dex-path', help='Path to target\'s dex output.') # native library options parser.add_option('--native-libs', help='List of top-level native libs.') parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') # apk options parser.add_option('--apk-path', help='Path to the target\'s apk output.') parser.add_option( '--tested-apk-config', help= 'Path to the build config of the tested apk (for an instrumentation ' 'test apk).') parser.add_option('--proguard-enabled', action='store_true', help='Whether proguard is enabled for this apk.') parser.add_option('--proguard-info', help='Path to the proguard .info output for this apk.') options, args = parser.parse_args(argv) if args: parser.error('No positional arguments should be given.') required_options_map = { 'java_binary': ['build_config', 'jar_path'], 'java_library': ['build_config', 'jar_path'], 'android_assets': ['build_config'], 'android_resources': ['build_config', 'resources_zip'], 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], 'deps_dex': ['build_config', 'dex_path'], 'resource_rewriter': ['build_config'] } required_options = required_options_map.get(options.type) if not required_options: raise Exception('Unknown type: <%s>' % options.type) if options.native_libs: required_options.append('readelf_path') build_utils.CheckOptions(options, parser, required_options) if options.type == 'java_library': if options.supports_android and not options.dex_path: raise Exception( 'java_library that supports Android requires a dex path.') if options.requires_android and not options.supports_android: raise Exception( '--supports-android is required when using --requires-android') possible_deps_config_paths = build_utils.ParseGypList( options.possible_deps_configs) allow_unknown_deps = (options.type in ('android_apk', 'android_assets', 'android_resources')) unknown_deps = [ c for c in possible_deps_config_paths if not os.path.exists(c) ] if unknown_deps and not allow_unknown_deps: raise Exception('Unknown deps: ' + str(unknown_deps)) direct_deps_config_paths = [ c for c in possible_deps_config_paths if not c in unknown_deps ] direct_deps_config_paths = _FilterUnwantedDepsPaths( direct_deps_config_paths, options.type) deps = Deps(direct_deps_config_paths) direct_library_deps = deps.Direct('java_library') all_library_deps = deps.All('java_library') direct_resources_deps = deps.Direct('android_resources') all_resources_deps = deps.All('android_resources') # Resources should be ordered with the highest-level dependency first so that # overrides are done correctly. all_resources_deps.reverse() if options.type == 'android_apk' and options.tested_apk_config: tested_apk_deps = Deps([options.tested_apk_config]) tested_apk_resources_deps = tested_apk_deps.All('android_resources') all_resources_deps = [ d for d in all_resources_deps if not d in tested_apk_resources_deps ] # Initialize some common config. config = { 'deps_info': { 'name': os.path.basename(options.build_config), 'path': options.build_config, 'type': options.type, 'deps_configs': direct_deps_config_paths } } deps_info = config['deps_info'] if (options.type in ('java_binary', 'java_library') and not options.bypass_platform_checks): deps_info['requires_android'] = options.requires_android deps_info['supports_android'] = options.supports_android deps_require_android = ( all_resources_deps + [d['name'] for d in all_library_deps if d['requires_android']]) deps_not_support_android = ([ d['name'] for d in all_library_deps if not d['supports_android'] ]) if deps_require_android and not options.requires_android: raise Exception( 'Some deps require building for the Android platform: ' + str(deps_require_android)) if deps_not_support_android and options.supports_android: raise Exception('Not all deps support the Android platform: ' + str(deps_not_support_android)) if options.type in ('java_binary', 'java_library', 'android_apk'): javac_classpath = [c['jar_path'] for c in direct_library_deps] java_full_classpath = [c['jar_path'] for c in all_library_deps] deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] deps_info['jar_path'] = options.jar_path if options.type == 'android_apk' or options.supports_android: deps_info['dex_path'] = options.dex_path if options.type == 'android_apk': deps_info['apk_path'] = options.apk_path config['javac'] = { 'classpath': javac_classpath, } config['java'] = {'full_classpath': java_full_classpath} if options.type in ('java_binary', 'java_library'): # Only resources might have srcjars (normal srcjar targets are listed in # srcjar_deps). A resource's srcjar contains the R.java file for those # resources, and (like Android's default build system) we allow a library to # refer to the resources in any of its dependents. config['javac']['srcjars'] = [ c['srcjar'] for c in direct_resources_deps if 'srcjar' in c ] if options.type == 'android_apk': # Apks will get their resources srcjar explicitly passed to the java step. config['javac']['srcjars'] = [] if options.type == 'android_assets': all_asset_sources = [] if options.asset_renaming_sources: all_asset_sources.extend( build_utils.ParseGypList(options.asset_renaming_sources)) if options.asset_sources: all_asset_sources.extend( build_utils.ParseGypList(options.asset_sources)) deps_info['assets'] = {'sources': all_asset_sources} if options.asset_renaming_destinations: deps_info['assets']['outputs'] = (build_utils.ParseGypList( options.asset_renaming_destinations)) if options.disable_asset_compression: deps_info['assets']['disable_compression'] = True if options.type == 'android_resources': deps_info['resources_zip'] = options.resources_zip if options.srcjar: deps_info['srcjar'] = options.srcjar if options.android_manifest: manifest = AndroidManifest(options.android_manifest) deps_info['package_name'] = manifest.GetPackageName() if options.package_name: deps_info['package_name'] = options.package_name if options.r_text: deps_info['r_text'] = options.r_text if options.type in ('android_resources', 'android_apk', 'resource_rewriter'): config['resources'] = {} config['resources']['dependency_zips'] = [ c['resources_zip'] for c in all_resources_deps ] config['resources']['extra_package_names'] = [] config['resources']['extra_r_text_files'] = [] if options.type == 'android_apk' or options.type == 'resource_rewriter': config['resources']['extra_package_names'] = [ c['package_name'] for c in all_resources_deps if 'package_name' in c ] config['resources']['extra_r_text_files'] = [ c['r_text'] for c in all_resources_deps if 'r_text' in c ] if options.type in ['android_apk', 'deps_dex']: deps_dex_files = [c['dex_path'] for c in all_library_deps] proguard_enabled = options.proguard_enabled if options.type == 'android_apk': deps_info['proguard_enabled'] = proguard_enabled if proguard_enabled: deps_info['proguard_info'] = options.proguard_info config['proguard'] = {} proguard_config = config['proguard'] proguard_config['input_paths'] = [options.jar_path ] + java_full_classpath proguard_config['tested_apk_info'] = '' # An instrumentation test apk should exclude the dex files that are in the apk # under test. if options.type == 'android_apk' and options.tested_apk_config: tested_apk_deps = Deps([options.tested_apk_config]) tested_apk_library_deps = tested_apk_deps.All('java_library') tested_apk_deps_dex_files = [ c['dex_path'] for c in tested_apk_library_deps ] deps_dex_files = [ p for p in deps_dex_files if not p in tested_apk_deps_dex_files ] tested_apk_config = GetDepConfig(options.tested_apk_config) expected_tested_package = tested_apk_config['package_name'] AndroidManifest(options.android_manifest).CheckInstrumentation( expected_tested_package) if tested_apk_config['proguard_enabled']: assert proguard_enabled, ( 'proguard must be enabled for instrumentation' ' apks if it\'s enabled for the tested apk') proguard_config['tested_apk_info'] = tested_apk_config[ 'proguard_info'] deps_info['tested_apk_path'] = tested_apk_config['apk_path'] # Dependencies for the final dex file of an apk or a 'deps_dex'. if options.type in ['android_apk', 'deps_dex']: config['final_dex'] = {} dex_config = config['final_dex'] dex_config['dependency_dex_files'] = deps_dex_files if options.type == 'android_apk': config['dist_jar'] = { 'dependency_jars': [c['jar_path'] for c in all_library_deps] } manifest = AndroidManifest(options.android_manifest) deps_info['package_name'] = manifest.GetPackageName() if not options.tested_apk_config and manifest.GetInstrumentation(): # This must then have instrumentation only for itself. manifest.CheckInstrumentation(manifest.GetPackageName()) library_paths = [] java_libraries_list_holder = [None] libraries = build_utils.ParseGypList(options.native_libs or '[]') if libraries: def recompute_ordered_libraries(): libraries_dir = os.path.dirname(libraries[0]) write_ordered_libraries.SetReadelfPath(options.readelf_path) write_ordered_libraries.SetLibraryDirs([libraries_dir]) all_deps = ( write_ordered_libraries. GetSortedTransitiveDependenciesForBinaries(libraries)) # Create a java literal array with the "base" library names: # e.g. libfoo.so -> foo java_libraries_list_holder[0] = ( '{%s}' % ','.join(['"%s"' % s[3:-3] for s in all_deps])) library_paths.extend( write_ordered_libraries.FullLibraryPath(x) for x in all_deps) # This step takes about 600ms on a z620 for chrome_apk, so it's worth # caching. md5_check.CallAndRecordIfStale(recompute_ordered_libraries, record_path=options.build_config + '.nativelibs.md5.stamp', input_paths=libraries, output_paths=[options.build_config]) if not library_paths: prev_config = build_utils.ReadJson(options.build_config) java_libraries_list_holder[0] = ( prev_config['native']['java_libraries_list']) library_paths.extend(prev_config['native']['libraries']) config['native'] = { 'libraries': library_paths, 'java_libraries_list': java_libraries_list_holder[0], } config['assets'], config['uncompressed_assets'] = (_MergeAssets( deps.All('android_assets'))) build_utils.WriteJson(config, options.build_config, only_if_changed=True) if options.depfile: build_utils.WriteDepfile( options.depfile, deps.AllConfigPaths() + build_utils.GetPythonDependencies())
def main(): parser = argparse.ArgumentParser() parser.add_argument('--output-directory', help='Path to the root build directory.') parser.add_argument('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level') parser.add_argument('--target', dest='targets', action='append', help='GN target to generate project for. ' 'May be repeated.') parser.add_argument('--project-dir', help='Root of the output project.', default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) parser.add_argument('--all', action='store_true', help='Generate all java targets (slows down IDE)') parser.add_argument('--use-gradle-process-resources', action='store_true', help='Have gradle generate R.java rather than ninja') args = parser.parse_args() if args.output_directory: constants.SetOutputDirectory(args.output_directory) constants.CheckOutputDirectory() output_dir = constants.GetOutDirectory() devil_chromium.Initialize(output_directory=output_dir) run_tests_helper.SetLogLevel(args.verbose_count) gradle_output_dir = os.path.abspath( args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) logging.warning('Creating project at: %s', gradle_output_dir) if args.all: # Run GN gen if necessary (faster than running "gn gen" in the no-op case). _RunNinja(output_dir, ['build.ninja']) # Query ninja for all __build_config targets. targets = _QueryForAllGnTargets(output_dir) else: targets = args.targets or _DEFAULT_TARGETS # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs # for our instrumentation tests. targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] main_entries = [_ProjectEntry(t) for t in targets] logging.warning('Building .build_config files...') _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) # There are many unused libraries, so restrict to those that are actually used # when using --all. if args.all: main_entries = [e for e in main_entries if e.GetType() == 'android_apk'] all_entries = _FindAllProjectEntries(main_entries) logging.info('Found %d dependent build_config targets.', len(all_entries)) logging.warning('Writing .gradle files...') jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) config_json = build_utils.ReadJson( os.path.join(output_dir, 'gradle', 'config.json')) project_entries = [] srcjar_tuples = [] for entry in all_entries: if entry.GetType() not in ('android_apk', 'java_library'): continue entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) build_config = entry.BuildConfig() srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', [])) if not args.use_gradle_process_resources: srcjars += _RebasePath(build_config['javac']['srcjars']) java_sources_file = build_config['gradle'].get('java_sources_file') if java_sources_file: java_sources_file = _RebasePath(java_sources_file) java_dirs = _CreateJavaSourceDir(output_dir, entry_output_dir, java_sources_file) if srcjars: java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) data = _GenerateGradleFile(build_config, config_json, java_dirs, relativize, args.use_gradle_process_resources, jinja_processor) if data: project_entries.append(entry) srcjar_tuples.extend( (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) for s in srcjars) _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data) _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'), _GenerateRootGradle(jinja_processor)) _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'), _GenerateSettingsGradle(project_entries)) sdk_path = _RebasePath(config_json['android_sdk_root']) _WriteFile(os.path.join(gradle_output_dir, 'local.properties'), _GenerateLocalProperties(sdk_path)) if srcjar_tuples: logging.warning('Building all .srcjar files...') targets = _RebasePath([s[0] for s in srcjar_tuples], output_dir) _RunNinja(output_dir, targets) _ExtractSrcjars(gradle_output_dir, srcjar_tuples) logging.warning('Project created! (%d subprojects)', len(project_entries)) logging.warning('Generated projects work best with Android Studio 2.2') logging.warning('For more tips: https://chromium.googlesource.com/chromium' '/src.git/+/master/docs/android_studio.md')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--output-directory', help='Path to the root build directory.') parser.add_argument('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level') parser.add_argument('--target', help='GN target to generate project for.', default='//chrome/android:chrome_public_apk') parser.add_argument('--project-dir', help='Root of the output project.', default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) parser.add_argument('--use-gradle-process-resources', action='store_true', help='Have gradle generate R.java rather than ninja') args = parser.parse_args() if args.output_directory: constants.SetOutputDirectory(args.output_directory) constants.CheckOutputDirectory() output_dir = constants.GetOutDirectory() devil_chromium.Initialize(output_directory=output_dir) run_tests_helper.SetLogLevel(args.verbose_count) gradle_output_dir = os.path.abspath( args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) logging.warning('Creating project at: %s', gradle_output_dir) main_entry = _ProjectEntry(args.target) logging.warning('Building .build_config files...') _RunNinja(output_dir, [main_entry.NinjaBuildConfigTarget()]) all_entries = _FindAllProjectEntries(main_entry) logging.info('Found %d dependent build_config targets.', len(all_entries)) config_json = build_utils.ReadJson( os.path.join(output_dir, 'gradle', 'config.json')) project_entries = [] srcjar_tuples = [] for entry in all_entries: build_config = entry.BuildConfig() if build_config['deps_info']['type'] not in ('android_apk', 'java_library'): continue entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) srcjars = _RebasePath(build_config['gradle'].get( 'bundled_srcjars', [])) if not args.use_gradle_process_resources: srcjars += _RebasePath(build_config['javac']['srcjars']) java_sources_file = build_config['gradle'].get('java_sources_file') if java_sources_file: java_sources_file = _RebasePath(java_sources_file) java_dirs = _CreateJavaSourceDir(entry_output_dir, java_sources_file) if srcjars: java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) data = _GenerateGradleFile(build_config, config_json, java_dirs, relativize, args.use_gradle_process_resources) if data: project_entries.append(entry) srcjar_tuples.extend( (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) for s in srcjars) _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data) _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'), _GenerateRootGradle()) _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'), _GenerateSettingsGradle(project_entries)) sdk_path = _RebasePath(config_json['android_sdk_root']) _WriteFile(os.path.join(gradle_output_dir, 'local.properties'), _GenerateLocalProperties(sdk_path)) if srcjar_tuples: logging.warning('Building all .srcjar files...') targets = _RebasePath([s[0] for s in srcjar_tuples], output_dir) _RunNinja(output_dir, targets) _ExtractSrcjars(gradle_output_dir, srcjar_tuples) logging.warning('Project created successfully!')