gn2bp: unconditionally remove -DANDROID for all host targets

It turns out, -DANDROID was not consistently applied across the chromium
code base, so it was removed for some targets where it shouldn't have
been.
Adding it to the host defaults solves this problem.

Test: //components/android/cronet:cronet
Change-Id: Ieff81727410c47a0d90d22b56348c6773f653a25
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 4687c4a..87f3931 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -202,7 +202,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -258,7 +257,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -920,7 +918,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -1142,7 +1139,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -1442,7 +1438,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -1475,7 +1470,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -1789,7 +1783,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -1822,7 +1815,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -1849,7 +1841,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -1882,7 +1873,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -1919,7 +1909,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -1928,13 +1917,6 @@
         "buildtools/third_party/libc++abi/trunk/include",
     ],
     cpp_std: "c++20",
-    target: {
-        host: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //base/third_party/xdg_mime:xdg_mime
@@ -1973,7 +1955,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -1982,13 +1963,6 @@
         "buildtools/third_party/libc++abi/trunk/include",
     ],
     cpp_std: "c++20",
-    target: {
-        host: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //base/third_party/xdg_user_dirs:xdg_user_dirs
@@ -2022,7 +1996,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -2031,13 +2004,6 @@
         "buildtools/third_party/libc++abi/trunk/include",
     ],
     cpp_std: "c++20",
-    target: {
-        host: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //base:tracing_buildflags
@@ -2528,18 +2494,6 @@
         "-fexceptions",
     ],
     rtti: true,
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //components/cronet/android:cronet_jni_headers
@@ -3261,18 +3215,6 @@
         "jni_headers",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //crypto:buildflags
@@ -3359,7 +3301,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -3409,7 +3350,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
             local_include_dirs: [
                 "build/linux/debian_bullseye_amd64-sysroot/usr/include/nspr",
@@ -3438,6 +3378,13 @@
         "-fvisibility=hidden",
     ],
     stl: "none",
+    target: {
+        host: {
+            cflags: [
+                "-UANDROID",
+            ],
+        },
+    },
 }
 
 // GN: //ipc:param_traits
@@ -4742,17 +4689,11 @@
             srcs: [
                 "net/disk_cache/blockfile/mapped_file_posix.cc",
             ],
-            cflags: [
-                "-UANDROID",
-            ],
         },
         android_x86_64: {
             srcs: [
                 "net/disk_cache/blockfile/mapped_file_bypass_mmap_posix.cc",
             ],
-            cflags: [
-                "-UANDROID",
-            ],
         },
     },
 }
@@ -5043,18 +4984,6 @@
         "third_party/boringssl/src/include/",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //net/third_party/quiche:net_quic_proto
@@ -5600,18 +5529,6 @@
         "third_party/zlib/",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //net/traffic_annotation:traffic_annotation
@@ -5707,18 +5624,6 @@
         "third_party/boringssl/src/include/",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/abseil-cpp:absl
@@ -7568,7 +7473,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -7602,7 +7506,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -7725,18 +7628,6 @@
         "third_party/brotli/include/",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/brotli:dec
@@ -7780,18 +7671,6 @@
         "third_party/brotli/include/",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/brotli:headers
@@ -8074,7 +7953,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -8110,7 +7988,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -8351,7 +8228,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -8387,7 +8263,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -8433,7 +8308,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -8472,7 +8346,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
             local_include_dirs: [
                 "third_party/libevent/linux/",
@@ -8643,7 +8516,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -8676,7 +8548,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -8802,7 +8673,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -8813,13 +8683,6 @@
         "third_party/zlib/",
     ],
     cpp_std: "c++20",
-    target: {
-        host: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/protobuf:protobuf_lite
@@ -8892,18 +8755,6 @@
         "third_party/protobuf/src/",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/protobuf:protoc
@@ -8952,7 +8803,6 @@
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"default\")))",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -8967,13 +8817,6 @@
         "-fexceptions",
     ],
     rtti: true,
-    target: {
-        host: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/protobuf:protoc_lib
@@ -9097,7 +8940,6 @@
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-UANDROID",
     ],
     local_include_dirs: [
         "./",
@@ -9107,13 +8949,6 @@
         "third_party/protobuf/src/",
     ],
     cpp_std: "c++20",
-    target: {
-        host: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //third_party/zlib:zlib
@@ -9166,7 +9001,6 @@
         "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D__STDC_CONSTANT_MACROS",
         "-D__STDC_FORMAT_MACROS",
-        "-UANDROID",
         "-mpclmul",
         "-mssse3",
     ],
@@ -9210,7 +9044,6 @@
                 "-D_FILE_OFFSET_BITS=64",
                 "-D_LARGEFILE64_SOURCE",
                 "-D_LARGEFILE_SOURCE",
-                "-UANDROID",
             ],
         },
     },
@@ -9409,18 +9242,6 @@
         "jni_headers",
     ],
     cpp_std: "c++20",
-    target: {
-        android_x86: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-        android_x86_64: {
-            cflags: [
-                "-UANDROID",
-            ],
-        },
-    },
 }
 
 // GN: //url:url_jni_headers
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index cf8a4fd..ac54f64 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -959,12 +959,6 @@
   cflags = {flag for flag in cflags if flag in cflag_allowlist}
   # Consider proper allowlist or denylist if needed
   cflags |= set("-D%s" % define.replace("\"", "\\\"") for define in defines)
-  # -DANDROID is added by default but target.defines contain -DANDROID if it's required.
-  # So adding -UANDROID to cancel default -DANDROID if it's not specified.
-  # This is needed for some targets(e.g. symbolize)
-  # TODO: Set -UANDROID considering common define
-  if "ANDROID" not in defines:
-    cflags.add("-UANDROID")
   return cflags
 
 def set_module_flags(module, cflags, defines):
@@ -1222,6 +1216,14 @@
       '-Wno-unreachable-code-loop-increment', # needed for icui18n
       '-O2',
   ]
+  defaults.target['host'].cflags = [
+      # -DANDROID is added by default but target.defines contain -DANDROID if
+      # it's required.  So adding -UANDROID to cancel default -DANDROID if it's
+      # not specified.
+      # Note: -DANDROID is not consistently applied across the chromium code
+      # base, so it is removed unconditionally for host targets.
+      '-UANDROID',
+  ]
   defaults.stl = 'none'
   blueprint.add_module(defaults)