OLD | NEW |
---|---|
(Empty) | |
1 'touch_file'#!/usr/bin/env python | |
kustermann
2013/01/31 14:35:53
What is this 'touch_file' doing there?
ricow1
2013/01/31 14:42:11
remove 'touch_file'
ahe
2013/02/04 11:12:05
Done.
ahe
2013/02/04 11:12:05
Done.
| |
2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
3 # for details. All rights reserved. Use of this source code is governed by a | |
4 # BSD-style license that can be found in the LICENSE file. | |
5 | |
6 import StringIO | |
7 import os | |
8 import sys | |
9 | |
10 from os.path import join | |
11 | |
12 | |
13 def _print_gypi_files(out, name, files): | |
14 out.write(" '%s': [\n" % name) | |
15 for filename in files: | |
16 out.write(''' r'%s',%s''' % (filename, '\n')) | |
17 out.write(" ],\n") | |
18 | |
19 | |
20 def _close(file_name, output): | |
21 if not isinstance(output, StringIO.StringIO): | |
22 output.close() | |
23 return | |
24 new_text = output.getvalue() | |
25 output.close() | |
26 with open(file_name, 'r') as f: | |
27 old_text = f.read() | |
28 if old_text == new_text: | |
29 return | |
30 with open(file_name, 'w') as f: | |
31 f.write(new_text) | |
32 | |
33 | |
34 def _make_output(fileName): | |
35 if os.path.exists(fileName): | |
36 return StringIO.StringIO() | |
ricow1
2013/01/31 14:42:11
Is it really worth it to create a memory file here
ahe
2013/02/04 11:12:05
I don't understand what you see the alternative is
| |
37 else: | |
38 return file(fileName, 'w') | |
39 | |
40 | |
41 def GenerateGypiFile(sources, outputFile): | |
42 gypi = _make_output(outputFile) | |
43 gypi.write("{\n 'variables': {\n") | |
44 _print_gypi_files(gypi, 'sources', sources) | |
45 gypi.write(" },\n}\n") | |
46 _close(outputFile, gypi) | |
47 | |
48 | |
49 def _list_sources(path, extension): | |
50 sources = [] | |
51 for fullpath, dirs, filenames in os.walk(path): | |
52 remove_me = [d for d in dirs if d.startswith('.')] | |
53 for d in remove_me: | |
ricow1
2013/01/31 14:42:11
what does this do? remove .svn directories?
ahe
2013/02/04 11:12:05
It filters out all directories that start with a d
| |
54 dirs.remove(d) | |
55 for filename in filenames: | |
56 if (filename.endswith(extension)): | |
57 sources.append(os.path.relpath(join(fullpath, filename), | |
58 start='editor/build/generated/')) | |
59 sources.sort() | |
60 return sources | |
61 | |
62 | |
63 def _list_pkgs(path): | |
64 result = None | |
65 for dirpath, dirnames, filenames in os.walk(path): | |
66 result = dirnames[:] # Copy array. | |
67 del dirnames[:] # Stop recursion by clearing array. | |
68 return result | |
69 | |
70 | |
71 def _split_sources(path, extension): | |
72 result = [] | |
73 count = 100 | |
74 segment = -1 | |
75 sources = None | |
76 for source in _list_sources(path, extension): | |
77 if count == 100: | |
78 count = 0 | |
79 segment += 1 | |
80 sources = [] | |
81 result.append(('chunk%s' % segment, sources)) | |
82 sources.append(source) | |
83 count += 1 | |
84 return result | |
85 | |
86 def _print_pkg_action(pkg, out): | |
87 print >> out, """ | |
88 { | |
89 'includes': [ | |
90 '%(pkg)s_sources.gypi', | |
91 ], | |
92 'action_name': '%(pkg)s_action', | |
93 'inputs': [ | |
94 '%(pkg)s_sources.gypi', | |
95 '<@(sources)', | |
96 ], | |
97 'outputs': [ | |
98 '<(SHARED_INTERMEDIATE_DIR)/editor_deps/%(pkg)s.stamp', | |
99 ], | |
100 'action': [ | |
101 'python', | |
102 '../touch_file.py', | |
103 '<@(_outputs)', | |
104 '<@(_inputs)', | |
105 ], | |
106 'message': 'Creating %(pkg)s time stamp.', | |
107 }, | |
108 """ % {'pkg':pkg} | |
109 | |
110 | |
111 def Main(argv): | |
112 # move up to the parent 'dart' directory | |
113 base_directory = join(os.path.dirname(argv[0]), '..', '..') | |
114 os.chdir(base_directory) | |
115 | |
116 pkg_dir = join('editor', 'tools', 'plugins') | |
117 out_dir = join('editor', 'build', 'generated') | |
118 | |
119 if not os.path.exists(out_dir): | |
120 os.mkdir(out_dir) | |
121 | |
122 with open(join(out_dir, 'editor_deps.gyp'), 'w') as gyp: | |
123 stamps = [] | |
124 print >> gyp, """ | |
125 { | |
126 'targets': [ | |
127 { | |
128 'target_name': 'editor_deps', | |
129 'type': 'none', | |
130 'actions': [""" | |
131 for pkg, sources in _split_sources(pkg_dir, '.java'): | |
ricow1
2013/01/31 14:42:11
add a blank line before this, it is hard to read o
ahe
2013/02/04 11:12:05
Done.
| |
132 GenerateGypiFile(sources, join(out_dir, '%s_sources.gypi' % pkg)) | |
133 _print_pkg_action(pkg, gyp) | |
134 stamps.append("'<(SHARED_INTERMEDIATE_DIR)/editor_deps/%s.stamp'" % pkg) | |
135 | |
136 | |
137 print >> gyp, """ | |
138 { | |
139 'action_name': 'editor_stamp_action', | |
140 'inputs': [ | |
141 %s, | |
142 ], | |
143 'outputs': [ | |
144 '<(SHARED_INTERMEDIATE_DIR)/editor_deps/editor.stamp', | |
145 ], | |
146 'action': [ | |
147 'python', | |
148 '../touch_file.py', | |
149 '<@(_outputs)', | |
150 ], | |
151 'message': 'Creating editor time stamp.', | |
152 }, | |
153 ], | |
154 }, | |
155 ], | |
156 } | |
157 """ % (",\n".join(stamps)) | |
158 | |
159 if __name__ == '__main__': | |
160 sys.exit(Main(sys.argv)) | |
OLD | NEW |