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