From 4c69948a003f80b823fc6852398bdb5b9441a567 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Thu, 25 Jan 2018 07:50:56 -0500 Subject: [PATCH] build: Trim libevent usage Use system libevent on Linux. Remove extra libs on other platforms. --- base/BUILD.gn | 14 ++++++++++++-- base/message_loop/message_pump_libevent.cc | 7 ++++++- tools/gn/bootstrap/bootstrap.py | 13 ++----------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/base/BUILD.gn b/base/BUILD.gn index 943412faef..88c642a632 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -1187,6 +1187,7 @@ jumbo_component("base") { defines = [] data = [] data_deps = [] + libs = [] configs += [ ":base_flags", @@ -1745,7 +1746,11 @@ jumbo_component("base") { } if (dep_libevent) { - deps += [ "//base/third_party/libevent" ] + if (is_linux) { + libs += [ "event_core" ] + } else { + deps += [ "//base/third_party/libevent" ] + } } if (use_libevent) { @@ -2466,6 +2471,7 @@ test("base_unittests") { ] defines = [] + libs = [] deps = [ ":base", @@ -2609,7 +2615,11 @@ test("base_unittests") { if (use_libevent) { sources += [ "message_loop/message_pump_libevent_unittest.cc" ] - deps += [ "//base/third_party/libevent" ] + if (is_linux) { + libs += [ "event_core" ] + } else { + deps += [ "//base/third_party/libevent" ] + } } if (is_fuchsia) { diff --git a/base/message_loop/message_pump_libevent.cc b/base/message_loop/message_pump_libevent.cc index 2a595e5fe5..e5380b1542 100644 --- a/base/message_loop/message_pump_libevent.cc +++ b/base/message_loop/message_pump_libevent.cc @@ -14,7 +14,6 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" -#include "base/third_party/libevent/event.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" @@ -23,6 +22,12 @@ #include "base/mac/scoped_nsautorelease_pool.h" #endif +#if defined(OS_LINUX) +#include +#else +#include "base/third_party/libevent/event.h" +#endif + // Lifecycle of struct event // Libevent uses two main data structures: // struct event_base (of which there is one per message pump), and diff --git a/tools/gn/bootstrap/bootstrap.py b/tools/gn/bootstrap/bootstrap.py index 300abacdbc..74e1c00cff 100755 --- a/tools/gn/bootstrap/bootstrap.py +++ b/tools/gn/bootstrap/bootstrap.py @@ -708,16 +708,13 @@ def write_gn_ninja(path, root_gen_dir, options, windows_x64_toolchain): 'base/threading/thread_local_storage_posix.cc', 'base/time/time_conversion_posix.cc', ]) + if not is_linux: static_libraries['libevent'] = { 'sources': [ 'base/third_party/libevent/buffer.c', 'base/third_party/libevent/evbuffer.c', - 'base/third_party/libevent/evdns.c', 'base/third_party/libevent/event.c', - 'base/third_party/libevent/event_tagging.c', - 'base/third_party/libevent/evrpc.c', 'base/third_party/libevent/evutil.c', - 'base/third_party/libevent/http.c', 'base/third_party/libevent/log.c', 'base/third_party/libevent/poll.c', 'base/third_party/libevent/select.c', @@ -838,13 +835,7 @@ def write_gn_ninja(path, root_gen_dir, options, windows_x64_toolchain): 'base/allocator/allocator_shim.cc', 'base/allocator/allocator_shim_default_dispatch_to_glibc.cc', ]) - libs.extend(['-lrt', '-latomic']) - static_libraries['libevent']['include_dirs'].extend([ - os.path.join(SRC_ROOT, 'base', 'third_party', 'libevent', 'linux') - ]) - static_libraries['libevent']['sources'].extend([ - 'base/third_party/libevent/epoll.c', - ]) + libs.extend(['-lrt', '-latomic', '-levent_core']) else: ldflags.extend(['-pthread']) libs.extend(['-lrt'])