Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: dart/editor/build/generate_sources.py

Issue 12090092: Build the Editor from GYP/build.py. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/editor/build/.gitignore ('k') | dart/editor/build/truncate_files.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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()
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 # Skip directories that start with a dot, such as ".svn".
53 remove_me = [d for d in dirs if d.startswith('.')]
54 for d in remove_me:
55 dirs.remove(d)
56
57 for filename in filenames:
58 if (filename.endswith(extension)):
59 sources.append(os.path.relpath(join(fullpath, filename),
60 start='editor/build/generated/'))
61 sources.sort()
62 return sources
63
64
65 def _list_pkgs(path):
66 result = None
67 for dirpath, dirnames, filenames in os.walk(path):
68 result = dirnames[:] # Copy array.
69 del dirnames[:] # Stop recursion by clearing array.
70 return result
71
72
73 def _split_sources(path, extension):
74 result = []
75 count = 100
76 segment = -1
77 sources = None
78 for source in _list_sources(path, extension):
79 if count == 100:
80 count = 0
81 segment += 1
82 sources = []
83 result.append(('chunk%s' % segment, sources))
84 sources.append(source)
85 count += 1
86 return result
87
88 def _print_pkg_action(pkg, out):
89 print >> out, """
90 {
91 'includes': [
92 '%(pkg)s_sources.gypi',
93 ],
94 'action_name': '%(pkg)s_action',
95 'inputs': [
96 '%(pkg)s_sources.gypi',
97 '<@(sources)',
98 ],
99 'outputs': [
100 '<(SHARED_INTERMEDIATE_DIR)/editor_deps/%(pkg)s.stamp',
101 ],
102 'action': [
103 'python',
104 '../truncate_files.py',
105 '<@(_outputs)',
106 ],
107 'message': 'Creating %(pkg)s time stamp.',
108 },
109 """ % {'pkg':pkg}
110
111
112 def Main(argv):
113 # move up to the parent 'dart' directory
114 base_directory = join(os.path.dirname(argv[0]), '..', '..')
115 os.chdir(base_directory)
116
117 pkg_dir = join('editor', 'tools', 'plugins')
118 out_dir = join('editor', 'build', 'generated')
119
120 if not os.path.exists(out_dir):
121 os.mkdir(out_dir)
122
123 with open(join(out_dir, 'editor_deps.gyp'), 'w') as gyp:
124 stamps = []
125 print >> gyp, """
126 {
127 'targets': [
128 {
129 'target_name': 'editor_deps',
130 'type': 'none',
131 'actions': ["""
132
133 for pkg, sources in _split_sources(pkg_dir, '.java'):
134 GenerateGypiFile(sources, join(out_dir, '%s_sources.gypi' % pkg))
135 _print_pkg_action(pkg, gyp)
136 stamps.append("'<(SHARED_INTERMEDIATE_DIR)/editor_deps/%s.stamp'" % pkg)
137
138 print >> gyp, """
139 {
140 'action_name': 'editor_stamp_action',
141 'inputs': [
142 %s,
143 ],
144 'outputs': [
145 '<(SHARED_INTERMEDIATE_DIR)/editor_deps/editor.stamp',
146 ],
147 'action': [
148 'python',
149 '../truncate_files.py',
150 '<@(_outputs)',
151 ],
152 'message': 'Creating editor time stamp.',
153 },
154 ],
155 },
156 ],
157 }
158 """ % (",\n".join(stamps))
159
160 if __name__ == '__main__':
161 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « dart/editor/build/.gitignore ('k') | dart/editor/build/truncate_files.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698