def generate_ninjas(): needs_clobbering, cache_to_save = _set_up_generate_ninja() ninja_list, independent_ninja_cache = _generate_independent_ninjas( needs_clobbering) cache_to_save.extend(independent_ninja_cache) ninja_list.extend( _generate_shared_lib_depending_ninjas(ninja_list)) ninja_list.extend(_generate_dependent_ninjas(ninja_list)) top_level_ninja = _generate_top_level_ninja(ninja_list) ninja_list.append(top_level_ninja) # Run verification before emitting to files. _verify_ninja_generator_list(ninja_list) # Emit each ninja script to a file. timer = build_common.SimpleTimer() timer.start('Emitting ninja scripts', OPTIONS.verbose()) for ninja in ninja_list: ninja.emit() top_level_ninja.emit_depfile() top_level_ninja.cleanup_out_directories(ninja_list) timer.done() if OPTIONS.enable_config_cache(): for cache_object, cache_path in cache_to_save: cache_object.save_to_file(cache_path)
def _set_up_generate_ninja(): # Create generated_ninja directory if necessary. ninja_dir = build_common.get_generated_ninja_dir() if not os.path.exists(ninja_dir): os.makedirs(ninja_dir) # Set up default resource path. framework_resources_base_path = ( build_common.get_build_path_for_apk('framework-res', subpath='R')) ninja_generator.JavaNinjaGenerator.add_default_resource_include( os.path.join(framework_resources_base_path, 'framework-res.apk')) # Set up global filter for makefile to ninja translator. make_to_ninja.MakefileNinjaTranslator.add_global_filter( _filter_all_make_to_ninja) dependency_inspection.start_inspection() dependency_inspection.add_files(*_get_build_system_dependencies()) make_to_ninja.prepare_make_to_ninja() depended_files = dependency_inspection.get_files() depended_listings = dependency_inspection.get_listings() dependency_inspection.stop_inspection() cache_to_save = [] needs_clobbering = True if OPTIONS.enable_config_cache(): needs_clobbering = False cache_path = _get_global_deps_file_path() global_deps = _load_global_deps_from_file(cache_path) if global_deps is None: needs_clobbering = True global_deps = CacheDependency() else: if not global_deps.check_freshness(): needs_clobbering = True global_deps.refresh(depended_files, depended_listings) cache_to_save.append((global_deps, cache_path)) _config_loader.load() return needs_clobbering, cache_to_save
def _generate_independent_ninjas(needs_clobbering): timer = build_common.SimpleTimer() # Invoke an unordered set of ninja-generators distributed across config # modules by name, and if that generator is marked for it. timer.start('Generating independent generate_ninjas', True) generator_list = list(_list_ninja_generators( _config_loader, 'generate_ninjas')) if OPTIONS.run_tests(): generator_list.extend(_list_ninja_generators( _config_loader, 'generate_test_ninjas')) task_list = [] cached_result_list = [] cache_miss = {} for config_context, generator in generator_list: cache_path = _get_cache_file_path(config_context.config_name, config_context.entry_point) config_cache = None if OPTIONS.enable_config_cache() and not needs_clobbering: config_cache = _load_config_cache_from_file(cache_path) if config_cache is not None and config_cache.check_cache_freshness(): cached_result = config_cache.to_config_result() if cached_result is not None: cached_result_list.append(cached_result) continue task_list.append(ninja_generator_runner.GeneratorTask( config_context, generator)) cache_miss[cache_path] = config_cache result_list = ninja_generator_runner.run_in_parallel( task_list, OPTIONS.configure_jobs()) aggregated_result = {} ninja_list = [] for config_result in result_list: cache_path = _get_cache_file_path(config_result.config_name, config_result.entry_point) ninja_list.extend(config_result.generated_ninjas) if cache_path in aggregated_result: aggregated_result[cache_path].merge(config_result) else: aggregated_result[cache_path] = config_result for cached_result in cached_result_list: ninja_list.extend(cached_result.generated_ninjas) cache_to_save = [] if OPTIONS.enable_config_cache(): for cache_path, config_result in aggregated_result.iteritems(): config_cache = cache_miss[cache_path] if config_cache is None: config_cache = _config_cache_from_config_result(config_result) else: config_cache.refresh_with_config_result(config_result) cache_to_save.append((config_cache, cache_path)) ninja_list.sort(key=lambda ninja: ninja.get_module_name()) timer.done() return ninja_list, cache_to_save