Run gn check for an android build on presubmit

Also, fix gn check errors.

This is a reland of https://codereview.chromium.org/808703005 with some
additional testing to only run gn check for android when the checkout
contains the android specific dependencies.

R=sky@chromium.org

Review URL: https://codereview.chromium.org/805083007
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index eac0a44..7a3cdc0 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -414,6 +414,7 @@
 
 def _CheckGNCheck(input_api, output_api):
   """Checks that gn gen and gn check pass"""
+  import os.path
 
   class _TemporaryDirectory(object):
     """Context manager for tempfile.mkdtemp()"""
@@ -427,32 +428,44 @@
       import shutil
       shutil.rmtree(self.path)
 
-  with _TemporaryDirectory() as out_dir:
-    try:
-      input_api.subprocess.check_output(['gn', 'gen', out_dir])
-    except input_api.subprocess.CalledProcessError, error:
-      return [output_api.PresubmitError(
-          'gn gen must not fail.', long_text=error.output)]
-
-    # TODO(eseidel): Currently only these are known to pass,
-    # once everything passes we can just call 'gn check' once without a filter!
-    KNOWN_PASSING = [
-      '//examples/*',
-      '//mojo/*',
-      '//services/*',
-      '//shell/*',
-    ]
-    if input_api.platform != 'win32':
-      KNOWN_PASSING += [
-        '//sky/*',
-      ]
-    for target_filter in KNOWN_PASSING:
+  available_os = [None]
+  # android tools directory is used as a sentinel to check if the current
+  # checkout is an android checkout.
+  android_tools_dir = os.path.join(input_api.change.RepositoryRoot(),
+                                   'third_party', 'android_tools')
+  if os.path.isdir(android_tools_dir):
+    available_os.append('android')
+  for target_os in available_os:
+    with _TemporaryDirectory() as out_dir:
       try:
-        input_api.subprocess.check_output(['gn', 'check', out_dir,
-            target_filter])
+        command = ['gn', 'gen', out_dir]
+        if target_os:
+           command.append('--args=%s' % r'''os="android"''')
+        input_api.subprocess.check_output(command)
       except input_api.subprocess.CalledProcessError, error:
-        error_title = 'gn check %s must not fail.' % target_filter
-        return [output_api.PresubmitError(error_title, long_text=error.output)]
+        return [output_api.PresubmitError(
+            'gn gen must not fail.', long_text=error.output)]
+
+      # TODO(eseidel): Currently only these are known to pass, once everything
+      # passes we can just call 'gn check' once without a filter!
+      KNOWN_PASSING = [
+        '//examples/*',
+        '//mojo/*',
+        '//services/*',
+        '//shell/*',
+      ]
+      if input_api.platform != 'win32':
+        KNOWN_PASSING += [
+          '//sky/*',
+        ]
+      for target_filter in KNOWN_PASSING:
+        try:
+          input_api.subprocess.check_output(['gn', 'check', out_dir,
+              target_filter])
+        except input_api.subprocess.CalledProcessError, error:
+          error_title = 'gn check %s must not fail.' % target_filter
+          return [output_api.PresubmitError(error_title,
+                                            long_text=error.output)]
   return []
 
 
diff --git a/examples/device_name/BUILD.gn b/examples/device_name/BUILD.gn
index d534aaa..cbab561 100644
--- a/examples/device_name/BUILD.gn
+++ b/examples/device_name/BUILD.gn
@@ -13,6 +13,7 @@
     "//mojo/public/c/system",
     "//mojo/public/cpp/application:standalone",
     "//mojo/public/cpp/bindings",
+    "//mojo/public/cpp/system",
     "//mojo/public/cpp/utility",
     "//mojo/public/platform/native:system",
     ":jni_headers",
diff --git a/mojo/edk/embedder/BUILD.gn b/mojo/edk/embedder/BUILD.gn
index 3d808d8..d9a6e69 100644
--- a/mojo/edk/embedder/BUILD.gn
+++ b/mojo/edk/embedder/BUILD.gn
@@ -38,9 +38,7 @@
     ":platform",
   ]
 
-  mojo_sdk_public_deps = [
-    "mojo/public/cpp/system",
-  ]
+  mojo_sdk_public_deps = [ "mojo/public/cpp/system" ]
 
   deps = [
     "//base",
@@ -50,13 +48,9 @@
 mojo_edk_source_set("platform") {
   # This isn't really a standalone target; it must be linked into the
   # mojo_system_impl component.
-  visibility = [
-    ":embedder",
-  ]
+  visibility = [ ":embedder" ]
 
-  mojo_edk_visibility = [
-    "mojo/edk/system",
-  ]
+  mojo_edk_visibility = [ "mojo/edk/system" ]
 
   sources = [
     "platform_channel_pair.cc",
@@ -90,6 +84,10 @@
   deps = [
     "//base",
   ]
+
+  if (is_android) {
+    deps += [ "//third_party/ashmem" ]
+  }
 }
 
 mojo_edk_source_set("embedder_unittests") {
diff --git a/mojo/services/network/BUILD.gn b/mojo/services/network/BUILD.gn
index 8143fb8..b8fac0a 100644
--- a/mojo/services/network/BUILD.gn
+++ b/mojo/services/network/BUILD.gn
@@ -24,6 +24,8 @@
 
     deps = [
       ":sources",
+      "//base",
+      "//net",
     ]
   }