def generate_ninjas(): n = ninja_generator.ArchiveNinjaGenerator( 'libgles', force_compiler='clang', enable_cxx11=True, base_path='graphics_translation/gles') n.add_compiler_flags('-Werror') n.add_notice_sources(['mods/graphics_translation/NOTICE']) _generate_api_entries_extra_code(n) _generate_pass_through_code(n) if OPTIONS.is_gles_api_tracing(): n.add_defines('ENABLE_API_TRACING') if OPTIONS.is_gles_api_logging(): n.add_defines('ENABLE_API_LOGGING') if OPTIONS.is_gles_passthrough_logging(): n.add_defines('ENABLE_PASSTHROUGH_LOGGING') if OPTIONS.is_gles_passthrough_tracing(): n.add_defines('ENABLE_PASSTHROUGH_TRACING') n.add_include_paths('mods', 'android/system/core/include', 'android/frameworks/native/opengl/include', _get_generated_sources_path()) n.emit_gl_common_flags(False) n.add_ppapi_compile_flags() all_sources = n.find_all_sources() all_sources.append(os.path.join('..', _get_pass_through_impl_path())) if (OPTIONS.is_gles_api_tracing() or OPTIONS.is_gles_api_logging()): all_sources.append(os.path.join('..', _get_api_entries_impl_path())) implicit = [_get_pass_through_h_path()] n.build_default(all_sources, base_path='mods', order_only=implicit) n.archive()
def generate_ninjas(): base_path = os.path.join('graphics_translation', 'egl') n = ninja_generator.ArchiveNinjaGenerator('libegl', force_compiler='clang', enable_cxx11=True, base_path=base_path) n.add_compiler_flags('-Werror') n.add_notice_sources(['mods/graphics_translation/NOTICE']) n.add_include_paths('mods', 'android/system/core/include', 'android/hardware/libhardware/include', 'android/frameworks/native/include', 'android/frameworks/native/opengl/include') n.emit_gl_common_flags(False) n.add_ppapi_compile_flags() if OPTIONS.is_egl_api_tracing(): n.add_defines('ENABLE_API_TRACING') if OPTIONS.is_egl_api_logging(): n.add_defines('ENABLE_API_LOGGING') if OPTIONS.is_ansi_fb_logging(): n.add_defines('ANSI_FB_LOGGING') sources = n.find_all_sources() n.build_default(sources, base_path='mods') n.archive()
def _generate_gmock_ninja(name, enable_libcxx=False): n = ninja_generator.ArchiveNinjaGenerator( name, base_path='testing/gmock/src', instances=0, # Not used by shared objects force_compiler='clang', enable_cxx11=True, enable_libcxx=enable_libcxx) n.add_include_paths(staging.as_staging('testing/gmock'), staging.as_staging('testing/gmock/include')) n.build_default(['gmock-all.cc']).archive()
def _generate_gtest_ninja(name, instances=0, enable_libcxx=False, host=False): n = ninja_generator.ArchiveNinjaGenerator( name, base_path='android/external/chromium_org/testing/gtest/src', instances=instances, force_compiler='clang', enable_cxx11=True, enable_libcxx=enable_libcxx, host=host) n.add_include_paths( staging.as_staging('android/external/chromium_org/testing/gtest')) # To avoid "private field 'pretty_' is not used" on clang. n.add_compiler_flags('-Wno-unused-private-field') n.build_default(['gtest-all.cc']).archive()
def _generate_lib_ninja(): n = ninja_generator.ArchiveNinjaGenerator( 'libgralloc', force_compiler='clang', enable_cxx11=True, base_path='graphics_translation/gralloc') n.add_compiler_flags('-Werror') n.add_notice_sources(['mods/graphics_translation/NOTICE']) n.emit_gl_common_flags(False) n.add_include_paths('mods', 'android/system/core/include', 'android/hardware/libhardware/include', 'android/frameworks/native/opengl/include', 'libyuv/include') sources = n.find_all_sources() sources.remove('graphics_translation/gralloc/gralloc_main.cpp') n.build_default(sources, base_path='mods') n.archive()
def _generate_libcommon_ninja(module_name, instances, enable_libcxx, extra_sources): n = ninja_generator.ArchiveNinjaGenerator(module_name, instances=instances, force_compiler='clang', enable_cxx11=True, enable_libcxx=enable_libcxx, base_path='src/common') n.add_compiler_flags('-Werror') if build_common.use_ndk_direct_execution(): n.add_compiler_flags('-DUSE_NDK_DIRECT_EXECUTION') # Common code really should not reach out into external. n.add_include_paths('android_libcommon') _add_compile_flags(n) sources = n.find_all_sources() sources.remove('src/common/plugin_handle.cc') sources.extend(build_common.as_list(extra_sources)) return n.build_default(sources, base_path=None).archive()
def _generate_libposix_translation(): compiler_flags = [ '-Werror', '-fvisibility=hidden', '-fvisibility-inlines-hidden'] n = ninja_generator.ArchiveNinjaGenerator( 'libposix_translation_static', # libart-gtest and libposix_translation need this force_compiler='clang', enable_cxx11=True) n.add_compiler_flags(*compiler_flags) if OPTIONS.is_posix_translation_debug(): n.add_defines('DEBUG_POSIX_TRANSLATION') if OPTIONS.use_verbose_memory_viewer(): n.add_defines('USE_VERBOSE_MEMORY_VIEWER') # For functions in chromium_org/base/ and private headers in ppapi/. # TODO(crbug.com/234789): Use public API so that we can depend on # nacl_pepper_path instead. n.add_ppapi_compile_flags() n.add_libchromium_base_compile_flags() all_files = build_common.find_all_files(['src/posix_translation'], ['.cc']) n.build_default(all_files).archive() n = ninja_generator.SharedObjectNinjaGenerator( 'libposix_translation', is_system_library=True, force_compiler='clang', enable_cxx11=True) n.add_library_deps('libc.so', 'libm.so', 'libdl.so', 'libstlport.so') n.add_whole_archive_deps('libposix_translation_static.a') # Statically link libchromium_base.a so that we can use unwrapped version of # the library. # TODO(crbug.com/423063, crbug.com/336316): Statically link libcommon.a into # the DSO too for more safety. n.add_library_deps('libchromium_base.a') n.add_compiler_flags(*compiler_flags) n.add_ppapi_link_flags() n.build_default([]).link()
def _generate_breakpad_ninja(): allowed_dirs = ['common', 'linux', 'dwarf'] n = ninja_generator.ArchiveNinjaGenerator('libbreakpad_common', base_path='breakpad/src/common', host=True) n.add_include_paths('breakpad/src') # 19 files in breakpad includes "third_party/lss/linux_syscall_support.h". # We use -idirafter instead of the normal -I. third_party/.. is the top # directory of ARC and developers may put some files whose name # conflicts with standard headers. For example, if one puts "new" at the # top of ARC source tree, ARC will not build if we use -I here. n.add_compiler_flags('-idirafter', 'third_party/..') n.add_cxx_flags('-frtti') # Breakpad uses RTTI. n.add_defines('HAVE_A_OUT_H') all_sources = n.find_all_sources() all_sources = [s for s in all_sources if not s.endswith('test.cc')] all_sources = [ s for s in all_sources if not os.path.basename(os.path.dirname(s)) not in allowed_dirs ] n.build_default(all_sources, base_path=None).archive() for tool, directory_name, cc in [ ['symupload', 'symupload', 'sym_upload.cc'], ['dump_syms', 'dump_syms', 'dump_syms.cc'], ['minidump-2-core-x86-64', 'md2core', 'minidump-2-core.cc'] ]: n = ninja_generator.ExecNinjaGenerator( tool, host=True, base_path='breakpad/src/tools/linux/' + directory_name) n.add_include_paths('breakpad/src') # Workaround for third_party/lss/linux_syscall_support.h n.add_compiler_flags('-idirafter', 'third_party/..') n.add_library_deps('libbreakpad_common.a') n.build_default([cc]).link()
def generate_test_ninjas(): n = ninja_generator.PpapiTestNinjaGenerator( 'posix_translation_test', base_path='src/posix_translation', force_compiler='clang', enable_cxx11=True) # Build a rootfs image for tests. rule_name = 'gen_test_fs_image' script_path = 'src/posix_translation/scripts/create_test_fs_image.py' gen_prod_image = ( build_common.get_posix_translation_readonly_fs_image_file_path()) # This is a little odd, but we use the documented path to the production image # to also store a test image in the same location for simplicity. out_path = os.path.dirname(gen_prod_image) gen_test_image = os.path.join(out_path, 'test_readonly_fs_image.img') n.rule(rule_name, command=script_path + ' $out_path', description=rule_name + ' $in_real_path') n.add_ppapi_compile_flags() n.build([gen_test_image], rule_name, variables={'out_path': out_path}, # The script calls create_readonly_fs_image.py. implicit=[script_path, _CREATE_READONLY_FS_IMAGE_SCRIPT, ]) all_files = n.find_all_contained_test_sources() n.build_default(all_files, base_path=None) n.add_compiler_flags('-Werror') n.add_library_deps('libposix_translation_static.a', 'libchromium_base.a', 'libcommon.a', 'libgccdemangle_static.a') if build_common.use_ndk_direct_execution(): n.add_defines('USE_NDK_DIRECT_EXECUTION') implicit = [gen_test_image] if open_source.is_open_source_repo(): implicit.append(gen_prod_image) n.add_defines('PROD_READONLY_FS_IMAGE="%s"' % gen_prod_image) else: # Add runtime to implicit dependencies because ReadonlyFsReaderTest uses # the readonly FS image in runtime. implicit.append(build_common.get_runtime_build_stamp()) n.add_defines('PROD_READONLY_FS_IMAGE="%s"' % os.path.join( build_common.get_runtime_platform_specific_path( build_common.get_runtime_out_dir(), OPTIONS.target()), os.path.basename(gen_prod_image))) n.run(n.link(), implicit=implicit) # To be able to refer mock implementation from outside of posix_translation. # Setting instance count is zero because usage count verifier doesn't check # the reference from test executable. See verify_usage_counts in # ninja_generator.py n = ninja_generator.ArchiveNinjaGenerator( 'mock_posix_translation', instances=0, force_compiler='clang', enable_cxx11=True) n.add_libchromium_base_compile_flags() n.add_compiler_flags('-Werror') all_files = ['src/posix_translation/test_util/mock_virtual_file_system.cc'] n.build_default(all_files).archive()
def _generate_libppapi_mocks(): ppapi_dir = staging.as_staging('chromium-ppapi/ppapi') api_dir = os.path.join(ppapi_dir, 'api') out_dir = os.path.join( ninja_generator.PpapiTestNinjaGenerator.get_ppapi_mocks_generated_dir( ), 'ppapi_mocks') stamp_file = os.path.join(out_dir, 'STAMP') # Generate PPAPI mock sources from IDL files. rule_name = 'gen_ppapi_mock' n = ninja_generator.PythonNinjaGenerator(rule_name) script_path = os.path.join(_MY_DIR, 'gen_ppapi_mock.py') args = [ '--wnone', # Suppress all warnings. '--range=start,end', # Generate code for all revisions. '--ppapicgen', # Generate PpapiMock source files. '--ppapihgen', # Generate PpapiMock header files. '--srcroot', api_dir, '--dstroot', out_dir ] n.emit_python_rule(rule_name, script_path, args, extra_command='&& touch $stamp') generated_files = [] idl_list = n.find_all_files('chromium-ppapi/ppapi/api', '.idl') for idl_path in idl_list: if 'finish_writing_these' in idl_path: # Files under ppapi/api/private/finish_writing_these/ directory are not # found by the parser of the idl generator library. continue path_stem = os.path.splitext(os.path.basename(idl_path))[0] # We are interested in only PPB files. if not path_stem.startswith('ppb_'): continue generated_files.append(os.path.join(out_dir, path_stem + '.cc')) generated_files.append(os.path.join(out_dir, path_stem + '.h')) n.run_python(generated_files + [stamp_file], rule_name, variables={'stamp': pipes.quote(stamp_file)}, implicit=map(staging.as_staging, idl_list)) # Build libppapi_mocks. libart-gtest depends on libppapi_mocks. n = ninja_generator.ArchiveNinjaGenerator('libppapi_mocks', instances=0, force_compiler='clang', enable_cxx11=True) n.add_ppapi_compile_flags() n.add_libchromium_base_compile_flags() n.add_include_paths( staging.as_staging('testing/gmock/include'), _MY_DIR, ninja_generator.PpapiTestNinjaGenerator.get_ppapi_mocks_generated_dir( )) n.build_default([path for path in generated_files if path.endswith('.cc')] + n.find_all_files([_MY_DIR], '.cc', include_tests=True), implicit=[stamp_file]) n.archive()
def _generate_libpluginhandle_ninja_common(module_name, instances, enable_libcxx): n = ninja_generator.ArchiveNinjaGenerator(module_name, instances=instances, enable_libcxx=enable_libcxx) return n.build_default(['src/common/plugin_handle.cc']).archive()
def _generate_real_syscall_aliases_ninja(): n = ninja_generator.ArchiveNinjaGenerator( 'libcommon_real_syscall_aliases', instances=0) # Should not be used by production binary. sources = [_get_real_syscall_aliases_s(n)] n.build_default(sources, base_path=None).archive()
def _generate_libcommon_test_main_ninja(): n = ninja_generator.ArchiveNinjaGenerator( 'libcommon_test_main', base_path='src/common/tests', instances=0) # Should not be used by production binary. sources = n.find_all_sources(include_tests=True) n.build_default(sources, base_path=None).archive()
def _generate_chromium_base_ninja_common(module_name, instances, enable_libcxx): base_path = 'android/external/chromium_org/base' # chromium_base is required by libart-gtest, libposix_translation, and the # plugin. n = ninja_generator.ArchiveNinjaGenerator(module_name, base_path=base_path, instances=instances, force_compiler='clang', enable_cxx11=True, enable_libcxx=enable_libcxx) n.add_compiler_flags('-fvisibility=hidden') # for libposix_translation.so _add_chromium_base_compiler_flags(n) def relevant(f): f = f.lstrip('android/external/chromium_org/') # Files with specific suffixes like '_linux' are usually excluded. # Here is the list of exceptions. whitelist = [ 'base/threading/platform_thread_linux.cc', 'base/threading/thread_local_android.cc', 'base/debug/stack_trace_android.cc', 'base/debug/trace_event_android.cc' ] if f in whitelist: return True # Exclude cc files that do not compile with nacl-g++. Roughly speaking, # functions in the following categories do not compile/work: # - Functions that execute commands (e.g. *_xdg.cc). # - Functions that depends on file_util.h which is not (yet) available. excludes = [ 'base/allocator/generic_allocators.cc', 'base/async_socket_io_handler_posix.cc', 'base/base64.cc', 'base/base_paths.cc', 'base/base_paths_posix.cc', 'base/check_example.cc', 'base/cpu.cc', 'base/debug_message.cc', # This is excluded in the upstream, too. 'base/debug/stack_trace_posix.cc', 'base/debug/trace_event_system_stats_monitor.cc', # TODO(crbug.com/414569): L-rebase: Do I need it? 'base/memory/discardable_memory_ashmem.cc', 'base/memory/discardable_memory_ashmem_allocator.cc', 'base/files/file_enumerator_posix.cc', 'base/files/file_proxy.cc', 'base/files/file_path_watcher_fsevents.cc', # for Mac 'base/files/important_file_writer.cc', 'base/files/memory_mapped_file.cc', 'base/files/memory_mapped_file_posix.cc', 'base/files/scoped_temp_dir.cc', 'base/guid_posix.cc', 'base/json/json_file_value_serializer.cc', 'base/memory/discardable_memory.cc', 'base/memory/shared_memory_posix.cc', 'base/message_loop/message_pump_ozone.cc', 'base/message_loop/message_pump_x11.cc', 'base/nix/mime_util_xdg.cc', 'base/nix/xdg_util.cc', # This provides timegm implementation, but we use the one in bionic. 'base/os_compat_nacl.cc', 'base/path_service.cc', 'base/perftimer.cc', 'base/rand_util.cc', 'base/rand_util_nacl.cc', 'base/rand_util_posix.cc', 'base/sync_socket_posix.cc', 'base/third_party/dmg_fp/dtoa_wrapper.cc', 'base/threading/watchdog.cc', 'base/x11/edid_parser_x11.cc', 'base/x11/x11_error_tracker.cc' ] if ((f in excludes) or # Exclude non-cc files. (not f.endswith('.cc') and not f.endswith('.c')) or # Exclude tests. re.search(r'test?\.cc|unittest|/test/', f) or # Exclude directories that are not compatible with nacl-g++. re.search(r'/(i18n|prefs|histogram|metrics|xdg_mime|process)/', f) or # Exclude files for other architectures. Also excludes files that # operates files. These files do not seem to support OS_NACL build. re.search( r'[/_](win|mac|linux|chromeos|android|ios|glib|gtk|' 'openbsd|freebsd|kqueue|libevent|aurax11|' # TODO(yusukes): Try to compile file_util*.cc with NaCl g++ # to minimize the |excludes| list above. 'sys_info|process_|shim|file_util)', f)): return False return True build_files = filter(relevant, n.find_all_sources()) n.build_default(build_files, base_path=None).archive() # Dump global symbols in libchromium_base. if not enable_libcxx: out_path = os.path.join( ninja_generator.CNinjaGenerator.get_symbols_path(), 'libchromium_base.a.defined') n.build([out_path], 'dump_defined_symbols', build_common.get_build_path_for_library('libchromium_base.a'), implicit='src/build/symbol_tool.py')