Make libbrillo-dbus compilation optional based on dbus USE flag.

On branches where DBus is not available we need to disable the
compilation of all the targets requiring DBus.

Bug: 25197634
Test: `mmma external/libbrillo` with the BRILLO_USE_DBUS := 0 in the .mk
Test: FEATURES=test emerge-link libbrillo

Change-Id: I4924c93e65ef14c732eea6ee7a73beb118538585
diff --git a/Android.mk b/Android.mk
index 71f906e..1af9778 100644
--- a/Android.mk
+++ b/Android.mk
@@ -12,6 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Default values for the USE flags. Set these variables in your product .mk
+# file.
+BRILLO_USE_DBUS ?= 1
+
 LOCAL_PATH := $(call my-dir)
 
 libbrillo_cpp_extension := .cc
@@ -89,21 +93,9 @@
     brillo/streams/fake_stream.cc \
 
 libbrillo_test_sources := \
-    brillo/any_unittest.cc \
-    brillo/any_internal_impl_unittest.cc \
     brillo/asynchronous_signal_handler_unittest.cc \
     brillo/backoff_entry_unittest.cc \
     brillo/data_encoding_unittest.cc \
-    brillo/dbus/async_event_sequencer_unittest.cc \
-    brillo/dbus/data_serialization_unittest.cc \
-    brillo/dbus/dbus_method_invoker_unittest.cc \
-    brillo/dbus/dbus_object_unittest.cc \
-    brillo/dbus/dbus_param_reader_unittest.cc \
-    brillo/dbus/dbus_param_writer_unittest.cc \
-    brillo/dbus/dbus_signal_handler_unittest.cc \
-    brillo/dbus/exported_object_manager_unittest.cc \
-    brillo/dbus/exported_property_set_unittest.cc \
-    brillo/dbus/test.proto \
     brillo/errors/error_codes_unittest.cc \
     brillo/errors/error_unittest.cc \
     brillo/file_utils_unittest.cc \
@@ -131,11 +123,26 @@
     brillo/streams/stream_utils_unittest.cc \
     brillo/strings/string_utils_unittest.cc \
     brillo/url_utils_unittest.cc \
+
+libbrillo_dbus_test_sources := \
+    brillo/any_unittest.cc \
+    brillo/any_internal_impl_unittest.cc \
+    brillo/dbus/async_event_sequencer_unittest.cc \
+    brillo/dbus/data_serialization_unittest.cc \
+    brillo/dbus/dbus_method_invoker_unittest.cc \
+    brillo/dbus/dbus_object_unittest.cc \
+    brillo/dbus/dbus_param_reader_unittest.cc \
+    brillo/dbus/dbus_param_writer_unittest.cc \
+    brillo/dbus/dbus_signal_handler_unittest.cc \
+    brillo/dbus/exported_object_manager_unittest.cc \
+    brillo/dbus/exported_property_set_unittest.cc \
+    brillo/dbus/test.proto \
     brillo/variant_dictionary_unittest.cc \
 
 libbrillo_CFLAGS := -Wall \
     -Wno-char-subscripts -Wno-missing-field-initializers \
-    -Wno-unused-function -Wno-unused-parameter -Werror
+    -Wno-unused-function -Wno-unused-parameter -Werror \
+    -DUSE_DBUS=$(BRILLO_USE_DBUS)
 libbrillo_CPPFLAGS := -Wno-non-virtual-dtor -Wno-sign-promo \
     -Wno-strict-aliasing
 libbrillo_includes := external/gtest/include
@@ -173,6 +180,8 @@
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
 include $(BUILD_SHARED_LIBRARY)
 
+ifeq ($(BRILLO_USE_DBUS),1)
+
 # Shared dbus library for target
 # ========================================================
 include $(CLEAR_VARS)
@@ -189,6 +198,8 @@
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) external/dbus
 include $(BUILD_SHARED_LIBRARY)
 
+endif  # BRILLO_USE_DBUS == 1
+
 # Shared minijail library for target
 # ========================================================
 include $(CLEAR_VARS)
@@ -317,11 +328,14 @@
     $(libbrillo_includes) \
     $(generated_sources_dir)/proto/external/libbrillo
 LOCAL_STATIC_LIBRARIES := libgtest libchrome_test_helpers \
-    libbrillo-test-helpers libgmock libBionicGtestMain \
-    libchrome_dbus_test_helpers
+    libbrillo-test-helpers libgmock libBionicGtestMain
 LOCAL_SHARED_LIBRARIES := $(libbrillo_shared_libraries) libbrillo libcurl \
-    libbrillo-dbus libbrillo-http libbrillo-stream libcrypto \
-    libchrome-dbus libdbus libprotobuf-cpp-lite-rtti
+    libbrillo-http libbrillo-stream libcrypto libprotobuf-cpp-lite-rtti
+ifeq ($(BRILLO_USE_DBUS),1)
+LOCAL_SRC_FILES += $(libbrillo_dbus_test_sources)
+LOCAL_STATIC_LIBRARIES += libchrome_dbus_test_helpers
+LOCAL_SHARED_LIBRARIES += libbrillo-dbus libchrome-dbus libdbus
+endif  # BRILLO_USE_DBUS == 1
 LOCAL_CFLAGS := $(libbrillo_CFLAGS)
 LOCAL_CPPFLAGS := $(libbrillo_CPPFLAGS) -Wno-sign-compare
 LOCAL_CLANG := true
diff --git a/libbrillo.gypi b/libbrillo.gypi
index e90252b..d0b3504 100644
--- a/libbrillo.gypi
+++ b/libbrillo.gypi
@@ -4,10 +4,14 @@
       'deps': [
         'libchrome-<(libbase_ver)'
       ],
+      'USE_dbus%': '1',
     },
     'include_dirs': [
       '../libbrillo',
     ],
+    'defines': [
+      'USE_DBUS=<(USE_dbus)',
+    ],
   },
   'targets': [
     {
@@ -45,6 +49,8 @@
         },
       },
       'libraries': ['-lmodp_b64'],
+      #TODO(deymo): Split DBus code from libbrillo-core the same way is split in
+      # the Android.mk, based on the <(USE_dbus) variable.
       'sources': [
         'brillo/any.cc',
         'brillo/asynchronous_signal_handler.cc',