GN

What we've got here is a little GN MVP.  It's lacking any knobs and doesn't yet build anything but libskia, zlib, libpng, and libjpeg-turbo.  I've been hopping back and forth between Linux at work and Mac at home.  These seem to be at least partially working, enough to build and run cmake/example.cpp.

The xcode backend seems to work.  From here, we can start exploring how to handle other backends (cmake,Android make, Google3).  There are a couple things I want to try:
  - add another backend like vs or xcode to GN directly
  - intercept via a custom toolchain
  - reverse from ninja -t commands
That last option seems kind of fun.

This tries to piggyback on Chrome's GN setup as much as possible.  Chrome's got quite a lot figured out, and we're basically required to do this if we want to have a single GN build system shareable by Chrome, our bots, and other clients.

This pulls in some new DEPS:
   - build: Chrome's GN configuration, and much more
   - buildtools: hashes for gn binary, pulled via hooks
   - tools/clang: hashes for Chrome's clang, pulled via hooks into third_party/llvm-build
It additionally symlinks tools/gyp to third_party/externals/gyp.  GN pulls some stuff from tools/gyp on Mac.

Have not yet tried building for Windows, Android, or iOS.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2087593002

Review-Url: https://codereview.chromium.org/2087593002
diff --git a/.gitignore b/.gitignore
index 9fb5a30..ad2470e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,3 +30,8 @@
 tools/skp/page_sets/data/*.json
 tools/skp/page_sets/data/*.wpr
 xcodebuild
+
+build
+buildtools
+tools/clang
+third_party/llvm-build
diff --git a/.gn b/.gn
new file mode 100644
index 0000000..c6fefba
--- /dev/null
+++ b/.gn
@@ -0,0 +1 @@
+buildconfig = "//build/config/BUILDCONFIG.gn"
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000..9af046a
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,265 @@
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("build/config/linux/pkg_config.gni")
+
+declare_args() {
+}
+
+# Skia public API, generally provided by :skia.
+config("skia_public") {
+  include_dirs = [
+    "include/c",
+    "include/config",
+    "include/core",
+    "include/effects",
+    "include/gpu",
+    "include/images",
+    "include/lazy",
+    "include/pathops",
+    "include/ports",
+    "include/utils",
+    "include/utils/mac",
+  ]
+  defines = [ "SKIA_DLL" ]
+}
+
+# Skia internal APIs, used by Skia itself and a few test tools.
+config("skia_private") {
+  visibility = [ ":*" ]
+
+  include_dirs = [
+    "include/private",
+    "src/c",
+    "src/config",
+    "src/core",
+    "src/effects",
+    "src/gpu",
+    "src/image",
+    "src/images",
+    "src/lazy",
+    "src/opts",
+    "src/pathops",
+    "src/ports",
+    "src/sfnt",
+    "src/utils",
+    "third_party/etc1",
+    "third_party/ktx",
+  ]
+}
+
+# Any code that's linked into Skia-the-library should use this config via += skia_library_configs.
+config("skia_library") {
+  visibility = [ ":*" ]
+
+  cflags = [
+    "-Winit-self",
+    "-Wpointer-arith",
+    "-Wsign-compare",
+    "-Wvla",
+    "-fstrict-aliasing",
+  ]
+  cflags_cc = [ "-Wnon-virtual-dtor" ]
+
+  defines = [ "SKIA_IMPLEMENTATION=1" ]
+}
+
+skia_library_configs = [
+  ":skia_public",
+  ":skia_private",
+  ":skia_library",
+]
+
+# Chrome's GN environment is mostly helpful, but a couple default configs tend to get in the way.
+unwanted_configs = [
+  "//build/config/clang:find_bad_constructs",  # Chrome style checks.
+  "//build/config:feature_flags",  # A bunch of #defines we don't care about.
+]
+
+core_gypi = exec_script("build/gypi_to_gn.py",
+                        [
+                          rebase_path("gyp/core.gypi"),
+                          "--replace=<(skia_include_path)=include",
+                          "--replace=<(skia_src_path)=src",
+                        ],
+                        "scope",
+                        [ "gyp/core.gypi" ])
+
+effects_gypi = exec_script("build/gypi_to_gn.py",
+                           [
+                             rebase_path("gyp/effects.gypi"),
+                             "--replace=<(skia_include_path)=include",
+                             "--replace=<(skia_src_path)=src",
+                           ],
+                           "scope",
+                           [ "gyp/effects.gypi" ])
+
+gpu_gypi = exec_script("build/gypi_to_gn.py",
+                       [
+                         rebase_path("gyp/gpu.gypi"),
+                         "--replace=<(skia_include_path)=include",
+                         "--replace=<(skia_src_path)=src",
+                       ],
+                       "scope",
+                       [ "gyp/gpu.gypi" ])
+
+opts_gypi = exec_script("build/gypi_to_gn.py",
+                        [
+                          rebase_path("gyp/opts.gypi"),
+                          "--replace=<(skia_include_path)=include",
+                          "--replace=<(skia_src_path)=src",
+                        ],
+                        "scope",
+                        [ "gyp/opts.gypi" ])
+
+pdf_gypi = exec_script("build/gypi_to_gn.py",
+                       [
+                         rebase_path("gyp/pdf.gypi"),
+                         "--replace=<(skia_include_path)=include",
+                         "--replace=<(skia_src_path)=src",
+                       ],
+                       "scope",
+                       [ "gyp/pdf.gypi" ])
+
+utils_gypi = exec_script("build/gypi_to_gn.py",
+                         [
+                           rebase_path("gyp/utils.gypi"),
+                           "--replace=<(skia_include_path)=include",
+                           "--replace=<(skia_src_path)=src",
+                         ],
+                         "scope",
+                         [ "gyp/utils.gypi" ])
+
+source_set("opts_ssse3") {
+  configs += skia_library_configs
+  configs -= unwanted_configs
+
+  sources = opts_gypi.ssse3_sources
+  cflags = [ "-mssse3" ]
+}
+
+source_set("opts_sse41") {
+  configs += skia_library_configs
+  configs -= unwanted_configs
+
+  sources = opts_gypi.sse41_sources
+  cflags = [ "-msse4.1" ]
+}
+
+component("skia") {
+  public_configs = [ ":skia_public" ]
+  configs += skia_library_configs
+  configs -= unwanted_configs
+
+  deps = [
+    ":opts_sse41",
+    ":opts_ssse3",
+    "third_party:zlib",
+  ]
+
+  libs = []
+
+  sources = []
+  sources += core_gypi.sources
+  sources += effects_gypi.sources
+  sources += gpu_gypi.skgpu_sources
+  sources += opts_gypi.sse2_sources
+  sources += pdf_gypi.sources
+  sources += utils_gypi.sources
+  sources += [
+    "src/images/SkImageEncoder.cpp",
+    "src/images/SkImageEncoder_Factory.cpp",
+    "src/ports/SkDiscardableMemory_none.cpp",
+    "src/ports/SkGlobalInitialization_default.cpp",
+    "src/ports/SkImageGenerator_none.cpp",
+    "src/ports/SkMemory_malloc.cpp",
+    "src/ports/SkOSFile_stdio.cpp",
+    "src/sfnt/SkOTTable_name.cpp",
+    "src/sfnt/SkOTUtils.cpp",
+    "src/utils/mac/SkStream_mac.cpp",
+    "third_party/etc1/etc1.cpp",
+    "third_party/ktx/ktx.cpp",
+  ]
+
+  if (is_win) {
+    sources += [
+      "src/ports/SkDebug_win.cpp",
+      "src/ports/SkFontHost_win.cpp",
+      "src/ports/SkFontMgr_win_dw.cpp",
+      "src/ports/SkFontMgr_win_dw_factory.cpp",
+      "src/ports/SkImageEncoder_WIC.cpp",
+      "src/ports/SkImageGeneratorWIC.cpp",
+      "src/ports/SkOSFile_win.cpp",
+      "src/ports/SkScalerContext_win_dw.cpp",
+      "src/ports/SkTLS_win.cpp",
+      "src/ports/SkTypeface_win_dw.cpp",
+    ]
+  } else {
+    sources += [
+      "src/ports/SkDebug_stdio.cpp",
+      "src/ports/SkOSFile_posix.cpp",
+      "src/ports/SkTLS_pthread.cpp",
+    ]
+  }
+
+  if (is_linux) {
+    deps += [
+      ":fontconfig",
+      ":freetype2",
+      "third_party:libjpeg-turbo",
+      "third_party:libpng",
+    ]
+    sources += [
+      "src/fonts/SkFontMgr_fontconfig.cpp",
+      "src/images/SkJPEGImageEncoder.cpp",
+      "src/images/SkJPEGWriteUtility.cpp",
+      "src/images/SkPNGImageEncoder.cpp",
+      "src/ports/SkFontConfigInterface_direct.cpp",
+      "src/ports/SkFontConfigInterface_direct_factory.cpp",
+      "src/ports/SkFontHost_FreeType.cpp",
+      "src/ports/SkFontHost_FreeType_common.cpp",
+      "src/ports/SkFontHost_fontconfig.cpp",
+    ]
+  }
+
+  if (is_mac) {
+    sources += [
+      "src/ports/SkFontHost_mac.cpp",
+      "src/ports/SkImageEncoder_CG.cpp",
+      "src/ports/SkImageGeneratorCG.cpp",
+    ]
+    libs += [ "ApplicationServices.framework" ]
+  }
+}
+
+executable("example") {
+  configs -= unwanted_configs
+
+  sources = [
+    "cmake/example.cpp",
+  ]
+  deps = [
+    ":skia",
+  ]
+
+  libs = []
+  if (is_mac) {
+    libs += [ "OpenGL.framework" ]
+  }
+}
+
+pkg_config("system_freetype2") {
+  packages = [ "freetype2" ]
+}
+group("freetype2") {
+  public_configs = [ ":system_freetype2" ]
+}
+
+pkg_config("system_fontconfig") {
+  packages = [ "fontconfig" ]
+}
+group("fontconfig") {
+  public_configs = [ ":system_fontconfig" ]
+}
diff --git a/DEPS b/DEPS
index 9504771..539b6a8 100644
--- a/DEPS
+++ b/DEPS
@@ -3,6 +3,10 @@
 # Dependencies on outside packages.
 #
 deps = {
+  "build":  "https://chromium.googlesource.com/chromium/src/build.git@54b609cc558d57003c7a7d657edcc25a3879bf78",
+  "buildtools": "https://chromium.googlesource.com/chromium/buildtools.git@3780bc523aad1d68a5bd00e05c453a80b2ba0b35",
+  "tools/clang": "https://chromium.googlesource.com/chromium/src/tools/clang.git@ea64c667cd841b2c3268bd7dfd223269f3ea23ba",
+
   "common": "https://skia.googlesource.com/common.git@c282fe0b6e392b14f88d647cbd86e1a3ef5498e0",
 
   # There is some duplication here that might be worth cleaning up:
@@ -63,3 +67,54 @@
 }
 
 recursedeps = [ "common" ]
+
+hooks = [
+  # Download GN.
+  {
+    'name': 'gn_win',
+    'action': [ 'download_from_google_storage',
+                '--quiet',
+                '--no_resume',
+                '--platform=win32',
+                '--no_auth',
+                '--bucket', 'chromium-gn',
+                '-s', 'buildtools/win/gn.exe.sha1',
+    ],
+  },
+  {
+    'name': 'gn_mac',
+    'pattern': '.',
+    'action': [ 'download_from_google_storage',
+                '--quiet',
+                '--no_resume',
+                '--platform=darwin',
+                '--no_auth',
+                '--bucket', 'chromium-gn',
+                '-s', 'buildtools/mac/gn.sha1',
+    ],
+  },
+  {
+    'name': 'gn_linux64',
+    'pattern': '.',
+    'action': [ 'download_from_google_storage',
+                '--quiet',
+                '--no_resume',
+                '--platform=linux*',
+                '--no_auth',
+                '--bucket', 'chromium-gn',
+                '-s', 'buildtools/linux64/gn.sha1',
+    ],
+  },
+  # Download Clang.
+  {
+    'name': 'clang',
+    'pattern': '.',
+    'action': [ 'python', 'tools/clang/scripts/update.py', '--if-needed' ],
+  },
+  # Download Linux sysroot.
+  {
+    'name': 'sysroot',
+    'pattern': '.',
+    'action': [ 'python', 'build/linux/sysroot_scripts/install-sysroot.py', '--arch=amd64' ],
+  },
+]
diff --git a/build_overrides/build.gni b/build_overrides/build.gni
new file mode 100644
index 0000000..72cf19a
--- /dev/null
+++ b/build_overrides/build.gni
@@ -0,0 +1,3 @@
+mac_sdk_min_build_override           = "10.10"
+mac_deployment_target_build_override = "10.7"
+
diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn
new file mode 100644
index 0000000..c631ee2
--- /dev/null
+++ b/third_party/BUILD.gn
@@ -0,0 +1,134 @@
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+declare_args() {
+}
+
+# Most third_party code should disable warnings: if we don't maintain the code, warnings are noise.
+config("no_warnings") {
+  cflags = [ "-w" ]
+}
+third_party_configs = [ ":no_warnings" ]
+
+# Chrome's GN environment sets up a bunch of default configs we don't need/want here.
+unwanted_configs = [
+  "//build/config/clang:extra_warnings",
+  "//build/config/clang:find_bad_constructs",
+  "//build/config/compiler:chromium_code",
+  "//build/config:feature_flags",
+]
+
+config("zlib_public") {
+  include_dirs = [ "externals/zlib" ]
+}
+source_set("zlib") {
+  public_configs = [ ":zlib_public" ]
+  configs += third_party_configs
+  configs -= unwanted_configs
+
+  sources = [
+    "externals/zlib/adler32.c",
+    "externals/zlib/compress.c",
+    "externals/zlib/crc32.c",
+    "externals/zlib/deflate.c",
+    "externals/zlib/gzclose.c",
+    "externals/zlib/gzlib.c",
+    "externals/zlib/gzread.c",
+    "externals/zlib/gzwrite.c",
+    "externals/zlib/infback.c",
+    "externals/zlib/inffast.c",
+    "externals/zlib/inflate.c",
+    "externals/zlib/inftrees.c",
+    "externals/zlib/simd_stub.c",
+    "externals/zlib/trees.c",
+    "externals/zlib/uncompr.c",
+    "externals/zlib/zutil.c",
+  ]
+}
+
+config("libpng_public") {
+  include_dirs = [ "libpng" ]
+}
+source_set("libpng") {
+  public_configs = [ ":libpng_public" ]
+  configs += third_party_configs
+  configs -= unwanted_configs
+
+  deps = [
+    ":zlib",
+  ]
+  sources = [
+    "libpng/png.c",
+    "libpng/pngerror.c",
+    "libpng/pngget.c",
+    "libpng/pngmem.c",
+    "libpng/pngpread.c",
+    "libpng/pngread.c",
+    "libpng/pngrio.c",
+    "libpng/pngrtran.c",
+    "libpng/pngrutil.c",
+    "libpng/pngset.c",
+    "libpng/pngtrans.c",
+    "libpng/pngwio.c",
+    "libpng/pngwrite.c",
+    "libpng/pngwtran.c",
+    "libpng/pngwutil.c",
+  ]
+}
+
+config("libjpeg-turbo_config") {
+  include_dirs = [ "externals/libjpeg-turbo" ]
+}
+source_set("libjpeg-turbo") {
+  public_configs = [ ":libjpeg-turbo_config" ]
+  configs += third_party_configs
+  configs -= unwanted_configs
+
+  sources = [
+    "externals/libjpeg-turbo/jcapimin.c",
+    "externals/libjpeg-turbo/jcapistd.c",
+    "externals/libjpeg-turbo/jccoefct.c",
+    "externals/libjpeg-turbo/jccolor.c",
+    "externals/libjpeg-turbo/jcdctmgr.c",
+    "externals/libjpeg-turbo/jchuff.c",
+    "externals/libjpeg-turbo/jcinit.c",
+    "externals/libjpeg-turbo/jcmainct.c",
+    "externals/libjpeg-turbo/jcmarker.c",
+    "externals/libjpeg-turbo/jcmaster.c",
+    "externals/libjpeg-turbo/jcomapi.c",
+    "externals/libjpeg-turbo/jcparam.c",
+    "externals/libjpeg-turbo/jcphuff.c",
+    "externals/libjpeg-turbo/jcprepct.c",
+    "externals/libjpeg-turbo/jcsample.c",
+    "externals/libjpeg-turbo/jdapimin.c",
+    "externals/libjpeg-turbo/jdapistd.c",
+    "externals/libjpeg-turbo/jdcoefct.c",
+    "externals/libjpeg-turbo/jdcolor.c",
+    "externals/libjpeg-turbo/jddctmgr.c",
+    "externals/libjpeg-turbo/jdhuff.c",
+    "externals/libjpeg-turbo/jdinput.c",
+    "externals/libjpeg-turbo/jdmainct.c",
+    "externals/libjpeg-turbo/jdmarker.c",
+    "externals/libjpeg-turbo/jdmaster.c",
+    "externals/libjpeg-turbo/jdmerge.c",
+    "externals/libjpeg-turbo/jdphuff.c",
+    "externals/libjpeg-turbo/jdpostct.c",
+    "externals/libjpeg-turbo/jdsample.c",
+    "externals/libjpeg-turbo/jerror.c",
+    "externals/libjpeg-turbo/jfdctflt.c",
+    "externals/libjpeg-turbo/jfdctfst.c",
+    "externals/libjpeg-turbo/jfdctint.c",
+    "externals/libjpeg-turbo/jidctflt.c",
+    "externals/libjpeg-turbo/jidctfst.c",
+    "externals/libjpeg-turbo/jidctint.c",
+    "externals/libjpeg-turbo/jidctred.c",
+    "externals/libjpeg-turbo/jmemmgr.c",
+    "externals/libjpeg-turbo/jmemnobs.c",
+    "externals/libjpeg-turbo/jquant1.c",
+    "externals/libjpeg-turbo/jquant2.c",
+    "externals/libjpeg-turbo/jsimd_none.c",
+    "externals/libjpeg-turbo/jutils.c",
+  ]
+}
diff --git a/tools/gyp b/tools/gyp
new file mode 120000
index 0000000..d871f5b
--- /dev/null
+++ b/tools/gyp
@@ -0,0 +1 @@
+../third_party/externals/gyp/
\ No newline at end of file