From a2f9136b2c54a2ab5224e217548a274db2a91478 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 20 Feb 2020 10:50:00 -0800 Subject: [PATCH] Refactor libinit_test_utils to not use libinit and expose its libraries Users of libinit_test_utils must include all libraries that it uses. If it uses libinit, then there is a large number of libraries that must be included. To avoid this, make libinit_test_utils only use init_common_sources and the small number of required libraries that go along with those sources. Additionally, expose these sources as a default for users of libinit_test_utils. Test: build Change-Id: I224fa7e0590d073e4cd40412b5dcb6f72a64b6bf --- init/Android.bp | 32 ++++++++++++++++++++++++++++++++ init/action_parser.cpp | 2 +- init/service.cpp | 4 ++-- init/service_parser.cpp | 2 +- init/subcontext.cpp | 2 +- init/test_utils/Android.bp | 27 --------------------------- init/util.cpp | 2 +- 7 files changed, 38 insertions(+), 33 deletions(-) delete mode 100644 init/test_utils/Android.bp diff --git a/init/Android.bp b/init/Android.bp index f28934e95..3bb08db6c 100644 --- a/init/Android.bp +++ b/init/Android.bp @@ -88,6 +88,7 @@ cc_defaults { "-DWORLD_WRITABLE_KMSG=0", "-DDUMP_ON_UMOUNT_FAILURE=0", "-DSHUTDOWN_ZERO_TIMEOUT=0", + "-DINIT_FULL_SOURCES", ], product_variables: { debuggable: { @@ -267,6 +268,37 @@ cc_benchmark { static_libs: ["libinit"], } +cc_defaults { + name: "libinit_test_utils_libraries_defaults", + shared_libs: [ + "libbase", + "libcutils", + "libselinux", + "libhidl-gen-utils", + "liblog", + "libprocessgroup", + "libprotobuf-cpp-lite", + ], +} + +cc_library_static { + name: "libinit_test_utils", + defaults: ["libinit_test_utils_libraries_defaults"], + cflags: [ + "-Wall", + "-Wextra", + "-Wno-unused-parameter", + "-Werror", + ], + srcs: init_common_sources + [ + "test_utils/service_utils.cpp", + ], + whole_static_libs: [ + "libcap", + ], + export_include_dirs: ["test_utils/include"], // for tests +} + // Host Verifier // ------------------------------------------------------------------------------ diff --git a/init/action_parser.cpp b/init/action_parser.cpp index f3168716f..52f6a1f3c 100644 --- a/init/action_parser.cpp +++ b/init/action_parser.cpp @@ -21,7 +21,7 @@ #include #include -#if defined(__ANDROID__) +#ifdef INIT_FULL_SOURCES #include "property_service.h" #include "selinux.h" #else diff --git a/init/service.cpp b/init/service.cpp index 665a1b0a1..b12d11aec 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -40,7 +40,7 @@ #include "service_list.h" #include "util.h" -#if defined(__ANDROID__) +#ifdef INIT_FULL_SOURCES #include #include @@ -303,7 +303,7 @@ void Service::Reap(const siginfo_t& siginfo) { return; } -#if defined(__ANDROID__) +#if INIT_FULL_SOURCES static bool is_apex_updatable = android::sysprop::ApexProperties::updatable().value_or(false); #else static bool is_apex_updatable = false; diff --git a/init/service_parser.cpp b/init/service_parser.cpp index 4b04ba05c..560f693f9 100644 --- a/init/service_parser.cpp +++ b/init/service_parser.cpp @@ -34,7 +34,7 @@ #include "service_utils.h" #include "util.h" -#if defined(__ANDROID__) +#ifdef INIT_FULL_SOURCES #include #include diff --git a/init/subcontext.cpp b/init/subcontext.cpp index 326015952..5263c14c8 100644 --- a/init/subcontext.cpp +++ b/init/subcontext.cpp @@ -31,7 +31,7 @@ #include "proto_utils.h" #include "util.h" -#if defined(__ANDROID__) +#ifdef INIT_FULL_SOURCES #include #include "property_service.h" #include "selabel.h" diff --git a/init/test_utils/Android.bp b/init/test_utils/Android.bp deleted file mode 100644 index 1cb05b629..000000000 --- a/init/test_utils/Android.bp +++ /dev/null @@ -1,27 +0,0 @@ -cc_library_static { - name: "libinit_test_utils", - cflags: [ - "-Wall", - "-Wextra", - "-Wno-unused-parameter", - "-Werror", - ], - srcs: [ - "service_utils.cpp", - ], - shared_libs: [ - "libcutils", - "liblog", - "libjsoncpp", - "libprotobuf-cpp-lite", - "libhidl-gen-utils", - ], - whole_static_libs: [ - "libinit", - "libpropertyinfoparser", - ], - static_libs: [ - "libbase", - ], - export_include_dirs: ["include"], // for tests -} diff --git a/init/util.cpp b/init/util.cpp index 503c70536..24f94ec9e 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -41,7 +41,7 @@ #include #include -#if defined(__ANDROID__) +#ifdef INIT_FULL_SOURCES #include #include