aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn4
-rw-r--r--gn/core.gni1
-rwxr-xr-xgn/find_headers.py84
3 files changed, 66 insertions, 23 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 24dc225427..7ae0f6d600 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1013,7 +1013,9 @@ if (skia_enable_tools) {
public_configs = [ ":skia.h_config" ]
skia_h = "$target_gen_dir/skia.h"
script = "gn/find_headers.py"
- args = [ rebase_path(skia_h, root_build_dir) ] +
+ args = [ rebase_path("//bin/gn") ] +
+ [ rebase_path("//") ] +
+ [ rebase_path(skia_h, root_build_dir) ] +
rebase_path(skia_public_includes)
depfile = "$skia_h.deps"
outputs = [
diff --git a/gn/core.gni b/gn/core.gni
index 5aca52cc98..19dbcf42d0 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -392,6 +392,7 @@ skia_core_sources = [
"$_include/core/SkData.h",
"$_include/core/SkDeferredDisplayListRecorder.h",
"$_include/core/SkDeque.h",
+ "$_include/core/SkDocument.h",
"$_include/core/SkDrawable.h",
"$_include/core/SkDrawFilter.h",
"$_include/core/SkDrawLooper.h",
diff --git a/gn/find_headers.py b/gn/find_headers.py
index 2f20e1e7d0..cbb59b5d95 100755
--- a/gn/find_headers.py
+++ b/gn/find_headers.py
@@ -5,43 +5,83 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import collections
+import json
import os
+import subprocess
import sys
-# We'll recursively search each include directory for headers,
-# then write them to skia.h with a small blacklist.
+# Finds all public sources in include directories then write them to skia.h.
-# We'll also write skia.h.deps, which Ninja uses to track dependencies. It's the
+# Also write skia.h.deps, which Ninja uses to track dependencies. It's the
# very same mechanism Ninja uses to know which .h files affect which .cpp files.
-skia_h = sys.argv[1]
-include_dirs = sys.argv[2:]
+gn = sys.argv[1]
+absolute_source = sys.argv[2]
+skia_h = sys.argv[3]
+include_dirs = sys.argv[4:]
-blacklist = {
- "GrGLConfig_chrome.h",
- "SkFontMgr_fontconfig.h",
-}
+absolute_source = os.path.normpath(absolute_source)
-headers = []
-for directory in include_dirs:
- for f in os.listdir(directory):
- if os.path.isfile(os.path.join(directory, f)):
- if f.endswith('.h') and f not in blacklist:
- headers.append(os.path.join(directory,f))
-headers.sort()
+include_dirs = [os.path.join(os.path.normpath(include_dir), '')
+ for include_dir in include_dirs]
+include_dirs.sort(key=len, reverse=True)
-with open(skia_h, "w") as f:
+# If skia ever uses 'public' that will need to be considered as well or instead.
+gn_sources_cmd = [gn, 'desc', '.', '--root=%s' % absolute_source,
+ '--format=json', '*', 'sources']
+
+sources_json_txt = ''
+try:
+ sources_json_txt = subprocess.check_output(gn_sources_cmd)
+except subprocess.CalledProcessError as e:
+ print e.output
+ raise
+
+sources_json = {}
+try:
+ sources_json = json.loads(sources_json_txt)
+except ValueError:
+ print sources_json_txt
+ raise
+
+sources = {os.path.join(absolute_source, os.path.normpath(source[2:]))
+ for target in sources_json.itervalues()
+ for source in target.get('sources', [])}
+
+Header = collections.namedtuple('Header', ['absolute', 'include'])
+headers = {}
+for source in sources:
+ source_as_include = [source[len(include_dir):]
+ for include_dir in include_dirs
+ if source.startswith(include_dir)]
+ if not source_as_include:
+ continue
+ statinfo = os.stat(source)
+ key = str(statinfo.st_ino) + ':' + str(statinfo.st_dev)
+ # On Windows os.stat st_ino is 0 until 3.3.4 and st_dev is 0 until 3.4.0.
+ if key == '0:0':
+ key = source
+ include_path = source_as_include[0]
+ if key not in headers or len(include_path) < len(headers[key].include):
+ headers[key] = Header(source, include_path)
+
+headers = headers.values()
+headers.sort(key=lambda x: x.include)
+
+with open(skia_h, 'w') as f:
f.write('// skia.h generated by GN.\n')
f.write('#ifndef skia_h_DEFINED\n')
f.write('#define skia_h_DEFINED\n')
- for h in headers:
- f.write('#include "' + os.path.basename(h) + '"\n')
+ for header in headers:
+ f.write('#include "' + header.include + '"\n')
f.write('#endif//skia_h_DEFINED\n')
-with open(skia_h + '.deps', "w") as f:
+with open(skia_h + '.deps', 'w') as f:
f.write(skia_h + ':')
- for h in headers:
- f.write(' ' + h)
+ for header in headers:
+ f.write(' ' + header.absolute)
+ f.write(' build.ninja.d')
f.write('\n')
# Temporary: during development this file wrote skia.h.d, not skia.h.deps,