| 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 # ......dart.lib (import library for VM native extensions on Windows) | 17 # ......dart.lib (import library for VM native extensions on Windows) |
| 18 # ......frogc.dart | 18 # ......frogc.dart |
| 19 # ......pub |
| 19 # ....include/ | 20 # ....include/ |
| 20 # ......dart_api.h | 21 # ......dart_api.h |
| 21 # ......dart_debugger_api.h | 22 # ......dart_debugger_api.h |
| 22 # ....lib/ | 23 # ....lib/ |
| 23 # ......builtin/ | 24 # ......builtin/ |
| 24 # ........builtin_runtime.dart | 25 # ........builtin_runtime.dart |
| 25 # ......io/ | 26 # ......io/ |
| 26 # ........io_runtime.dart | 27 # ........io_runtime.dart |
| 27 # ........runtime/ | 28 # ........runtime/ |
| 28 # ......core/ | 29 # ......core/ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 # ........html_dartium.dart | 44 # ........html_dartium.dart |
| 44 # ......json/ | 45 # ......json/ |
| 45 # ........json_frog.dart | 46 # ........json_frog.dart |
| 46 #.........json.dart | 47 #.........json.dart |
| 47 # ........{frog}/ | 48 # ........{frog}/ |
| 48 # ......uri/ | 49 # ......uri/ |
| 49 # ........uri.dart | 50 # ........uri.dart |
| 50 # ......utf/ | 51 # ......utf/ |
| 51 # ......(more will come here) | 52 # ......(more will come here) |
| 52 # ....util/ | 53 # ....util/ |
| 54 # ......pub/ |
| 53 # ......(more will come here) | 55 # ......(more will come here) |
| 54 | 56 |
| 55 | 57 |
| 56 | 58 |
| 57 import os | 59 import os |
| 58 import re | 60 import re |
| 59 import sys | 61 import sys |
| 60 import tempfile | 62 import tempfile |
| 61 import utils | 63 import utils |
| 62 | 64 |
| 63 # TODO(dgrove): Only import modules following Google style guide. | 65 # TODO(dgrove): Only import modules following Google style guide. |
| 64 from os.path import dirname, join, realpath, exists, isdir | 66 from os.path import basename, dirname, join, realpath, exists, isdir |
| 65 | 67 |
| 66 # TODO(dgrove): Only import modules following Google style guide. | 68 # TODO(dgrove): Only import modules following Google style guide. |
| 67 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | 69 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move |
| 68 | 70 |
| 69 def ReplaceInFiles(paths, subs): | 71 def ReplaceInFiles(paths, subs): |
| 70 '''Reads a series of files, applies a series of substitutions to each, and | 72 '''Reads a series of files, applies a series of substitutions to each, and |
| 71 saves them back out. subs should by a list of (pattern, replace) tuples.''' | 73 saves them back out. subs should by a list of (pattern, replace) tuples.''' |
| 72 for path in paths: | 74 for path in paths: |
| 73 contents = open(path).read() | 75 contents = open(path).read() |
| 74 for pattern, replace in subs: | 76 for pattern, replace in subs: |
| 75 contents = re.sub(pattern, replace, contents) | 77 contents = re.sub(pattern, replace, contents) |
| 76 | 78 |
| 77 dest = open(path, 'w') | 79 dest = open(path, 'w') |
| 78 dest.write(contents) | 80 dest.write(contents) |
| 79 dest.close() | 81 dest.close() |
| 80 | 82 |
| 81 | 83 |
| 82 def Copy(src, dest): | 84 def Copy(src, dest): |
| 83 copyfile(src, dest) | 85 copyfile(src, dest) |
| 84 copymode(src, dest) | 86 copymode(src, dest) |
| 85 | 87 |
| 86 | 88 |
| 89 def CopyShellScript(src_file, dest_dir): |
| 90 '''Copies a shell/batch script to the given destination directory. Handles |
| 91 using the appropriate platform-specific file extension.''' |
| 92 file_extension = '' |
| 93 if utils.GuessOS() == 'win32': |
| 94 file_extension = '.bat' |
| 95 |
| 96 src = src_file + file_extension |
| 97 dest = join(dest_dir, basename(src_file) + file_extension) |
| 98 Copy(src, dest) |
| 99 |
| 100 |
| 87 def CopyDart2Js(build_dir, sdk_root): | 101 def CopyDart2Js(build_dir, sdk_root): |
| 88 ''' | 102 ''' |
| 89 Install dart2js in SDK/lib/dart2js. | 103 Install dart2js in SDK/lib/dart2js. |
| 90 | 104 |
| 91 Currently, we copy too much stuff to this location, but the SDK's | 105 Currently, we copy too much stuff to this location, but the SDK's |
| 92 layout matches the the layout of the part of the repository we're | 106 layout matches the the layout of the part of the repository we're |
| 93 dealing with here which frees us from rewriting files. The long term | 107 dealing with here which frees us from rewriting files. The long term |
| 94 plan is to align the layout of the repository and the SDK, at which | 108 plan is to align the layout of the repository and the SDK, at which |
| 95 point we should be able to simplify Main below and share the dart | 109 point we should be able to simplify Main below and share the dart |
| 96 files between the various components to minimize SDK download size. | 110 files between the various components to minimize SDK download size. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 113 [(r'%SCRIPTPATH%\.\.\\lib', | 127 [(r'%SCRIPTPATH%\.\.\\lib', |
| 114 r'%SCRIPTPATH%..\lib\dart2js\lib')]) | 128 r'%SCRIPTPATH%..\lib\dart2js\lib')]) |
| 115 else: | 129 else: |
| 116 dart2js = os.path.join(sdk_root, 'bin', 'dart2js') | 130 dart2js = os.path.join(sdk_root, 'bin', 'dart2js') |
| 117 Copy(os.path.join(build_dir, 'dart2js'), dart2js) | 131 Copy(os.path.join(build_dir, 'dart2js'), dart2js) |
| 118 ReplaceInFiles([dart2js], | 132 ReplaceInFiles([dart2js], |
| 119 [(r'\$BIN_DIR/\.\./\.\./lib', | 133 [(r'\$BIN_DIR/\.\./\.\./lib', |
| 120 r'$BIN_DIR/../lib/dart2js/lib')]) | 134 r'$BIN_DIR/../lib/dart2js/lib')]) |
| 121 | 135 |
| 122 | 136 |
| 123 | |
| 124 def Main(argv): | 137 def Main(argv): |
| 125 # Pull in all of the gpyi files which will be munged into the sdk. | 138 # Pull in all of the gpyi files which will be munged into the sdk. |
| 126 builtin_runtime_sources = \ | 139 builtin_runtime_sources = \ |
| 127 (eval(open("runtime/bin/builtin_sources.gypi").read()))['sources'] | 140 (eval(open("runtime/bin/builtin_sources.gypi").read()))['sources'] |
| 128 io_runtime_sources = \ | 141 io_runtime_sources = \ |
| 129 (eval(open("runtime/bin/io_sources.gypi").read()))['sources'] | 142 (eval(open("runtime/bin/io_sources.gypi").read()))['sources'] |
| 130 corelib_sources = \ | 143 corelib_sources = \ |
| 131 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] | 144 (eval(open("corelib/src/corelib_sources.gypi").read()))['sources'] |
| 132 corelib_frog_sources = \ | 145 corelib_frog_sources = \ |
| 133 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] | 146 (eval(open("frog/lib/frog_corelib_sources.gypi").read()))['sources'] |
| (...skipping 19 matching lines...) Expand all Loading... |
| 153 | 166 |
| 154 # Create and populate sdk/bin. | 167 # Create and populate sdk/bin. |
| 155 BIN = join(SDK_tmp, 'bin') | 168 BIN = join(SDK_tmp, 'bin') |
| 156 os.makedirs(BIN) | 169 os.makedirs(BIN) |
| 157 | 170 |
| 158 # Copy the Dart VM binary, frogc and Windows dart VM link library | 171 # Copy the Dart VM binary, frogc and Windows dart VM link library |
| 159 # into sdk/bin. | 172 # into sdk/bin. |
| 160 # | 173 # |
| 161 # TODO(dgrove) - deal with architectures that are not ia32. | 174 # TODO(dgrove) - deal with architectures that are not ia32. |
| 162 build_dir = os.path.dirname(argv[1]) | 175 build_dir = os.path.dirname(argv[1]) |
| 163 frogc_file_extension = '' | |
| 164 dart_file_extension = '' | 176 dart_file_extension = '' |
| 165 if utils.GuessOS() == 'win32': | 177 if utils.GuessOS() == 'win32': |
| 166 dart_file_extension = '.exe' | 178 dart_file_extension = '.exe' |
| 167 frogc_file_extension = '.bat' | |
| 168 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') | 179 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') |
| 169 dart_import_lib_dest = join(BIN, 'dart.lib') | 180 dart_import_lib_dest = join(BIN, 'dart.lib') |
| 170 copyfile(dart_import_lib_src, dart_import_lib_dest) | 181 copyfile(dart_import_lib_src, dart_import_lib_dest) |
| 171 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) | 182 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) |
| 172 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) | 183 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) |
| 173 frogc_src_binary = join(HOME, 'frog', 'scripts', 'bootstrap', | |
| 174 'frogc' + frogc_file_extension) | |
| 175 frogc_dest_binary = join(BIN, 'frogc' + frogc_file_extension) | |
| 176 copyfile(dart_src_binary, dart_dest_binary) | 184 copyfile(dart_src_binary, dart_dest_binary) |
| 177 copymode(dart_src_binary, dart_dest_binary) | 185 copymode(dart_src_binary, dart_dest_binary) |
| 178 copyfile(frogc_src_binary, frogc_dest_binary) | 186 |
| 179 copymode(frogc_src_binary, frogc_dest_binary) | 187 frogc_src_binary = join(HOME, 'frog', 'scripts', 'bootstrap', 'frogc') |
| 188 CopyShellScript(frogc_src_binary, BIN) |
| 180 | 189 |
| 181 # Create sdk/bin/frogc.dart, and hack as needed. | 190 # Create sdk/bin/frogc.dart, and hack as needed. |
| 182 frog_src_dir = join(HOME, 'frog') | 191 frog_src_dir = join(HOME, 'frog') |
| 183 | 192 |
| 184 # Convert frogc.dart's imports from import('*') -> import('frog/*'). | 193 # Convert frogc.dart's imports from import('*') -> import('frog/*'). |
| 185 frogc_contents = open(join(frog_src_dir, 'frogc.dart')).read() | 194 frogc_contents = open(join(frog_src_dir, 'frogc.dart')).read() |
| 186 frogc_dest = open(join(BIN, 'frogc.dart'), 'w') | 195 frogc_dest = open(join(BIN, 'frogc.dart'), 'w') |
| 187 frogc_dest.write( | 196 frogc_dest.write( |
| 188 re.sub(r"#import\('([^.])", r"#import('../lib/frog/\1", frogc_contents)) | 197 re.sub(r"#import\('([^.])", r"#import('../lib/frog/\1", frogc_contents)) |
| 189 frogc_dest.close() | 198 frogc_dest.close() |
| 190 | 199 |
| 200 # Create pub shell script. |
| 201 pub_src_script = join(HOME, 'utils', 'pub', 'sdk', 'pub') |
| 202 CopyShellScript(pub_src_script, BIN) |
| 203 |
| 191 # TODO(dgrove): copy and fix up frog.dart, minfrogc.dart. | 204 # TODO(dgrove): copy and fix up frog.dart, minfrogc.dart. |
| 192 | 205 |
| 193 # | 206 # |
| 194 # Create and populate sdk/include. | 207 # Create and populate sdk/include. |
| 195 # | 208 # |
| 196 INCLUDE = join(SDK_tmp, 'include') | 209 INCLUDE = join(SDK_tmp, 'include') |
| 197 os.makedirs(INCLUDE) | 210 os.makedirs(INCLUDE) |
| 198 copyfile(join(HOME, 'runtime', 'include', 'dart_api.h'), | 211 copyfile(join(HOME, 'runtime', 'include', 'dart_api.h'), |
| 199 join(INCLUDE, 'dart_api.h')) | 212 join(INCLUDE, 'dart_api.h')) |
| 200 copyfile(join(HOME, 'runtime', 'include', 'dart_debugger_api.h'), | 213 copyfile(join(HOME, 'runtime', 'include', 'dart_debugger_api.h'), |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 join(LIB, 'dartdoc', 'classify.dart'), | 381 join(LIB, 'dartdoc', 'classify.dart'), |
| 369 join(LIB, 'dartdoc', 'client-live-nav.dart'), | 382 join(LIB, 'dartdoc', 'client-live-nav.dart'), |
| 370 join(LIB, 'dartdoc', 'client-static.dart') | 383 join(LIB, 'dartdoc', 'client-static.dart') |
| 371 ], [ | 384 ], [ |
| 372 ("#import\('../../frog", "#import('../frog") | 385 ("#import\('../../frog", "#import('../frog") |
| 373 ]) | 386 ]) |
| 374 | 387 |
| 375 # Create and populate lib/isolate | 388 # Create and populate lib/isolate |
| 376 copytree(join(HOME, 'lib', 'isolate'), join(LIB, 'isolate'), | 389 copytree(join(HOME, 'lib', 'isolate'), join(LIB, 'isolate'), |
| 377 ignore=ignore_patterns('.svn')) | 390 ignore=ignore_patterns('.svn')) |
| 378 | 391 |
| 379 isolate_runtime_dir = join(LIB, 'isolate', 'runtime') | 392 isolate_runtime_dir = join(LIB, 'isolate', 'runtime') |
| 380 # path seems to exist when run locally, but not on builder | 393 # path seems to exist when run locally, but not on builder |
| 381 if not exists(isolate_runtime_dir): | 394 if not exists(isolate_runtime_dir): |
| 382 os.makedirs(isolate_runtime_dir) | 395 os.makedirs(isolate_runtime_dir) |
| 383 | 396 |
| 384 isolate_runtime_src = join(HOME, 'runtime', 'lib', 'isolate.dart') | 397 isolate_runtime_src = join(HOME, 'runtime', 'lib', 'isolate.dart') |
| 385 isolate_runtime_dest = join(LIB, 'isolate', 'runtime', 'isolate.dart') | 398 isolate_runtime_dest = join(LIB, 'isolate', 'runtime', 'isolate.dart') |
| 386 copyfile(isolate_runtime_src, isolate_runtime_dest) | 399 copyfile(isolate_runtime_src, isolate_runtime_dest) |
| 387 | 400 |
| 388 # | 401 # |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 for filename in coreimpl_runtime_sources: | 483 for filename in coreimpl_runtime_sources: |
| 471 if filename.endswith('.dart'): | 484 if filename.endswith('.dart'): |
| 472 dest_file.write('#source("runtime/' + filename + '");\n') | 485 dest_file.write('#source("runtime/' + filename + '");\n') |
| 473 dest_file.close() | 486 dest_file.close() |
| 474 | 487 |
| 475 # Create and copy tools. | 488 # Create and copy tools. |
| 476 | 489 |
| 477 UTIL = join(SDK_tmp, 'util') | 490 UTIL = join(SDK_tmp, 'util') |
| 478 os.makedirs(UTIL) | 491 os.makedirs(UTIL) |
| 479 | 492 |
| 493 # Create and populate util/pub |
| 494 pub_src_dir = join(HOME, 'utils', 'pub') |
| 495 pub_dst_dir = join(UTIL, 'pub') |
| 496 copytree(pub_src_dir, pub_dst_dir, |
| 497 ignore=ignore_patterns('.svn', 'sdk')) |
| 480 | 498 |
| 481 # Copy import maps | 499 # Copy import maps |
| 482 PLATFORMS = ['any', 'vm', 'dartium', 'dart2js', 'frog' ] | 500 PLATFORMS = ['any', 'vm', 'dartium', 'dart2js', 'frog' ] |
| 483 os.makedirs(join(LIB, 'config')) | 501 os.makedirs(join(LIB, 'config')) |
| 484 for platform in PLATFORMS: | 502 for platform in PLATFORMS: |
| 485 import_src = join(HOME, 'lib', 'config', 'import_' + platform + '.config') | 503 import_src = join(HOME, 'lib', 'config', 'import_' + platform + '.config') |
| 486 import_dst = join(LIB, 'config', 'import_' + platform + '.config') | 504 import_dst = join(LIB, 'config', 'import_' + platform + '.config') |
| 487 copyfile(import_src, import_dst); | 505 copyfile(import_src, import_dst); |
| 488 | 506 |
| 489 CopyDart2Js(build_dir, SDK_tmp) | 507 CopyDart2Js(build_dir, SDK_tmp) |
| 490 | 508 |
| 491 # Write the 'revision' file | 509 # Write the 'revision' file |
| 492 revision = utils.GetSVNRevision() | 510 revision = utils.GetSVNRevision() |
| 493 if revision is not None: | 511 if revision is not None: |
| 494 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: | 512 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: |
| 495 f.write(revision + '\n') | 513 f.write(revision + '\n') |
| 496 f.close() | 514 f.close() |
| 497 | 515 |
| 498 move(SDK_tmp, SDK) | 516 move(SDK_tmp, SDK) |
| 499 utils.Touch(os.path.join(SDK, 'create.stamp')) | 517 utils.Touch(os.path.join(SDK, 'create.stamp')) |
| 500 | 518 |
| 501 if __name__ == '__main__': | 519 if __name__ == '__main__': |
| 502 sys.exit(Main(sys.argv)) | 520 sys.exit(Main(sys.argv)) |
| OLD | NEW |