8from __future__
import print_function
22absolute_source = sys.argv[2]
24include_dirs = sys.argv[4:]
26absolute_source = os.path.normpath(absolute_source)
28include_dirs = [os.path.join(os.path.normpath(include_dir),
'')
29 for include_dir
in include_dirs]
30include_dirs.sort(key=len, reverse=
True)
32gn_desc_cmd = [gn,
'desc',
'.',
'--root=%s' % absolute_source,
'--format=json',
37 desc_json_txt = subprocess.check_output(gn_desc_cmd).
decode(
'utf-8')
38except subprocess.CalledProcessError
as e:
39 print(e.output.decode(
'utf-8'))
42if desc_json_txt.startswith(
'WARNING'):
43 print(
'\ngn generated a warning when we asked for JSON output.',
44 'To see the warning, run this command from the out_dir:',
45 '(you may need to quote the * argument)\n',
46 ' '.join(gn_desc_cmd),
52 desc_json = json.loads(desc_json_txt)
59for target
in desc_json.values():
63 search_list = target.get(
'public')
64 if search_list ==
'*':
65 search_list = target.get(
'sources', [])
67 for name
in search_list:
68 sources.add(os.path.join(absolute_source, os.path.normpath(name[2:])))
70Header = collections.namedtuple(
'Header', [
'absolute',
'include'])
73 source_as_include = [os.path.relpath(source, absolute_source)
74 for include_dir
in include_dirs
75 if source.startswith(include_dir)]
76 if not source_as_include:
78 statinfo = os.stat(source)
79 key = str(statinfo.st_ino) +
':' + str(statinfo.st_dev)
83 include_path = source_as_include[0]
84 if key
not in headers
or len(include_path) <
len(headers[key].include):
85 headers[key] =
Header(source, include_path)
87headers = sorted(headers.values(), key=
lambda x: x.include)
89with open(skia_h,
'w')
as f:
90 f.write(
'// skia.h generated by GN.\n')
91 f.write(
'#ifndef skia_h_DEFINED\n')
92 f.write(
'#define skia_h_DEFINED\n')
93 for header
in headers:
94 f.write(
'#include "' + header.include +
'"\n')
95 f.write(
'#endif//skia_h_DEFINED\n')
97with open(skia_h +
'.deps',
'w')
as f:
99 for header
in headers:
100 f.write(
' ' + header.absolute)
101 f.write(
' build.ninja.d')
106if os.path.exists(skia_h +
'.d'):
107 os.remove(skia_h +
'.d')
static DecodeResult decode(std::string path)