debugd: Conditionally build cellular and WiMAX support.

This CL conditionally compiles cellular and WiMAX support in debugd
based on the 'cellular' and 'wimax' USE flags.

When USE='-cellular', the following DBus methods do nothing and return
an empty response:
  org.chromium.debugd.GetModemStatus
  org.chromium.debugd.RunModemCommand

When USE='-wimax', the following DBus method does nothing and returns an
empty response:
  org.chromium.debugd.GetWiMaxStatus

BUG=chromium:343417
CQ-DEPEND=CL:186350
TEST=Tested the following:
1. `USE='cellular gdmwimax wimax' FEATURES=test emerge-$BOARD platform2`
2. `USE='-cellular -gdmwimax -wimax' FEATURES=test emerge-$BOARD platform2`
3. Verify the following commands return valid output when debugd is
   built with cellular/WiMAX support, and return an empty string when
   debugd is built without cellular/WiMAX support:

     # Test on a system with a Gobi3k modem
     dbus-send --system --print-reply --dest=org.chromium.debugd \
        /org/chromium/debugd org.chromium.debugd.GetModemStatus
     dbus-send --system --print-reply --dest=org.chromium.debugd \
        /org/chromium/debugd org.chromium.debugd.RunModemCommand \
        string:'AT'

     # Test on a system with a WiMAX module
     dbus-send --system --print-reply --dest=org.chromium.debugd \
        /org/chromium/debugd org.chromium.debugd.GetWiMaxStatus

4. Verify the 'modem-status', 'mm-status', and 'wimax-status' section
   under chrome://system report valid information when debugd is built
   with cellular/WiMAX support, and no information when debugd is built
   without cellular/WiMAX support.

Change-Id: Ifd25eb450521719275769d3d1413cf3d4cc43db6
Reviewed-on: https://chromium-review.googlesource.com/186304
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
diff --git a/debugd.gyp b/debugd.gyp
index dfd9958..50ae5fa 100644
--- a/debugd.gyp
+++ b/debugd.gyp
@@ -18,6 +18,10 @@
     "cflags": [
       '-fvisibility=hidden',
     ],
+    'defines': [
+      'USE_CELLULAR=<(USE_cellular)',
+      'USE_WIMAX=<(USE_wimax)',
+    ],
   },
   'targets': [
     {
@@ -118,14 +122,6 @@
       ]
     },
     {
-      'target_name': 'modem_status',
-      'type': 'executable',
-      'dependencies': ['debugd-proxies'],
-      'sources': [
-        'src/helpers/modem_status.cc',
-      ]
-    },
-    {
       'target_name': 'network_status',
       'type': 'executable',
       'dependencies': ['debugd-proxies'],
@@ -133,16 +129,20 @@
         'src/helpers/network_status.cc',
       ]
     },
-    {
-      'target_name': 'wimax_status',
-      'type': 'executable',
-      'dependencies': ['debugd-proxies'],
-      'sources': [
-        'src/helpers/wimax_status.cc',
-      ]
-    },
   ],
   'conditions': [
+    ['USE_cellular == 1', {
+      'targets': [
+        {
+          'target_name': 'modem_status',
+          'type': 'executable',
+          'dependencies': ['debugd-proxies'],
+          'sources': [
+            'src/helpers/modem_status.cc',
+          ]
+        },
+      ],
+    }],
     ['USE_test == 1', {
       'targets': [
         {
@@ -161,5 +161,17 @@
         },
       ],
     }],
+    ['USE_wimax == 1', {
+      'targets': [
+        {
+          'target_name': 'wimax_status',
+          'type': 'executable',
+          'dependencies': ['debugd-proxies'],
+          'sources': [
+            'src/helpers/wimax_status.cc',
+          ]
+        },
+      ],
+    }],
   ],
 }
diff --git a/src/log_tool.cc b/src/log_tool.cc
index 3e963ab..f743170 100644
--- a/src/log_tool.cc
+++ b/src/log_tool.cc
@@ -175,14 +175,18 @@
 };
 
 static const Log extra_logs[] = {
+#if USE_CELLULAR
   { "mm-status", "/usr/bin/modem status" },
+#endif  // USE_CELLULAR
   { "network-devices", "/usr/bin/connectivity show devices" },
   { "network-services", "/usr/bin/connectivity show services" },
   { NULL, NULL }
 };
 
 static const Log feedback_logs[] = {
+#if USE_CELLULAR
   { "mm-status", "/usr/bin/modem status-feedback" },
+#endif  // USE_CELLULAR
   { "network-devices", "/usr/bin/connectivity show-feedback devices" },
   { "network-services", "/usr/bin/connectivity show-feedback services" },
   { NULL, NULL }
diff --git a/src/modem_status_tool.cc b/src/modem_status_tool.cc
index 030ce6f..9bf3e7b 100644
--- a/src/modem_status_tool.cc
+++ b/src/modem_status_tool.cc
@@ -16,6 +16,9 @@
 ModemStatusTool::~ModemStatusTool() { }
 
 std::string ModemStatusTool::GetModemStatus(DBus::Error& error) { // NOLINT
+  if (!USE_CELLULAR)
+    return "";
+
   char *envvar = getenv("DEBUGD_HELPERS");
   std::string path = StringPrintf("%s/modem_status", envvar ? envvar
                                   : "/usr/libexec/debugd/helpers");
@@ -31,6 +34,9 @@
 }
 
 string ModemStatusTool::RunModemCommand(const string& command) {
+  if (!USE_CELLULAR)
+    return "";
+
   if (command == "get-oma-status") {
     return SendATCommand("AT+OMADM=?");
   }
@@ -54,6 +60,9 @@
 }
 
 string ModemStatusTool::SendATCommand(const string& command) {
+  if (!USE_CELLULAR)
+    return "";
+
   char *envvar = getenv("DEBUGD_HELPERS");
   string path = StringPrintf("%s/send_at_command.sh",
                              envvar ? envvar : "/usr/libexec/debugd/helpers");
diff --git a/src/wimax_status_tool.cc b/src/wimax_status_tool.cc
index fb4bd6f..9c3f1aa 100644
--- a/src/wimax_status_tool.cc
+++ b/src/wimax_status_tool.cc
@@ -14,6 +14,9 @@
 WiMaxStatusTool::~WiMaxStatusTool() {}
 
 std::string WiMaxStatusTool::GetWiMaxStatus(DBus::Error& error) {  // NOLINT
+  if (!USE_WIMAX)
+    return "";
+
   char *envvar = getenv("DEBUGD_HELPERS");
   std::string path = StringPrintf("%s/wimax_status", envvar ? envvar
                                   : "/usr/libexec/debugd/helpers");