Chromium Code Reviews| 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 # ......pub | |
| 18 # ....lib/ | 19 # ....lib/ |
| 19 # ......builtin/ | 20 # ......builtin/ |
| 20 # ........builtin_runtime.dart | 21 # ........builtin_runtime.dart |
| 21 # ......io/ | 22 # ......io/ |
| 22 # ........io_runtime.dart | 23 # ........io_runtime.dart |
| 23 # ........runtime/ | 24 # ........runtime/ |
| 24 # ......core/ | 25 # ......core/ |
| 25 # ........core_{frog, runtime}.dart | 26 # ........core_{frog, runtime}.dart |
| 26 # ........{frog, runtime}/ | 27 # ........{frog, runtime}/ |
| 27 # ......coreimpl/ | 28 # ......coreimpl/ |
| 28 # ........coreimpl_{frog, runtime}.dart | 29 # ........coreimpl_{frog, runtime}.dart |
| 29 # ........{frog, runtime}/ | 30 # ........{frog, runtime}/ |
| 30 # ......dartdoc/ | 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_frog.dart | 39 # ........html_frog.dart |
| 39 # ........html_dartium.dart | 40 # ........html_dartium.dart |
| 40 # ......json/ | 41 # ......json/ |
| 41 # ........json_frog.dart | 42 # ........json_frog.dart |
| 42 #.........json.dart | 43 #.........json.dart |
| 43 # ........{frog}/ | 44 # ........{frog}/ |
| 44 # ......uri/ | 45 # ......uri/ |
| 45 # ........uri.dart | 46 # ........uri.dart |
| 46 # ......utf/ | 47 # ......utf/ |
| 48 # ......yaml/ | |
|
dgrove
2012/04/28 13:26:06
I think yaml should be a subdirectory under util/p
Bob Nystrom
2012/04/30 17:30:56
It seemed consistent to me to put it next to JSON,
dgrove
2012/05/01 09:21:48
I don't think this is a commonly-desired library f
nweiz
2012/05/01 18:12:54
I don't understand why we wouldn't put a general-p
| |
| 47 # ......(more will come here) | 49 # ......(more will come here) |
| 48 # ....util/ | 50 # ....util/ |
| 51 # ......pub/ | |
| 49 # ......(more will come here) | 52 # ......(more will come here) |
| 50 | 53 |
| 51 | 54 |
| 52 | 55 |
| 53 import os | 56 import os |
| 54 import re | 57 import re |
| 55 import sys | 58 import sys |
| 56 import tempfile | 59 import tempfile |
| 57 import utils | 60 import utils |
| 58 | 61 |
| 59 # TODO(dgrove): Only import modules following Google style guide. | 62 # TODO(dgrove): Only import modules following Google style guide. |
| 60 from os.path import dirname, join, realpath, exists, isdir | 63 from os.path import basename, dirname, join, realpath, exists, isdir |
| 61 | 64 |
| 62 # TODO(dgrove): Only import modules following Google style guide. | 65 # TODO(dgrove): Only import modules following Google style guide. |
| 63 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | 66 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move |
| 64 | 67 |
| 65 def ReplaceInFiles(paths, subs): | 68 def ReplaceInFiles(paths, subs): |
| 66 '''Reads a series of files, applies a series of substitutions to each, and | 69 '''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.''' | 70 saves them back out. subs should by a list of (pattern, replace) tuples.''' |
| 68 for path in paths: | 71 for path in paths: |
| 69 contents = open(path).read() | 72 contents = open(path).read() |
| 70 for pattern, replace in subs: | 73 for pattern, replace in subs: |
| 71 contents = re.sub(pattern, replace, contents) | 74 contents = re.sub(pattern, replace, contents) |
| 72 | 75 |
| 73 dest = open(path, 'w') | 76 dest = open(path, 'w') |
| 74 dest.write(contents) | 77 dest.write(contents) |
| 75 dest.close() | 78 dest.close() |
| 76 | 79 |
| 80 def CopyShellScript(src_file, dest_dir): | |
| 81 '''Copies a shell/batch script to the given destination directory. Handles | |
| 82 using the appropriate platform-specific file extension.''' | |
| 83 file_extension = '' | |
| 84 if utils.GuessOS() == 'win32': | |
| 85 file_extension = '.bat' | |
| 86 | |
| 87 src = src_file + file_extension | |
| 88 dest = join(dest_dir, basename(src_file) + file_extension) | |
| 89 | |
| 90 copyfile(src, dest) | |
| 91 copymode(src, dest) | |
| 92 | |
| 93 | |
| 77 def Main(argv): | 94 def Main(argv): |
| 78 # Pull in all of the gpyi files which will be munged into the sdk. | 95 # Pull in all of the gpyi files which will be munged into the sdk. |
| 79 builtin_runtime_sources = \ | 96 builtin_runtime_sources = \ |
| 80 (eval(open("runtime/bin/builtin_sources.gypi").read()))['sources'] | 97 (eval(open("runtime/bin/builtin_sources.gypi").read()))['sources'] |
| 81 io_runtime_sources = \ | 98 io_runtime_sources = \ |
| 82 (eval(open("runtime/bin/io_sources.gypi").read()))['sources'] | 99 (eval(open("runtime/bin/io_sources.gypi").read()))['sources'] |
| 83 corelib_sources = \ | 100 corelib_sources = \ |
| 84 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] | 101 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] |
| 85 corelib_frog_sources = \ | 102 corelib_frog_sources = \ |
| 86 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] | 103 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 104 if exists(SDK): | 121 if exists(SDK): |
| 105 rmtree(SDK) | 122 rmtree(SDK) |
| 106 | 123 |
| 107 # Create and populate sdk/bin. | 124 # Create and populate sdk/bin. |
| 108 BIN = join(SDK_tmp, 'bin') | 125 BIN = join(SDK_tmp, 'bin') |
| 109 os.makedirs(BIN) | 126 os.makedirs(BIN) |
| 110 | 127 |
| 111 # Copy the Dart VM binary into sdk/bin. | 128 # Copy the Dart VM binary into sdk/bin. |
| 112 # TODO(dgrove) - deal with architectures that are not ia32. | 129 # TODO(dgrove) - deal with architectures that are not ia32. |
| 113 build_dir = os.path.dirname(argv[1]) | 130 build_dir = os.path.dirname(argv[1]) |
| 114 frogc_file_extension = '' | |
| 115 dart_file_extension = '' | 131 dart_file_extension = '' |
| 116 if utils.GuessOS() == 'win32': | 132 if utils.GuessOS() == 'win32': |
| 117 dart_file_extension = '.exe' | 133 dart_file_extension = '.exe' |
| 118 frogc_file_extension = '.bat' | |
| 119 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) | 134 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) |
| 120 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) | 135 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) |
| 121 frogc_src_binary = join(HOME, 'frog', 'scripts', 'bootstrap', | |
| 122 'frogc' + frogc_file_extension) | |
| 123 frogc_dest_binary = join(BIN, 'frogc' + frogc_file_extension) | |
| 124 copyfile(dart_src_binary, dart_dest_binary) | 136 copyfile(dart_src_binary, dart_dest_binary) |
| 125 copymode(dart_src_binary, dart_dest_binary) | 137 copymode(dart_src_binary, dart_dest_binary) |
| 126 copyfile(frogc_src_binary, frogc_dest_binary) | 138 |
| 127 copymode(frogc_src_binary, frogc_dest_binary) | 139 frogc_src_binary = join(HOME, 'frog', 'scripts', 'bootstrap', 'frogc') |
| 140 CopyShellScript(frogc_src_binary, BIN) | |
| 128 | 141 |
| 129 # Create sdk/bin/frogc.dart, and hack as needed. | 142 # Create sdk/bin/frogc.dart, and hack as needed. |
| 130 frog_src_dir = join(HOME, 'frog') | 143 frog_src_dir = join(HOME, 'frog') |
| 131 | 144 |
| 132 # Convert frogc.dart's imports from import('*') -> import('frog/*'). | 145 # Convert frogc.dart's imports from import('*') -> import('frog/*'). |
| 133 frogc_contents = open(join(frog_src_dir, 'frogc.dart')).read() | 146 frogc_contents = open(join(frog_src_dir, 'frogc.dart')).read() |
| 134 frogc_dest = open(join(BIN, 'frogc.dart'), 'w') | 147 frogc_dest = open(join(BIN, 'frogc.dart'), 'w') |
| 135 frogc_dest.write( | 148 frogc_dest.write( |
| 136 re.sub(r"#import\('([^.])", r"#import('../lib/frog/\1", frogc_contents)) | 149 re.sub(r"#import\('([^.])", r"#import('../lib/frog/\1", frogc_contents)) |
| 137 frogc_dest.close() | 150 frogc_dest.close() |
| 138 | 151 |
| 152 # Create pub shell script. | |
| 153 pub_src_script = join(HOME, 'utils', 'pub', 'sdk', 'pub') | |
| 154 CopyShellScript(pub_src_script, BIN) | |
| 155 | |
| 139 # TODO(dgrove): copy and fix up frog.dart, minfrogc.dart. | 156 # TODO(dgrove): copy and fix up frog.dart, minfrogc.dart. |
| 140 | 157 |
| 141 # | 158 # |
| 142 # Create and populate sdk/lib. | 159 # Create and populate sdk/lib. |
| 143 # | 160 # |
| 144 | 161 |
| 145 LIB = join(SDK_tmp, 'lib') | 162 LIB = join(SDK_tmp, 'lib') |
| 146 os.makedirs(LIB) | 163 os.makedirs(LIB) |
| 147 corelib_dest_dir = join(LIB, 'core') | 164 corelib_dest_dir = join(LIB, 'core') |
| 148 os.makedirs(corelib_dest_dir) | 165 os.makedirs(corelib_dest_dir) |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 join(LIB, 'dartdoc', 'classify.dart'), | 323 join(LIB, 'dartdoc', 'classify.dart'), |
| 307 join(LIB, 'dartdoc', 'client-live-nav.dart'), | 324 join(LIB, 'dartdoc', 'client-live-nav.dart'), |
| 308 join(LIB, 'dartdoc', 'client-static.dart') | 325 join(LIB, 'dartdoc', 'client-static.dart') |
| 309 ], [ | 326 ], [ |
| 310 ("#import\('../../frog", "#import('../frog") | 327 ("#import\('../../frog", "#import('../frog") |
| 311 ]) | 328 ]) |
| 312 | 329 |
| 313 # Create and populate lib/isolate | 330 # Create and populate lib/isolate |
| 314 copytree(join(HOME, 'lib', 'isolate'), join(LIB, 'isolate'), | 331 copytree(join(HOME, 'lib', 'isolate'), join(LIB, 'isolate'), |
| 315 ignore=ignore_patterns('.svn')) | 332 ignore=ignore_patterns('.svn')) |
| 316 | 333 |
| 317 isolate_runtime_dir = join(LIB, 'isolate', 'runtime') | 334 isolate_runtime_dir = join(LIB, 'isolate', 'runtime') |
| 318 # path seems to exist when run locally, but not on builder | 335 # path seems to exist when run locally, but not on builder |
| 319 if not exists(isolate_runtime_dir): | 336 if not exists(isolate_runtime_dir): |
| 320 os.makedirs(isolate_runtime_dir) | 337 os.makedirs(isolate_runtime_dir) |
| 321 | 338 |
| 322 isolate_runtime_src = join(HOME, 'runtime', 'lib', 'isolate.dart') | 339 isolate_runtime_src = join(HOME, 'runtime', 'lib', 'isolate.dart') |
| 323 isolate_runtime_dest = join(LIB, 'isolate', 'runtime', 'isolate.dart') | 340 isolate_runtime_dest = join(LIB, 'isolate', 'runtime', 'isolate.dart') |
| 324 copyfile(isolate_runtime_src, isolate_runtime_dest) | 341 copyfile(isolate_runtime_src, isolate_runtime_dest) |
| 325 | 342 |
| 326 # | 343 # |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 # Construct lib/coreimpl/coreimpl_runtime.dart from whole cloth. | 420 # Construct lib/coreimpl/coreimpl_runtime.dart from whole cloth. |
| 404 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_runtime.dart'), 'w') | 421 dest_file = open(join(coreimpl_dest_dir, 'coreimpl_runtime.dart'), 'w') |
| 405 dest_file.write('#library("dart:coreimpl");\n') | 422 dest_file.write('#library("dart:coreimpl");\n') |
| 406 for filename in coreimpl_sources: | 423 for filename in coreimpl_sources: |
| 407 dest_file.write('#source("runtime/' + filename + '");\n') | 424 dest_file.write('#source("runtime/' + filename + '");\n') |
| 408 for filename in coreimpl_runtime_sources: | 425 for filename in coreimpl_runtime_sources: |
| 409 if filename.endswith('.dart'): | 426 if filename.endswith('.dart'): |
| 410 dest_file.write('#source("runtime/' + filename + '");\n') | 427 dest_file.write('#source("runtime/' + filename + '");\n') |
| 411 dest_file.close() | 428 dest_file.close() |
| 412 | 429 |
| 430 # Create and populate lib/yaml | |
| 431 yaml_src_dir = join(HOME, 'utils', 'yaml') | |
| 432 yaml_dest_dir = join(LIB, 'yaml') | |
| 433 copytree(yaml_src_dir, yaml_dest_dir, ignore=ignore_patterns('.svn')) | |
| 434 | |
| 413 # Create and copy tools. | 435 # Create and copy tools. |
| 414 | 436 |
| 415 UTIL = join(SDK_tmp, 'util') | 437 UTIL = join(SDK_tmp, 'util') |
| 416 os.makedirs(UTIL) | 438 os.makedirs(UTIL) |
| 417 | 439 |
| 440 # Create and populate util/pub | |
| 441 pub_src_dir = join(HOME, 'utils', 'pub') | |
| 442 pub_dst_dir = join(UTIL, 'pub') | |
| 443 copytree(pub_src_dir, pub_dst_dir, | |
| 444 ignore=ignore_patterns('.svn', 'sdk')) | |
| 445 ReplaceInFiles([ | |
| 446 join(UTIL, 'pub', 'pub.dart') | |
| 447 ], [ | |
| 448 ("'../yaml/yaml.dart'", "'../../lib/yaml/yaml.dart'") | |
| 449 ]) | |
| 418 | 450 |
| 419 # Copy import maps | 451 # Copy import maps |
| 420 PLATFORMS = ['any', 'vm', 'dartium', 'dart2js', 'frog' ] | 452 PLATFORMS = ['any', 'vm', 'dartium', 'dart2js', 'frog' ] |
| 421 os.makedirs(join(LIB, 'config')) | 453 os.makedirs(join(LIB, 'config')) |
| 422 for platform in PLATFORMS: | 454 for platform in PLATFORMS: |
| 423 import_src = join(HOME, 'lib', 'config', 'import_' + platform + '.config') | 455 import_src = join(HOME, 'lib', 'config', 'import_' + platform + '.config') |
| 424 import_dst = join(LIB, 'config', 'import_' + platform + '.config') | 456 import_dst = join(LIB, 'config', 'import_' + platform + '.config') |
| 425 copyfile(import_src, import_dst); | 457 copyfile(import_src, import_dst); |
| 426 | 458 |
| 427 # Write the 'revision' file | 459 # Write the 'revision' file |
| 428 revision = utils.GetSVNRevision() | 460 revision = utils.GetSVNRevision() |
| 429 if revision is not None: | 461 if revision is not None: |
| 430 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: | 462 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: |
| 431 f.write(revision + '\n') | 463 f.write(revision + '\n') |
| 432 f.close() | 464 f.close() |
| 433 | 465 |
| 434 move(SDK_tmp, SDK) | 466 move(SDK_tmp, SDK) |
| 435 | 467 |
| 436 if __name__ == '__main__': | 468 if __name__ == '__main__': |
| 437 sys.exit(Main(sys.argv)) | 469 sys.exit(Main(sys.argv)) |
| OLD | NEW |