From c1b32bd7a19ff8926b7610694c15a8cbc4c47ea6 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 11 Jan 2022 15:26:32 +0000 Subject: [PATCH] chore: Enable compiler layering check. This ensures that we're explicit about what we depend on and avoids transitive dependencies. --- other/bootstrap_daemon/BUILD.bazel | 9 +++ testing/BUILD.bazel | 16 ++++- toxav/BUILD.bazel | 29 +++++++++- toxcore/BUILD.bazel | 93 +++++++++++++++++++++++++++--- 4 files changed, 135 insertions(+), 12 deletions(-) diff --git a/other/bootstrap_daemon/BUILD.bazel b/other/bootstrap_daemon/BUILD.bazel index 0f38085d82..86363ff1e3 100644 --- a/other/bootstrap_daemon/BUILD.bazel +++ b/other/bootstrap_daemon/BUILD.bazel @@ -1,5 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") +package(features = ["layering_check"]) + cc_binary( name = "bootstrap_daemon", srcs = glob([ @@ -9,6 +11,13 @@ cc_binary( deps = [ "//c-toxcore/other:bootstrap_node_packets", "//c-toxcore/toxcore", + "//c-toxcore/toxcore:DHT", + "//c-toxcore/toxcore:TCP_connection", + "//c-toxcore/toxcore:ccompat", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", + "//c-toxcore/toxcore:network", + "//c-toxcore/toxcore:onion_announce", "@libconfig", ], ) diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel index aa5464004c..2abb8d86ef 100644 --- a/testing/BUILD.bazel +++ b/testing/BUILD.bazel @@ -1,5 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +package(features = ["layering_check"]) + CIMPLE_FILES = [ "//c-toxcore/toxav:cimple_files", "//c-toxcore/toxcore:cimple_files", @@ -20,7 +22,11 @@ cc_library( srcs = ["misc_tools.c"], hdrs = ["misc_tools.h"], visibility = ["//c-toxcore:__subpackages__"], - deps = ["//c-toxcore/toxcore"], + deps = [ + "//c-toxcore/toxcore", + "//c-toxcore/toxcore:ccompat", + "@libsodium", + ], ) cc_library( @@ -35,7 +41,10 @@ cc_binary( srcs = ["DHT_test.c"], deps = [ ":misc_tools", - "//c-toxcore/toxcore", + "//c-toxcore/toxcore:DHT", + "//c-toxcore/toxcore:Messenger", + "//c-toxcore/toxcore:friend_requests", + "//c-toxcore/toxcore:mono_time", ], ) @@ -44,7 +53,8 @@ cc_binary( srcs = ["Messenger_test.c"], deps = [ ":misc_tools", - "//c-toxcore/toxcore", + "//c-toxcore/toxcore:Messenger", + "//c-toxcore/toxcore:mono_time", ], ) diff --git a/toxav/BUILD.bazel b/toxav/BUILD.bazel index 7935b8860e..4fccacf58d 100644 --- a/toxav/BUILD.bazel +++ b/toxav/BUILD.bazel @@ -1,6 +1,8 @@ load("@rules_cc//cc:defs.bzl", "cc_test") load("//tools:no_undefined.bzl", "cc_library") +package(features = ["layering_check"]) + filegroup( name = "public_headers", srcs = ["toxav.h"], @@ -25,6 +27,7 @@ cc_test( srcs = ["ring_buffer_test.cc"], deps = [ ":ring_buffer", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -47,6 +50,9 @@ cc_library( ":ring_buffer", "//c-toxcore/toxcore", "//c-toxcore/toxcore:Messenger", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", + "//c-toxcore/toxcore:network", ], ) @@ -54,7 +60,13 @@ cc_library( name = "rtp", srcs = ["rtp.c"], hdrs = ["rtp.h"], - deps = [":bwcontroller"], + deps = [ + ":bwcontroller", + "//c-toxcore/toxcore:Messenger", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", + "//c-toxcore/toxcore:network", + ], ) cc_test( @@ -64,6 +76,7 @@ cc_test( deps = [ ":rtp", "//c-toxcore/toxcore:crypto_core", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -75,6 +88,8 @@ cc_library( deps = [ ":public", ":rtp", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", "//c-toxcore/toxcore:network", "@opus", ], @@ -93,6 +108,10 @@ cc_library( deps = [ ":audio", ":public", + ":ring_buffer", + ":rtp", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", "//c-toxcore/toxcore:network", "@libvpx", ], @@ -104,6 +123,9 @@ cc_library( hdrs = ["groupav.h"], deps = [ "//c-toxcore/toxcore", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", + "//c-toxcore/toxcore:network", "@opus", ], ) @@ -120,7 +142,12 @@ cc_library( visibility = ["//c-toxcore:__subpackages__"], deps = [ ":groupav", + ":rtp", ":video", + "//c-toxcore/toxcore:Messenger", + "//c-toxcore/toxcore:logger", + "//c-toxcore/toxcore:mono_time", + "//c-toxcore/toxcore:network", ], ) diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index 23203b5b91..862f8eee56 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -1,6 +1,8 @@ load("@rules_cc//cc:defs.bzl", "cc_test") load("//tools:no_undefined.bzl", "cc_library") +package(features = ["layering_check"]) + filegroup( name = "public_headers", srcs = ["tox.h"], @@ -36,6 +38,7 @@ cc_test( flaky = True, deps = [ ":crypto_core", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -53,6 +56,7 @@ cc_test( srcs = ["list_test.cc"], deps = [ ":list", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -61,6 +65,10 @@ cc_library( name = "logger", srcs = ["logger.c"], hdrs = ["logger.h"], + visibility = [ + "//c-toxcore/other/bootstrap_daemon:__pkg__", + "//c-toxcore/toxav:__pkg__", + ], deps = [":ccompat"], ) @@ -75,6 +83,11 @@ cc_library( name = "mono_time", srcs = ["mono_time.c"], hdrs = ["mono_time.h"], + visibility = [ + "//c-toxcore/other/bootstrap_daemon:__pkg__", + "//c-toxcore/testing:__pkg__", + "//c-toxcore/toxav:__pkg__", + ], deps = [ ":ccompat", "@pthread", @@ -87,6 +100,7 @@ cc_test( srcs = ["mono_time_test.cc"], deps = [ ":mono_time", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -103,6 +117,7 @@ cc_library( ], visibility = [ "//c-toxcore/other:__pkg__", + "//c-toxcore/other/bootstrap_daemon:__pkg__", "//c-toxcore/toxav:__pkg__", ], deps = [ @@ -110,6 +125,7 @@ cc_library( ":crypto_core", ":logger", ":mono_time", + "@libsodium", "@psocket", "@pthread", ], @@ -121,6 +137,7 @@ cc_test( srcs = ["network_test.cc"], deps = [ ":network", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -130,7 +147,9 @@ cc_test( size = "small", srcs = ["util_test.cc"], deps = [ + ":crypto_core", ":network", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -139,7 +158,11 @@ cc_library( name = "ping_array", srcs = ["ping_array.c"], hdrs = ["ping_array.h"], - deps = [":network"], + deps = [ + ":crypto_core", + ":mono_time", + ":network", + ], ) cc_test( @@ -147,7 +170,9 @@ cc_test( size = "small", srcs = ["ping_array_test.cc"], deps = [ + ":mono_time", ":ping_array", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -164,10 +189,15 @@ cc_library( "LAN_discovery.h", "ping.h", ], - visibility = ["//c-toxcore/other/bootstrap_daemon:__pkg__"], + visibility = [ + "//c-toxcore/other/bootstrap_daemon:__pkg__", + "//c-toxcore/testing:__pkg__", + ], deps = [ ":crypto_core", ":logger", + ":mono_time", + ":network", ":ping_array", ":state", ], @@ -179,6 +209,8 @@ cc_test( srcs = ["DHT_test.cc"], deps = [ ":DHT", + ":crypto_core", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -199,6 +231,8 @@ cc_library( ], deps = [ ":logger", + ":mono_time", + ":network", ":ping_array", ":state", ], @@ -208,7 +242,12 @@ cc_library( name = "onion", srcs = ["onion.c"], hdrs = ["onion.h"], - deps = [":DHT"], + deps = [ + ":DHT", + ":crypto_core", + ":mono_time", + ":network", + ], ) cc_library( @@ -227,9 +266,12 @@ cc_library( "//tools/config:linux": ["-DTCP_SERVER_USE_EPOLL=1"], "//conditions:default": [], }), + visibility = ["//c-toxcore/other/bootstrap_daemon:__pkg__"], deps = [ ":crypto_core", ":list", + ":mono_time", + ":network", ":onion", ], ) @@ -240,6 +282,7 @@ cc_test( srcs = ["TCP_connection_test.cc"], deps = [ ":TCP_connection", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -251,6 +294,8 @@ cc_library( deps = [ ":DHT", ":TCP_connection", + ":mono_time", + ":network", ], ) @@ -258,7 +303,13 @@ cc_library( name = "onion_announce", srcs = ["onion_announce.c"], hdrs = ["onion_announce.h"], - deps = [":onion"], + visibility = ["//c-toxcore/other/bootstrap_daemon:__pkg__"], + deps = [ + ":DHT", + ":mono_time", + ":network", + ":onion", + ], ) cc_library( @@ -266,7 +317,10 @@ cc_library( srcs = ["onion_client.c"], hdrs = ["onion_client.h"], deps = [ + ":DHT", + ":mono_time", ":net_crypto", + ":network", ":onion_announce", ], ) @@ -277,7 +331,9 @@ cc_library( hdrs = ["friend_connection.h"], deps = [ ":DHT", + ":mono_time", ":net_crypto", + ":network", ":onion_client", ], ) @@ -288,6 +344,7 @@ cc_test( srcs = ["friend_connection_test.cc"], deps = [ ":friend_connection", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -296,16 +353,26 @@ cc_library( name = "friend_requests", srcs = ["friend_requests.c"], hdrs = ["friend_requests.h"], - deps = [":friend_connection"], + visibility = ["//c-toxcore/testing:__pkg__"], + deps = [ + ":friend_connection", + ":network", + ], ) cc_library( name = "Messenger", srcs = ["Messenger.c"], hdrs = ["Messenger.h"], - visibility = ["//c-toxcore/toxav:__pkg__"], + visibility = [ + "//c-toxcore/testing:__pkg__", + "//c-toxcore/toxav:__pkg__", + ], deps = [ ":friend_requests", + ":logger", + ":mono_time", + ":network", ":state", ], ) @@ -315,20 +382,30 @@ cc_library( srcs = ["group.c"], hdrs = ["group.h"], visibility = ["//c-toxcore/toxav:__pkg__"], - deps = [":Messenger"], + deps = [ + ":Messenger", + ":mono_time", + ":network", + ":state", + ], ) cc_library( name = "toxcore", srcs = [ "tox.c", - "tox.h", "tox_api.c", "tox_private.h", ], + hdrs = ["tox.h"], visibility = ["//c-toxcore:__subpackages__"], deps = [ + ":Messenger", + ":ccompat", ":group", + ":logger", + ":mono_time", + ":network", "//c-toxcore/toxencryptsave:defines", ], )