| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 # | 6 # |
| 7 # A script which will be invoked from gyp to create an SDK. | 7 # A script which will be invoked from gyp to create an SDK. |
| 8 # | 8 # |
| 9 # Usage: create_sdk.py sdk_directory | 9 # Usage: create_sdk.py sdk_directory |
| 10 # | 10 # |
| 11 # The SDK will be used either from the command-line or from the editor. | 11 # The SDK will be used either from the command-line or from the editor. |
| 12 # Top structure is | 12 # Top structure is |
| 13 # | 13 # |
| 14 # ..dart-sdk/ | 14 # ..dart-sdk/ |
| 15 # ....bin/ | 15 # ....bin/ |
| 16 # ......dart or dart.exe (executable) | 16 # ......dart or dart.exe (executable) |
| 17 # ......frogc.dart | 17 # ......frogc.dart |
| 18 # ......frogsh (coming later) | 18 # ......frogsh (coming later) |
| 19 # ....lib/ | 19 # ....lib/ |
| 20 # ......builtin/ | 20 # ......builtin/ |
| 21 # ........builtin_runtime.dart | 21 # ........builtin_runtime.dart |
| 22 # ......io/ | 22 # ......io/ |
| 23 # ........io_runtime.dart | 23 # ........io_runtime.dart |
| 24 # ........runtime/ | 24 # ........runtime/ |
| 25 # ......core/ | 25 # ......core/ |
| 26 # ........core_{frog, runtime}.dart | 26 # ........core_{frog, runtime}.dart |
| 27 # ........{frog, runtime}/ | 27 # ........{frog, runtime}/ |
| 28 # ......coreimpl/ | 28 # ......coreimpl/ |
| 29 # ........coreimpl_{frog, runtime}.dart | 29 # ........coreimpl_{frog, runtime}.dart |
| 30 # ........{frog, runtime}/ | 30 # ........{frog, runtime}/ |
| 31 # ......dartdoc/ |
| 31 # ......isolate/ | 32 # ......isolate/ |
| 32 # ........isolate_{frog, runtime}.dart | 33 # ........isolate_{frog, runtime}.dart |
| 33 # ........{frog, runtime}/ | 34 # ........{frog, runtime}/ |
| 34 # ......dom/ | 35 # ......dom/ |
| 35 # ........dom.dart | 36 # ........dom.dart |
| 36 # ......frog/ | 37 # ......frog/ |
| 37 # ......html/ | 38 # ......html/ |
| 38 # ........html.dart | 39 # ........html.dart |
| 39 # ......htmlimpl/ | 40 # ......htmlimpl/ |
| 40 # ........htmlimpl.dart | 41 # ........htmlimpl.dart |
| 41 # ......json/ | 42 # ......json/ |
| 42 # ........json_frog.dart | 43 # ........json_frog.dart |
| 43 #.........json.dart | 44 #.........json.dart |
| 44 # ........{frog}/ | 45 # ........{frog}/ |
| 45 # ......uri/ | 46 # ......uri/ |
| 46 # ........uri.dart | 47 # ........uri.dart |
| 47 # ......utf8/ | 48 # ......utf8/ |
| 48 # ........utf8.dart | 49 # ........utf8.dart |
| 49 # ......(more will come here) | 50 # ......(more will come here) |
| 50 # ....util/ | 51 # ....util/ |
| 51 # ......(more will come here) | 52 # ......(more will come here) |
| 52 | 53 |
| 53 | 54 |
| 54 | 55 |
| 55 import os | 56 import os |
| 56 import re | 57 import re |
| 57 import sys | 58 import sys |
| 58 import tempfile | 59 import tempfile |
| 59 import utils | 60 import utils |
| 60 | 61 |
| 61 from os.path import dirname, join, realpath, exists, isdir | 62 from os.path import dirname, join, realpath, exists, isdir |
| 62 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | 63 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move |
| 63 | 64 |
| 65 def ReplaceInFiles(paths, subs): |
| 66 '''Reads a series of files, applies a series of substitutions to each, and |
| 67 saves them back out. subs should by a list of (pattern, replace) tuples.''' |
| 68 for path in paths: |
| 69 contents = open(path).read() |
| 70 for pattern, replace in subs: |
| 71 contents = re.sub(pattern, replace, contents) |
| 72 |
| 73 dest = open(path, 'w') |
| 74 dest.write(contents) |
| 75 dest.close() |
| 76 |
| 64 def Main(argv): | 77 def Main(argv): |
| 65 # Pull in all of the gpyi files which will be munged into the sdk. | 78 # Pull in all of the gpyi files which will be munged into the sdk. |
| 66 builtin_runtime_sources = \ | 79 builtin_runtime_sources = \ |
| 67 (eval(open("runtime/bin/builtin_sources.gypi").read()))['sources'] | 80 (eval(open("runtime/bin/builtin_sources.gypi").read()))['sources'] |
| 68 io_runtime_sources = \ | 81 io_runtime_sources = \ |
| 69 (eval(open("runtime/bin/io_sources.gypi").read()))['sources'] | 82 (eval(open("runtime/bin/io_sources.gypi").read()))['sources'] |
| 70 corelib_sources = \ | 83 corelib_sources = \ |
| 71 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] | 84 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] |
| 72 corelib_frog_sources = \ | 85 corelib_frog_sources = \ |
| 73 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] | 86 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] |
| (...skipping 24 matching lines...) Expand all Loading... |
| 98 # Copy the Dart VM binary into sdk/bin. | 111 # Copy the Dart VM binary into sdk/bin. |
| 99 # TODO(dgrove) - deal with architectures that are not ia32. | 112 # TODO(dgrove) - deal with architectures that are not ia32. |
| 100 build_dir = os.path.dirname(argv[1]) | 113 build_dir = os.path.dirname(argv[1]) |
| 101 frogc_file_extension = '' | 114 frogc_file_extension = '' |
| 102 dart_file_extension = '' | 115 dart_file_extension = '' |
| 103 if utils.GuessOS() == 'win32': | 116 if utils.GuessOS() == 'win32': |
| 104 dart_file_extension = '.exe' | 117 dart_file_extension = '.exe' |
| 105 frogc_file_extension = '.bat' | 118 frogc_file_extension = '.bat' |
| 106 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) | 119 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) |
| 107 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) | 120 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) |
| 108 frogc_src_binary = join(HOME, 'frog', 'scripts', 'bootstrap', | 121 frogc_src_binary = join(HOME, 'frog', 'scripts', 'bootstrap', |
| 109 'frogc' + frogc_file_extension) | 122 'frogc' + frogc_file_extension) |
| 110 frogc_dest_binary = join(BIN, 'frogc' + frogc_file_extension) | 123 frogc_dest_binary = join(BIN, 'frogc' + frogc_file_extension) |
| 111 copyfile(dart_src_binary, dart_dest_binary) | 124 copyfile(dart_src_binary, dart_dest_binary) |
| 112 copymode(dart_src_binary, dart_dest_binary) | 125 copymode(dart_src_binary, dart_dest_binary) |
| 113 copyfile(frogc_src_binary, frogc_dest_binary) | 126 copyfile(frogc_src_binary, frogc_dest_binary) |
| 114 copymode(frogc_src_binary, frogc_dest_binary) | 127 copymode(frogc_src_binary, frogc_dest_binary) |
| 115 | 128 |
| 116 # Create sdk/bin/frogc.dart, and hack as needed. | 129 # Create sdk/bin/frogc.dart, and hack as needed. |
| 117 frog_src_dir = join(HOME, 'frog') | 130 frog_src_dir = join(HOME, 'frog') |
| 118 | 131 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 # Create and populate lib/frog. | 196 # Create and populate lib/frog. |
| 184 # | 197 # |
| 185 frog_dest_dir = join(LIB, 'frog') | 198 frog_dest_dir = join(LIB, 'frog') |
| 186 os.makedirs(frog_dest_dir) | 199 os.makedirs(frog_dest_dir) |
| 187 | 200 |
| 188 for filename in os.listdir(frog_src_dir): | 201 for filename in os.listdir(frog_src_dir): |
| 189 if filename == 'frog_options.dart': | 202 if filename == 'frog_options.dart': |
| 190 # change config from 'dev' to 'sdk' in frog_options.dart | 203 # change config from 'dev' to 'sdk' in frog_options.dart |
| 191 frog_options_contents = open(join(frog_src_dir, filename)).read() | 204 frog_options_contents = open(join(frog_src_dir, filename)).read() |
| 192 frog_options_dest = open(join(frog_dest_dir, filename), 'w') | 205 frog_options_dest = open(join(frog_dest_dir, filename), 'w') |
| 193 frog_options_dest.write(re.sub("final config = \'dev\';", | 206 frog_options_dest.write(re.sub("final config = \'dev\';", |
| 194 "final config = \'sdk\';", | 207 "final config = \'sdk\';", |
| 195 frog_options_contents)) | 208 frog_options_contents)) |
| 196 frog_options_dest.close() | 209 frog_options_dest.close() |
| 197 elif filename.endswith('.dart'): | 210 elif filename.endswith('.dart'): |
| 198 copyfile(join(frog_src_dir, filename), join(frog_dest_dir, filename)) | 211 copyfile(join(frog_src_dir, filename), join(frog_dest_dir, filename)) |
| 199 | 212 |
| 200 leg_dest_dir = join(frog_dest_dir, 'leg') | 213 leg_dest_dir = join(frog_dest_dir, 'leg') |
| 201 copytree(join(frog_src_dir, 'leg'), leg_dest_dir, | 214 copytree(join(frog_src_dir, 'leg'), leg_dest_dir, |
| 202 ignore=ignore_patterns('.svn')) | 215 ignore=ignore_patterns('.svn')) |
| 203 | 216 |
| 204 # Remap imports in frog/leg/* . | 217 # Remap imports in frog/leg/* . |
| 205 for filename in os.listdir(leg_dest_dir): | 218 for filename in os.listdir(leg_dest_dir): |
| 206 if filename.endswith('.dart'): | 219 if filename.endswith('.dart'): |
| 207 file_contents = open(join(leg_dest_dir, filename)).read() | 220 file_contents = open(join(leg_dest_dir, filename)).read() |
| 208 file = open(join(leg_dest_dir, filename), 'w') | 221 file = open(join(leg_dest_dir, filename), 'w') |
| 209 file.write(re.sub("../../lib", "../..", file_contents)) | 222 file.write(re.sub("../../lib", "../..", file_contents)) |
| 210 file.close() | 223 file.close() |
| 211 | 224 |
| 212 copytree(join(frog_src_dir, 'server'), join(frog_dest_dir, 'server'), | 225 copytree(join(frog_src_dir, 'server'), join(frog_dest_dir, 'server'), |
| 213 ignore=ignore_patterns('.svn')) | 226 ignore=ignore_patterns('.svn')) |
| 214 | 227 |
| 215 # Remap imports in frog/... . | 228 # Remap imports in frog/... . |
| 216 for (dirpath, subdirs, _) in os.walk(frog_dest_dir): | 229 for (dirpath, subdirs, _) in os.walk(frog_dest_dir): |
| 217 for subdir in subdirs: | 230 for subdir in subdirs: |
| 218 for filename in os.listdir(join(dirpath, subdir)): | 231 for filename in os.listdir(join(dirpath, subdir)): |
| 219 if filename.endswith('.dart'): | 232 if filename.endswith('.dart'): |
| 220 file_contents = open(join(dirpath, subdir, filename)).read() | 233 file_contents = open(join(dirpath, subdir, filename)).read() |
| 221 file = open(join(dirpath, subdir, filename), 'w') | 234 file = open(join(dirpath, subdir, filename), 'w') |
| 222 file.write(re.sub("../lib/", "../", file_contents)) | 235 file.write(re.sub("../lib/", "../", file_contents)) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 239 # | 252 # |
| 240 # Create and populate lib/dom. | 253 # Create and populate lib/dom. |
| 241 # | 254 # |
| 242 dom_src_dir = join(HOME, 'client', 'dom') | 255 dom_src_dir = join(HOME, 'client', 'dom') |
| 243 dom_dest_dir = join(LIB, 'dom') | 256 dom_dest_dir = join(LIB, 'dom') |
| 244 os.makedirs(dom_dest_dir) | 257 os.makedirs(dom_dest_dir) |
| 245 | 258 |
| 246 copyfile(join(dom_src_dir, 'frog', 'dom_frog.dart'), | 259 copyfile(join(dom_src_dir, 'frog', 'dom_frog.dart'), |
| 247 join(dom_dest_dir, 'dom_frog.dart')) | 260 join(dom_dest_dir, 'dom_frog.dart')) |
| 248 | 261 |
| 249 # | 262 # |
| 250 # Create and populate lib/{json, uri, utf8} . | 263 # Create and populate lib/{json, uri, utf8} . |
| 251 # | 264 # |
| 252 | 265 |
| 253 for library in ['json', 'uri', 'utf8']: | 266 for library in ['json', 'uri', 'utf8']: |
| 254 src_dir = join(HOME, 'lib', library) | 267 src_dir = join(HOME, 'lib', library) |
| 255 dest_dir = join(LIB, library) | 268 dest_dir = join(LIB, library) |
| 256 os.makedirs(dest_dir) | 269 os.makedirs(dest_dir) |
| 257 | 270 |
| 258 for filename in os.listdir(src_dir): | 271 for filename in os.listdir(src_dir): |
| 259 if filename.endswith('.dart'): | 272 if filename.endswith('.dart'): |
| 260 copyfile(join(src_dir, filename), join(dest_dir, filename)) | 273 copyfile(join(src_dir, filename), join(dest_dir, filename)) |
| 261 | 274 |
| 275 # Create and populate lib/dartdoc |
| 276 dartdoc_src_dir = join(HOME, 'lib', 'dartdoc') |
| 277 dartdoc_dest_dir = join(LIB, 'dartdoc') |
| 278 copytree(dartdoc_src_dir, dartdoc_dest_dir, |
| 279 ignore=ignore_patterns('.svn', 'docs')) |
| 280 ReplaceInFiles([ |
| 281 join(LIB, 'dartdoc', 'dartdoc') |
| 282 ], [ |
| 283 ("../../frog/minfrog", "../../bin/frogc"), |
| 284 ("--libdir=../../frog/lib", "--libdir=../") |
| 285 ]) |
| 286 ReplaceInFiles([ |
| 287 join(LIB, 'dartdoc', 'dartdoc.dart') |
| 288 ], [ |
| 289 ("#import\('../../frog", "#import('../frog"), |
| 290 ("'../../frog'", "'../frog'"), |
| 291 ("'--libdir=../../frog/lib'", "'--libdir=../'") |
| 292 ]) |
| 293 ReplaceInFiles([ |
| 294 join(LIB, 'dartdoc', 'classify.dart'), |
| 295 join(LIB, 'dartdoc', 'client-live-nav.dart'), |
| 296 join(LIB, 'dartdoc', 'client-static.dart') |
| 297 ], [ |
| 298 ("#import\('../../frog", "#import('../frog") |
| 299 ]) |
| 300 |
| 262 # Create and populate lib/isolate | 301 # Create and populate lib/isolate |
| 263 copytree(join(HOME, 'lib', 'isolate'), join(LIB, 'isolate'), | 302 copytree(join(HOME, 'lib', 'isolate'), join(LIB, 'isolate'), |
| 264 ignore=ignore_patterns('.svn')) | 303 ignore=ignore_patterns('.svn')) |
| 265 | 304 |
| 266 # | 305 # |
| 267 # Create and populate lib/core. | 306 # Create and populate lib/core. |
| 268 # | 307 # |
| 269 | 308 |
| 270 # First, copy corelib/* to lib/{frog, runtime} | 309 # First, copy corelib/* to lib/{frog, runtime} |
| 271 for filename in corelib_sources: | 310 for filename in corelib_sources: |
| 272 for target_dir in ['frog', 'runtime']: | 311 for target_dir in ['frog', 'runtime']: |
| 273 copyfile(join('corelib', 'src', filename), | 312 copyfile(join('corelib', 'src', filename), |
| 274 join(corelib_dest_dir, target_dir, filename)) | 313 join(corelib_dest_dir, target_dir, filename)) |
| 275 | 314 |
| 276 # Next, copy the frog library source on top of core/frog | 315 # Next, copy the frog library source on top of core/frog |
| 277 # TOOD(dgrove): move json to top-level | 316 # TOOD(dgrove): move json to top-level |
| 278 for filename in corelib_frog_sources: | 317 for filename in corelib_frog_sources: |
| 279 copyfile(join('frog', 'lib', filename), | 318 copyfile(join('frog', 'lib', filename), |
| 280 join(corelib_dest_dir, 'frog', filename)) | 319 join(corelib_dest_dir, 'frog', filename)) |
| 281 | 320 |
| 282 # Next, copy the runtime library source on top of core/runtime | 321 # Next, copy the runtime library source on top of core/runtime |
| 283 for filename in corelib_runtime_sources: | 322 for filename in corelib_runtime_sources: |
| 284 if filename.endswith('.dart'): | 323 if filename.endswith('.dart'): |
| 285 copyfile(join('runtime', 'lib', filename), | 324 copyfile(join('runtime', 'lib', filename), |
| 286 join(corelib_dest_dir, 'runtime', filename)) | 325 join(corelib_dest_dir, 'runtime', filename)) |
| 287 | 326 |
| 288 # | 327 # |
| 289 # At this point, it's time to create lib/core/core*dart . | 328 # At this point, it's time to create lib/core/core*dart . |
| 290 # | 329 # |
| 291 # munge frog/lib/corelib.dart into lib/core_frog.dart . | 330 # munge frog/lib/corelib.dart into lib/core_frog.dart . |
| 292 src_file = join('frog', 'lib', 'corelib.dart') | 331 src_file = join('frog', 'lib', 'corelib.dart') |
| 293 dest_file = open(join(corelib_dest_dir, 'core_frog.dart'), 'w') | 332 dest_file = open(join(corelib_dest_dir, 'core_frog.dart'), 'w') |
| 294 contents = open(src_file).read() | 333 contents = open(src_file).read() |
| 295 contents = re.sub('source\(\"../../corelib/src/', 'source(\"', contents) | 334 contents = re.sub('source\(\"../../corelib/src/', 'source(\"', contents) |
| 296 contents = re.sub("source\(\"", "source(\"frog/", contents) | 335 contents = re.sub("source\(\"", "source(\"frog/", contents) |
| 297 dest_file.write(contents) | 336 dest_file.write(contents) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 308 dest_file.write('#source("runtime/' + filename + '");\n') | 347 dest_file.write('#source("runtime/' + filename + '");\n') |
| 309 dest_file.close() | 348 dest_file.close() |
| 310 | 349 |
| 311 # | 350 # |
| 312 # Create and populate lib/coreimpl. | 351 # Create and populate lib/coreimpl. |
| 313 # | 352 # |
| 314 | 353 |
| 315 # First, copy corelib/src/implementation to corelib/{frog, runtime}. | 354 # First, copy corelib/src/implementation to corelib/{frog, runtime}. |
| 316 for filename in coreimpl_sources: | 355 for filename in coreimpl_sources: |
| 317 for target_dir in ['frog', 'runtime']: | 356 for target_dir in ['frog', 'runtime']: |
| 318 copyfile(join('corelib', 'src', 'implementation', filename), | 357 copyfile(join('corelib', 'src', 'implementation', filename), |
| 319 join(coreimpl_dest_dir, target_dir, filename)) | 358 join(coreimpl_dest_dir, target_dir, filename)) |
| 320 | 359 |
| 321 for filename in coreimpl_frog_sources: | 360 for filename in coreimpl_frog_sources: |
| 322 copyfile(join('frog', 'lib', filename), | 361 copyfile(join('frog', 'lib', filename), |
| 323 join(coreimpl_dest_dir, 'frog', filename)) | 362 join(coreimpl_dest_dir, 'frog', filename)) |
| 324 | 363 |
| 325 for filename in coreimpl_runtime_sources: | 364 for filename in coreimpl_runtime_sources: |
| 326 if filename.endswith('.dart'): | 365 if filename.endswith('.dart'): |
| 327 copyfile(join('runtime', 'lib', filename), | 366 copyfile(join('runtime', 'lib', filename), |
| 328 join(coreimpl_dest_dir, 'runtime', filename)) | 367 join(coreimpl_dest_dir, 'runtime', filename)) |
| 329 | 368 |
| 330 | 369 |
| 331 # Create and fix up lib/coreimpl/coreimpl_frog.dart . | 370 # Create and fix up lib/coreimpl/coreimpl_frog.dart . |
| 332 src_file = join('frog', 'lib', 'corelib_impl.dart') | 371 src_file = join('frog', 'lib', 'corelib_impl.dart') |
| 333 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_frog.dart'), 'w') | 372 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_frog.dart'), 'w') |
| 334 contents = open(src_file).read() | 373 contents = open(src_file).read() |
| 335 contents = re.sub('source\(\"../../corelib/src/implementation/', | 374 contents = re.sub('source\(\"../../corelib/src/implementation/', |
| 336 'source(\"', contents) | 375 'source(\"', contents) |
| 337 contents = re.sub('source\(\"', 'source(\"frog/', contents) | 376 contents = re.sub('source\(\"', 'source(\"frog/', contents) |
| 338 dest_file.write(contents) | 377 dest_file.write(contents) |
| 339 dest_file.close() | 378 dest_file.close() |
| 340 | 379 |
| 341 # Construct lib/coreimpl/coreimpl_runtime.dart from whole cloth. | 380 # Construct lib/coreimpl/coreimpl_runtime.dart from whole cloth. |
| 342 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_runtime.dart'), 'w') | 381 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_runtime.dart'), 'w') |
| 343 dest_file.write('#library("dart:coreimpl");\n') | 382 dest_file.write('#library("dart:coreimpl");\n') |
| 344 for filename in coreimpl_sources: | 383 for filename in coreimpl_sources: |
| 345 dest_file.write('#source("runtime/' + filename + '");\n') | 384 dest_file.write('#source("runtime/' + filename + '");\n') |
| 346 for filename in coreimpl_runtime_sources: | 385 for filename in coreimpl_runtime_sources: |
| 347 if filename.endswith('.dart'): | 386 if filename.endswith('.dart'): |
| 348 dest_file.write('#source("runtime/' + filename + '");\n') | 387 dest_file.write('#source("runtime/' + filename + '");\n') |
| 349 dest_file.close() | 388 dest_file.close() |
| 350 | 389 |
| 351 # Create and copy tools. | 390 # Create and copy tools. |
| 352 | 391 |
| 353 UTIL = join(SDK_tmp, 'util') | 392 UTIL = join(SDK_tmp, 'util') |
| 354 os.makedirs(UTIL) | 393 os.makedirs(UTIL) |
| 355 | 394 |
| 356 move(SDK_tmp, SDK) | 395 move(SDK_tmp, SDK) |
| 357 | 396 |
| 358 if __name__ == '__main__': | 397 if __name__ == '__main__': |
| 359 sys.exit(Main(sys.argv)) | 398 sys.exit(Main(sys.argv)) |
| OLD | NEW |