From 122352d983805b8ded5f8f3c07e75844244aba40 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Mon, 2 Oct 2017 15:20:07 -0700 Subject: [PATCH] Use -Werror in system/core * Move -Wall -Werror from cppflags to cflags. * Fix/suppress warning on unused variables. Bug: 66996870 Test: build with WITH_TIDY=1 Change-Id: I1e05e96a1d0bcb2ccef1ce456504b3af57167cc5 --- base/Android.bp | 13 ++++++------- debuggerd/crasher/Android.bp | 2 +- fs_mgr/Android.bp | 6 +++++- init/Android.bp | 2 +- init/test_service/Android.bp | 1 + init/test_service/test_service.cpp | 1 - libasyncio/Android.bp | 11 +++++------ libgrallocusage/Android.bp | 5 ++++- libpackagelistparser/Android.bp | 1 + libprocinfo/Android.bp | 13 ++++++------- libutils/Android.bp | 3 ++- libutils/RefBase.cpp | 3 +-- libutils/StopWatch.cpp | 5 +---- libutils/include/utils/StopWatch.h | 19 ++++++++----------- libutils/tests/Android.bp | 2 ++ libvndksupport/Android.bp | 1 + libvndksupport/tests/Android.bp | 1 + trusty/keymaster/Android.bp | 1 + trusty/keymaster/trusty_keymaster_main.cpp | 1 - trusty/libtrusty/Android.bp | 1 + trusty/libtrusty/tipc-test/Android.bp | 1 + 21 files changed, 49 insertions(+), 44 deletions(-) diff --git a/base/Android.bp b/base/Android.bp index f4a841107..7ff02a0ee 100644 --- a/base/Android.bp +++ b/base/Android.bp @@ -14,11 +14,10 @@ // limitations under the License. // -libbase_cppflags = [ - "-Wall", - "-Wextra", - "-Werror", -] +cc_defaults { + name: "libbase_defaults", + cflags: ["-Wall", "-Werror", "-Wextra"], +} cc_library_headers { name: "libbase_headers", @@ -38,6 +37,7 @@ cc_library_headers { cc_library { name: "libbase", + defaults: ["libbase_defaults"], vendor_available: true, host_supported: true, vndk: { @@ -59,7 +59,6 @@ cc_library { ], export_header_lib_headers: ["libbase_headers"], - cppflags: libbase_cppflags, shared_libs: ["liblog"], target: { android: { @@ -102,6 +101,7 @@ cc_library { // ------------------------------------------------------------------------------ cc_test { name: "libbase_test", + defaults: ["libbase_defaults"], host_supported: true, srcs: [ "endian_test.cpp", @@ -133,7 +133,6 @@ cc_test { }, }, local_include_dirs: ["."], - cppflags: libbase_cppflags, shared_libs: ["libbase"], compile_multilib: "both", multilib: { diff --git a/debuggerd/crasher/Android.bp b/debuggerd/crasher/Android.bp index 67b4ab7b5..7bec470fb 100644 --- a/debuggerd/crasher/Android.bp +++ b/debuggerd/crasher/Android.bp @@ -1,7 +1,7 @@ cc_defaults { name: "crasher-defaults", - cppflags: [ + cflags: [ "-W", "-Wall", "-Wextra", diff --git a/fs_mgr/Android.bp b/fs_mgr/Android.bp index 5a6298e9b..ed165ed79 100644 --- a/fs_mgr/Android.bp +++ b/fs_mgr/Android.bp @@ -20,7 +20,11 @@ cc_defaults { misc_undefined: ["integer"], }, local_include_dirs: ["include/"], - cppflags: ["-Werror"], + cflags: [ + "-Wall", + "-Werror", + "-Wno-unused-variable", + ], } cc_library_static { diff --git a/init/Android.bp b/init/Android.bp index 8c4f005d8..45ee754af 100644 --- a/init/Android.bp +++ b/init/Android.bp @@ -20,7 +20,7 @@ cc_defaults { sanitize: { misc_undefined: ["signed-integer-overflow"], }, - cppflags: [ + cflags: [ "-DLOG_UEVENTS=0", "-Wall", "-Wextra", diff --git a/init/test_service/Android.bp b/init/test_service/Android.bp index 9bd6f275e..63996993a 100644 --- a/init/test_service/Android.bp +++ b/init/test_service/Android.bp @@ -17,6 +17,7 @@ cc_binary { name: "test_service", srcs: ["test_service.cpp"], + cflags: ["-Wall", "-Werror"], shared_libs: ["libbase"], init_rc: ["test_service.rc"], } diff --git a/init/test_service/test_service.cpp b/init/test_service/test_service.cpp index e7206f89e..71d1ea44b 100644 --- a/init/test_service/test_service.cpp +++ b/init/test_service/test_service.cpp @@ -59,7 +59,6 @@ int main(int argc, char* argv[]) { } bool test_fails = false; - size_t uargc = static_cast(argc); // |argc| >= 3. for (size_t i = 1; i < static_cast(argc); i = i + 2) { std::string expected_value = argv[i + 1]; auto f = fields.find(argv[i]); diff --git a/libasyncio/Android.bp b/libasyncio/Android.bp index 9a637acb7..9a12f0d2d 100644 --- a/libasyncio/Android.bp +++ b/libasyncio/Android.bp @@ -14,20 +14,19 @@ // limitations under the License. // -libasyncio_cppflags = [ - "-Wall", - "-Wextra", - "-Werror", -] +cc_defaults { + name: "libasyncio_defaults", + cflags: ["-Wall", "-Werror", "-Wextra"], +} cc_library { name: "libasyncio", + defaults: ["libasyncio_defaults"], vendor_available: true, host_supported: true, srcs: [ "AsyncIO.cpp", ], - cppflags: libasyncio_cppflags, export_include_dirs: ["include"], target: { diff --git a/libgrallocusage/Android.bp b/libgrallocusage/Android.bp index cf03868d2..bcc061691 100644 --- a/libgrallocusage/Android.bp +++ b/libgrallocusage/Android.bp @@ -15,9 +15,12 @@ cc_library_static { name: "libgrallocusage", vendor_available: true, + cflags: [ + "-Wall", + "-Werror", + ], cppflags: [ "-Weverything", - "-Werror", "-Wno-c++98-compat-pedantic", // Hide errors in headers we include "-Wno-global-constructors", diff --git a/libpackagelistparser/Android.bp b/libpackagelistparser/Android.bp index a9fec7df3..3d202fc1d 100644 --- a/libpackagelistparser/Android.bp +++ b/libpackagelistparser/Android.bp @@ -2,6 +2,7 @@ cc_library { name: "libpackagelistparser", srcs: ["packagelistparser.c"], + cflags: ["-Wall", "-Werror"], shared_libs: ["liblog"], local_include_dirs: ["include"], export_include_dirs: ["include"], diff --git a/libprocinfo/Android.bp b/libprocinfo/Android.bp index b568ee5da..1cfabd5be 100644 --- a/libprocinfo/Android.bp +++ b/libprocinfo/Android.bp @@ -14,14 +14,14 @@ // limitations under the License. // -libprocinfo_cppflags = [ - "-Wall", - "-Wextra", - "-Werror", -] +cc_defaults { + name: "libprocinfo_defaults", + cflags: ["-Wall", "-Werror", "-Wextra"], +} cc_library { name: "libprocinfo", + defaults: ["libprocinfo_defaults"], vendor_available: true, vndk: { enabled: true, @@ -30,7 +30,6 @@ cc_library { srcs: [ "process.cpp", ], - cppflags: libprocinfo_cppflags, local_include_dirs: ["include"], export_include_dirs: ["include"], @@ -52,6 +51,7 @@ cc_library { // ------------------------------------------------------------------------------ cc_test { name: "libprocinfo_test", + defaults: ["libprocinfo_defaults"], host_supported: true, srcs: [ "process_test.cpp", @@ -65,7 +65,6 @@ cc_test { }, }, - cppflags: libprocinfo_cppflags, shared_libs: ["libbase", "libprocinfo"], compile_multilib: "both", diff --git a/libutils/Android.bp b/libutils/Android.bp index b70845b75..4bd2a9859 100644 --- a/libutils/Android.bp +++ b/libutils/Android.bp @@ -75,7 +75,7 @@ cc_library { "misc.cpp", ], - cflags: ["-Werror"], + cflags: ["-Wall", "-Werror"], include_dirs: ["external/safe-iop/include"], header_libs: [ "libutils_headers", @@ -154,6 +154,7 @@ cc_test { static_libs: ["libutils"], shared_libs: ["liblog"], srcs: ["SharedBufferTest.cpp"], + cflags: ["-Wall", "-Werror"], } subdirs = ["tests"] diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index f5f881fcc..8bccb0f5c 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -410,8 +410,7 @@ void RefBase::incStrong(const void* id) const return; } - int32_t old = refs->mStrong.fetch_sub(INITIAL_STRONG_VALUE, - std::memory_order_relaxed); + int32_t old __unused = refs->mStrong.fetch_sub(INITIAL_STRONG_VALUE, std::memory_order_relaxed); // A decStrong() must still happen after us. ALOG_ASSERT(old > INITIAL_STRONG_VALUE, "0x%x too small", old); refs->mBase->onFirstRef(); diff --git a/libutils/StopWatch.cpp b/libutils/StopWatch.cpp index 219c13c67..d01865e9c 100644 --- a/libutils/StopWatch.cpp +++ b/libutils/StopWatch.cpp @@ -30,10 +30,7 @@ namespace android { - -StopWatch::StopWatch(const char *name, int clock, uint32_t flags) - : mName(name), mClock(clock), mFlags(flags) -{ +StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) { reset(); } diff --git a/libutils/include/utils/StopWatch.h b/libutils/include/utils/StopWatch.h index 693dd3ccf..76d78d0f4 100644 --- a/libutils/include/utils/StopWatch.h +++ b/libutils/include/utils/StopWatch.h @@ -29,21 +29,18 @@ namespace android { class StopWatch { public: - StopWatch( const char *name, - int clock = SYSTEM_TIME_MONOTONIC, - uint32_t flags = 0); - ~StopWatch(); - - const char* name() const; - nsecs_t lap(); - nsecs_t elapsedTime() const; + StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC); + ~StopWatch(); + + const char* name() const; + nsecs_t lap(); + nsecs_t elapsedTime() const; + + void reset(); - void reset(); - private: const char* mName; int mClock; - uint32_t mFlags; struct lap_t { nsecs_t soFar; diff --git a/libutils/tests/Android.bp b/libutils/tests/Android.bp index a891fcae2..a3e7ffe73 100644 --- a/libutils/tests/Android.bp +++ b/libutils/tests/Android.bp @@ -77,6 +77,7 @@ cc_test_library { host_supported: true, relative_install_path: "libutils_tests", srcs: ["Singleton_test1.cpp"], + cflags: ["-Wall", "-Werror"], } cc_test_library { @@ -84,5 +85,6 @@ cc_test_library { host_supported: true, relative_install_path: "libutils_tests", srcs: ["Singleton_test2.cpp"], + cflags: ["-Wall", "-Werror"], shared_libs: ["libutils_tests_singleton1"], } diff --git a/libvndksupport/Android.bp b/libvndksupport/Android.bp index b62422323..fec79b70d 100644 --- a/libvndksupport/Android.bp +++ b/libvndksupport/Android.bp @@ -3,6 +3,7 @@ subdirs = ["tests"] cc_library { name: "libvndksupport", srcs: ["linker.c"], + cflags: ["-Wall", "-Werror"], local_include_dirs: ["include/vndksupport"], export_include_dirs: ["include"], shared_libs: ["liblog"], diff --git a/libvndksupport/tests/Android.bp b/libvndksupport/tests/Android.bp index 3587cf88a..5b467f8ff 100644 --- a/libvndksupport/tests/Android.bp +++ b/libvndksupport/tests/Android.bp @@ -17,6 +17,7 @@ cc_test { srcs: [ "linker_test.cpp", ], + cflags: ["-Wall", "-Werror"], host_supported: false, shared_libs: [ diff --git a/trusty/keymaster/Android.bp b/trusty/keymaster/Android.bp index 6b9d72359..773568499 100644 --- a/trusty/keymaster/Android.bp +++ b/trusty/keymaster/Android.bp @@ -30,6 +30,7 @@ cc_binary { "trusty_keymaster_ipc.cpp", "trusty_keymaster_main.cpp", ], + cflags: ["-Wall", "-Werror"], shared_libs: [ "libcrypto", "libcutils", diff --git a/trusty/keymaster/trusty_keymaster_main.cpp b/trusty/keymaster/trusty_keymaster_main.cpp index 9c2ae2d0a..ed78b7fb2 100644 --- a/trusty/keymaster/trusty_keymaster_main.cpp +++ b/trusty/keymaster/trusty_keymaster_main.cpp @@ -289,7 +289,6 @@ static bool test_import_ecdsa(TrustyKeymasterDevice* device) { std::unique_ptr deleter(key.key_material); printf("=== Signing with imported ECDSA key ===\n"); - keymaster_ec_sign_params_t sign_params = {DIGEST_NONE}; size_t message_len = 30 /* arbitrary */; std::unique_ptr message(new uint8_t[message_len]); memset(message.get(), 'a', message_len); diff --git a/trusty/libtrusty/Android.bp b/trusty/libtrusty/Android.bp index f316da229..1a8db2f90 100644 --- a/trusty/libtrusty/Android.bp +++ b/trusty/libtrusty/Android.bp @@ -21,6 +21,7 @@ cc_library { srcs: ["trusty.c"], export_include_dirs: ["include"], + cflags: ["-Wall", "-Werror"], shared_libs: ["liblog"], } diff --git a/trusty/libtrusty/tipc-test/Android.bp b/trusty/libtrusty/tipc-test/Android.bp index cb00fe772..6ec8c23f7 100644 --- a/trusty/libtrusty/tipc-test/Android.bp +++ b/trusty/libtrusty/tipc-test/Android.bp @@ -23,4 +23,5 @@ cc_test { "liblog", ], gtest: false, + cflags: ["-Wall", "-Werror"], }