OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
4 # for details. All rights reserved. Use of this source code is governed by a | |
5 # BSD-style license that can be found in the LICENSE file. | |
6 # | |
7 # A script which will be invoked from gyp to create an SDK. The SDK will be | |
8 # used either from the command-line or from the editor. Top structure is | |
9 # | |
10 # ..sdk/ | |
11 # ....bin/ | |
12 # ......dart or dart.exe (executable) | |
13 # ......frogc.dart | |
14 # ......frogsh (coming later) | |
15 # ....lib/ | |
16 # ......core/ | |
17 # ........core_{compiler, frog, runtime}.dart | |
18 # ........{compiler, frog, runtime}/ | |
19 # ......coreimpl/ | |
20 # ........coreimpl_{compiler, frog, runtime}.dart | |
21 # ........{compiler, frog, runtime}/ | |
22 # ......dom/ | |
23 # ........dom.dart | |
24 # ......frog/ | |
25 # ......html/ | |
26 # ........html.dart | |
27 # ......htmlimpl/ | |
28 # ........htmlimpl.dart | |
29 # ......(more will come here - io, etc) | |
30 # ....tools/ | |
31 # ......dartdoc/ | |
32 # ......(more will come here) | |
33 | |
34 | |
35 | |
36 import os | |
37 import re | |
38 import sys | |
39 import utils | |
40 | |
41 from os.path import dirname, join, realpath, exists, isdir | |
42 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree | |
43 | |
44 def Main(): | |
45 # Pull in all of the gpyi files which will be munged into the sdk. | |
46 corelib_sources = \ | |
47 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] | |
48 corelib_frog_sources = \ | |
49 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] | |
50 corelib_runtime_sources = \ | |
51 (eval(open("runtime/lib/lib_sources.gypi").read()))['sources'] | |
52 corelib_compiler_sources = \ | |
53 (eval(open("compiler/compiler_corelib_sources.gypi").read())) \ | |
54 ['variables']['compiler_corelib_resources'] | |
55 coreimpl_sources = \ | |
56 (eval(open("corelib/src/implementation/corelib_impl_sources.gypi").read()))\ | |
57 ['sources'] | |
58 coreimpl_frog_sources = \ | |
59 (eval(open("frog/lib/frog_coreimpl_sources.gypi").read()))['sources'] | |
60 coreimpl_runtime_sources = \ | |
61 (eval(open("runtime/lib/lib_impl_sources.gypi").read()))['sources'] | |
62 | |
63 HOME = dirname(dirname(realpath(__file__))) | |
64 | |
65 SDK = join(HOME, 'sdk') | |
66 if exists(SDK): | |
67 rmtree(SDK) | |
68 | |
69 # Create and populate sdk/bin. | |
70 BIN = join(SDK, 'bin') | |
71 os.makedirs(BIN) | |
72 | |
73 # Copy the Dart VM binary into sdk/bin. | |
74 # TODO(dgrove) - deal with architectures that are not ia32 | |
75 build_dir = utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32') | |
76 if utils.GuessOS() == 'win32': | |
77 dart_src_binary = join(join(HOME, build_dir), 'dart.exe') | |
78 dart_dest_binary = join(BIN, 'dart.exe') | |
79 else: | |
80 dart_src_binary = join(join(HOME, build_dir), 'dart') | |
81 dart_dest_binary = join(BIN, 'dart') | |
82 copyfile(dart_src_binary, dart_dest_binary) | |
83 copymode(dart_src_binary, dart_dest_binary) | |
84 | |
85 # Create sdk/bin/frogc.dart, and hack as needed. | |
86 frog_src_dir = join(HOME, 'frog') | |
87 | |
88 # Convert frogc.dart's imports from import('*') -> import('frog/*'). | |
89 frogc_contents = open(join(frog_src_dir, 'frogc.dart')).read() | |
90 frogc_dest = open(join(BIN, 'frogc.dart'), 'w') | |
91 frogc_dest.write( | |
92 re.sub("#import\('", "#import('../lib/frog/", frogc_contents)) | |
93 frogc_dest.close() | |
94 | |
95 # TODO(dgrove): copy and fix up frog.dart, minfrogc.dart | |
96 | |
97 # | |
98 # Create and populate sdk/lib. | |
99 # | |
100 | |
101 LIB = join(SDK, 'lib') | |
102 os.makedirs(LIB) | |
103 corelib_dest_dir = join(LIB, 'core') | |
104 os.makedirs(corelib_dest_dir) | |
105 os.makedirs(join(corelib_dest_dir, 'compiler')) | |
106 os.makedirs(join(corelib_dest_dir, 'frog')) | |
107 os.makedirs(join(corelib_dest_dir, 'runtime')) | |
108 | |
109 coreimpl_dest_dir = join(LIB, 'coreimpl') | |
110 os.makedirs(coreimpl_dest_dir) | |
111 os.makedirs(join(coreimpl_dest_dir, 'compiler')) | |
112 os.makedirs(join(coreimpl_dest_dir, 'frog')) | |
113 os.makedirs(join(coreimpl_dest_dir, 'frog', 'node')) | |
114 os.makedirs(join(coreimpl_dest_dir, 'runtime')) | |
115 | |
116 | |
117 # | |
118 # Create and populate lib/frog. | |
119 # | |
120 frog_dest_dir = join(LIB, 'frog') | |
121 os.makedirs(frog_dest_dir) | |
122 | |
123 for filename in os.listdir(frog_src_dir): | |
124 if filename == 'frog_options.dart': | |
125 # change config from 'dev' to 'sdk' in frog_options.dart | |
126 frog_options_contents = open(join(frog_src_dir, filename)).read() | |
127 frog_options_dest = open(join(frog_dest_dir, filename), 'w') | |
128 frog_options_dest.write(re.sub("final config = \'dev\';", | |
129 "final config = \'sdk\';", | |
130 frog_options_contents)) | |
131 frog_options_dest.close() | |
132 elif filename.endswith('.dart'): | |
133 copyfile(join(frog_src_dir, filename), join(frog_dest_dir, filename)) | |
134 | |
135 copytree(join(frog_src_dir, 'leg'), join(frog_dest_dir, 'leg'), | |
136 ignore=ignore_patterns('.svn')) | |
137 | |
138 # | |
139 # Create and populate lib/html and lib/htmlimpl. | |
140 # | |
141 html_src_dir = join(HOME, 'client', 'html') | |
142 html_dest_dir = join(LIB, 'html') | |
143 os.makedirs(html_dest_dir) | |
144 htmlimpl_dest_dir = join(LIB, 'htmlimpl') | |
145 os.makedirs(htmlimpl_dest_dir) | |
146 | |
147 copyfile(join(html_src_dir, 'release', 'html.dart'), | |
148 join(html_dest_dir, 'html.dart')) | |
149 copyfile(join(html_src_dir, 'release', 'htmlimpl.dart'), | |
150 join(htmlimpl_dest_dir, 'htmlimpl.dart')) | |
151 | |
152 # TODO(dgrove): prune the correct files in html and htmlimpl. | |
153 for target_dir in [html_dest_dir, htmlimpl_dest_dir]: | |
154 copytree(join(html_src_dir, 'src'), join(target_dir, 'src'), | |
155 ignore=ignore_patterns('.svn')) | |
156 copytree(join(html_src_dir, 'generated'), join(target_dir, 'generated'), | |
157 ignore=ignore_patterns('.svn')) | |
158 | |
159 # | |
160 # Create and populate lib/dom. | |
161 # | |
162 dom_src_dir = join(HOME, 'client', 'dom') | |
163 dom_dest_dir = join(LIB, 'dom') | |
164 os.makedirs(dom_dest_dir) | |
165 | |
166 for filename in os.listdir(dom_src_dir): | |
167 src_file = join(dom_src_dir, filename) | |
168 dest_file = join(dom_dest_dir, filename) | |
169 if filename.endswith('.dart') or filename.endswith('.js'): | |
170 copyfile(src_file, dest_file) | |
171 elif isdir(src_file): | |
172 if filename not in ['benchmarks', 'idl', 'scripts', 'snippets', '.svn']: | |
173 copytree(src_file, dest_file, | |
174 ignore=ignore_patterns('.svn', 'interface', 'wrapping', | |
175 '*monkey*')) | |
176 | |
177 # | |
178 # Create and populate lib/core. | |
179 # | |
180 | |
181 # First, copy corelib/* to lib/{compiler, frog, runtime} | |
182 for filename in corelib_sources: | |
183 for target_dir in ['compiler', 'frog', 'runtime']: | |
184 copyfile(join('corelib', 'src', filename), | |
185 join(corelib_dest_dir, target_dir, filename)) | |
186 | |
187 # Next, copy the compiler sources on top of {core,coreimpl}/compiler | |
188 for filename in corelib_compiler_sources: | |
189 if (filename.endswith(".dart")): | |
190 filename = re.sub("lib/","", filename) | |
191 if not filename.startswith("implementation/"): | |
192 copyfile(join('compiler', 'lib', filename), | |
193 join(corelib_dest_dir, 'compiler', filename)) | |
194 | |
195 # Next, copy the frog library source on top of core/frog | |
196 # TOOD(dgrove): move json to top-level | |
197 for filename in corelib_frog_sources: | |
198 copyfile(join('frog', 'lib', filename), | |
199 join(corelib_dest_dir, 'frog', filename)) | |
200 | |
201 # Next, copy the runtime library source on top of core/runtime | |
202 for filename in corelib_runtime_sources: | |
203 if filename.endswith('.dart'): | |
204 copyfile(join('runtime', 'lib', filename), | |
205 join(corelib_dest_dir, 'runtime', filename)) | |
206 | |
207 # | |
208 # At this point, it's time to create lib/core/core*dart . | |
209 # | |
210 # munge frog/lib/corelib.dart into lib/core_frog.dart . | |
211 src_file = join('frog', 'lib', 'corelib.dart') | |
212 dest_file = open(join(corelib_dest_dir, 'core_frog.dart'), 'w') | |
213 contents = open(src_file).read() | |
214 contents = re.sub('source\(\"../../corelib/src/', 'source(\"', contents) | |
215 contents = re.sub("source\(\"", "source(\"frog/", contents) | |
216 dest_file.write(contents) | |
217 dest_file.close() | |
218 | |
219 # construct lib/core_runtimedart from whole cloth. | |
Ivan Posva
2011/12/02 23:17:33
core_runtime.dart
| |
220 dest_file = open(join(corelib_dest_dir, 'core_runtime.dart'), 'w') | |
221 dest_file.write('#library("dart:core");\n') | |
222 dest_file.write('#import("dart:coreimpl");\n') | |
223 for filename in corelib_sources: | |
224 dest_file.write('#source("runtime/' + filename + '");\n') | |
225 for filename in corelib_runtime_sources: | |
226 if filename.endswith('.dart'): | |
227 dest_file.write('#source("runtime/' + filename + '");\n') | |
228 dest_file.close() | |
229 | |
230 # TODO(dgrove) - create lib/core/core_compiler.dart | |
231 | |
232 # | |
233 # Create and populate lib/coreimpl | |
234 # | |
235 | |
236 # First, copy corelib/src/implementation to corelib/{compiler, frog, runtime}. | |
237 for filename in coreimpl_sources: | |
238 for target_dir in ['compiler', 'frog', 'runtime']: | |
239 copyfile(join('corelib', 'src', 'implementation', filename), | |
240 join(coreimpl_dest_dir, target_dir, filename)) | |
241 | |
242 # Next, copy {compiler, frog, runtime}-specific implementations. | |
243 for filename in corelib_compiler_sources: | |
244 if (filename.endswith(".dart")): | |
245 if filename.startswith("lib/implementation/"): | |
246 filename = os.path.basename(filename) | |
247 copyfile(join('compiler', 'lib', 'implementation', filename), | |
248 join(coreimpl_dest_dir, 'compiler', filename)) | |
249 | |
250 for filename in coreimpl_frog_sources: | |
251 copyfile(join('frog', 'lib', filename), | |
252 join(coreimpl_dest_dir, 'frog', filename)) | |
253 | |
254 for filename in coreimpl_runtime_sources: | |
255 if filename.endswith('.dart'): | |
256 copyfile(join('runtime', 'lib', filename), | |
257 join(coreimpl_dest_dir, 'runtime', filename)) | |
258 | |
259 | |
260 # Create and fix up lib/coreimpl/coreimpl_frog.dart . | |
261 src_file = join('frog', 'lib', 'corelib_impl.dart') | |
262 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_frog.dart'), 'w') | |
263 contents = open(src_file).read() | |
264 contents = re.sub('source\(\"../../corelib/src/implementation/', | |
265 'source(\"', contents) | |
266 contents = re.sub('source\(\"', 'source(\"frog/', contents) | |
267 dest_file.write(contents) | |
268 dest_file.close() | |
269 | |
270 # Construct lib/coreimpl/coreimpl_runtime.dart from whole cloth. | |
271 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_runtime.dart'), 'w') | |
272 dest_file.write('#library("dart:coreimpl");\n') | |
273 for filename in coreimpl_sources: | |
274 dest_file.write('#source("runtime/' + filename + '");\n') | |
275 for filename in coreimpl_runtime_sources: | |
276 if filename.endswith('.dart'): | |
277 dest_file.write('#source("runtime/' + filename + '");\n') | |
278 dest_file.close() | |
279 | |
280 # TODO(dgrove) - create lib/coreimpl/coreimpl_compiler.dart | |
281 | |
282 # Create and copy tools. | |
283 | |
284 UTIL = join(SDK, 'tools') | |
285 os.makedirs(UTIL) | |
286 | |
287 copytree(join(HOME, 'utils', 'dartdoc'), join(UTIL, 'dartdoc'), | |
288 ignore=ignore_patterns('.svn')) | |
289 | |
290 if __name__ == '__main__': | |
291 sys.exit(Main()) | |
OLD | NEW |