[gn] Use target_cc for unsafe_buffers_mappings compiler flag check

When building for Android locally, we would do the check for the
unsafe_buffers_mappings compiler flag on the host version of cc, this
caused local builds where the host cc supported this flag to fail as
Android NDK's version of cc didn't support this flag.

Moved the toolchain target logic so we have access to target_ar,
target_cc, and target_cxx in all BUILD.gn files to share logic, then
used target_cc instead of cc when doing the compiler flag check.

Change-Id: I7a218a645d75493a1e51df5bf178d10d1be0f80b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1380937
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Nathan Sanchez <nathanasanchez@google.com>
diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn
index 3c77ba6..3f54ba4 100644
--- a/gn/BUILDCONFIG.gn
+++ b/gn/BUILDCONFIG.gn
@@ -139,6 +139,26 @@
   }
 }
 
+declare_args() {
+  if (is_android) {
+    _prefix = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin"
+    if (host_os == "win") {
+      target_ar = "$_prefix/llvm-ar.exe"
+      target_cc = "$_prefix/clang.exe --target=$ndk_target$ndk_api -fno-addrsig"
+      target_cxx =
+          "$_prefix/clang++.exe --target=$ndk_target$ndk_api -fno-addrsig"
+    } else {
+      target_ar = "$_prefix/llvm-ar"
+      target_cc = "$_prefix/$ndk_target$ndk_api-clang"
+      target_cxx = "$_prefix/$ndk_target$ndk_api-clang++"
+    }
+  } else {
+    target_ar = ar
+    target_cc = cc
+    target_cxx = cxx
+  }
+}
+
 if (target_os == "win") {
   # By default we look for 2017 (Enterprise, Pro, and Community), then 2015. If MSVC is installed in a
   # non-default location, you can set win_vc to inform us where it is.
diff --git a/gn/skia/BUILD.gn b/gn/skia/BUILD.gn
index c792021..4ba786e 100644
--- a/gn/skia/BUILD.gn
+++ b/gn/skia/BUILD.gn
@@ -644,7 +644,7 @@
     _supports_unsafe_buffers_mappings =
         exec_script("//gn/check_compiler_flag.py",
                     [
-                      cc,
+                      target_cc,
                       "--warning-suppression-mappings=" +
                           _unsafe_buffers_mappings,
                     ],
diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn
index 4357b64..5183b71 100644
--- a/gn/toolchain/BUILD.gn
+++ b/gn/toolchain/BUILD.gn
@@ -7,24 +7,6 @@
   host_cc = cc
   host_cxx = cxx
 
-  if (is_android) {
-    _prefix = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin"
-    if (host_os == "win") {
-      target_ar = "$_prefix/llvm-ar.exe"
-      target_cc = "$_prefix/clang.exe --target=$ndk_target$ndk_api -fno-addrsig"
-      target_cxx =
-          "$_prefix/clang++.exe --target=$ndk_target$ndk_api -fno-addrsig"
-    } else {
-      target_ar = "$_prefix/llvm-ar"
-      target_cc = "$_prefix/$ndk_target$ndk_api-clang"
-      target_cxx = "$_prefix/$ndk_target$ndk_api-clang++"
-    }
-  } else {
-    target_ar = ar
-    target_cc = cc
-    target_cxx = cxx
-  }
-
   cc_wrapper = ""
 
   # dsymutil seems to kill the machine when too many processes are run in