| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright (c) 2012, 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. | |
| 8 # | |
| 9 # Usage: create_sdk.py sdk_directory | |
| 10 # | |
| 11 # The SDK will be used either from the command-line or from the editor. | |
| 12 # Top structure is | |
| 13 # | |
| 14 # ..dart-sdk/ | |
| 15 # ....bin/ | |
| 16 # ......dart or dart.exe (executable) | |
| 17 # ......dart.lib (import library for VM native extensions on Windows) | |
| 18 # ......dartdoc | |
| 19 # ......dartfmt | |
| 20 # ......dart2js | |
| 21 # ......dartanalyzer | |
| 22 # ......dartdevc | |
| 23 # ......pub | |
| 24 # ......snapshots/ | |
| 25 # ........analysis_server.dart.snapshot | |
| 26 # ........dart2js.dart.snapshot | |
| 27 # ........dartanalyzer.dart.snapshot | |
| 28 # ........dartdoc.dart.snapshot | |
| 29 # ........dartfmt.dart.snapshot | |
| 30 # ........dartdevc.dart.snapshot | |
| 31 # ........pub.dart.snapshot | |
| 32 # ........utils_wrapper.dart.snapshot | |
| 33 #.........resources/ | |
| 34 #...........dartdoc/ | |
| 35 #..............packages | |
| 36 #.............resources/ | |
| 37 #.............templates/ | |
| 38 # ....include/ | |
| 39 # ......dart_api.h | |
| 40 # ......dart_mirrors_api.h | |
| 41 # ......dart_native_api.h | |
| 42 # ......dart_tools_api.h | |
| 43 # ....lib/ | |
| 44 # ......dart_client.platform | |
| 45 # ......dart_server.platform | |
| 46 # ......dart_shared.platform | |
| 47 # ......_internal/ | |
| 48 #.........spec.sum | |
| 49 #.........strong.sum | |
| 50 #.........dev_compiler/ | |
| 51 # ......analysis_server/ | |
| 52 # ......analyzer/ | |
| 53 # ......async/ | |
| 54 # ......collection/ | |
| 55 # ......convert/ | |
| 56 # ......core/ | |
| 57 # ......front_end/ | |
| 58 # ......html/ | |
| 59 # ......internal/ | |
| 60 # ......io/ | |
| 61 # ......isolate/ | |
| 62 # ......js/ | |
| 63 # ......js_util/ | |
| 64 # ......kernel/ | |
| 65 # ......math/ | |
| 66 # ......mirrors/ | |
| 67 # ......typed_data/ | |
| 68 # ......api_readme.md | |
| 69 # ....util/ | |
| 70 # ......(more will come here) | |
| 71 | |
| 72 | |
| 73 import optparse | |
| 74 import os | |
| 75 import re | |
| 76 import sys | |
| 77 import subprocess | |
| 78 | |
| 79 import utils | |
| 80 | |
| 81 | |
| 82 HOST_OS = utils.GuessOS() | |
| 83 | |
| 84 # TODO(dgrove): Only import modules following Google style guide. | |
| 85 from os.path import basename, dirname, join, realpath, exists | |
| 86 | |
| 87 # TODO(dgrove): Only import modules following Google style guide. | |
| 88 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | |
| 89 | |
| 90 | |
| 91 def GetOptions(): | |
| 92 options = optparse.OptionParser(usage='usage: %prog [options]') | |
| 93 options.add_option("--sdk_output_dir", | |
| 94 help='Where to output the sdk') | |
| 95 options.add_option("--snapshot_location", | |
| 96 help='Location of the snapshots.') | |
| 97 return options.parse_args() | |
| 98 | |
| 99 | |
| 100 def Copy(src, dest): | |
| 101 copyfile(src, dest) | |
| 102 copymode(src, dest) | |
| 103 | |
| 104 | |
| 105 def CopyShellScript(src_file, dest_dir): | |
| 106 """Copies a shell/batch script to the given destination directory. Handles | |
| 107 using the appropriate platform-specific file extension.""" | |
| 108 file_extension = '' | |
| 109 if HOST_OS == 'win32': | |
| 110 file_extension = '.bat' | |
| 111 | |
| 112 # If we're copying an SDK-specific shell script, strip off the suffix. | |
| 113 dest_file = basename(src_file) | |
| 114 if dest_file.endswith('_sdk'): | |
| 115 dest_file = dest_file.replace('_sdk', '') | |
| 116 | |
| 117 src = src_file + file_extension | |
| 118 dest = join(dest_dir, dest_file + file_extension) | |
| 119 Copy(src, dest) | |
| 120 | |
| 121 | |
| 122 def CopyDartScripts(home, sdk_root): | |
| 123 for executable in ['dart2js_sdk', 'dartanalyzer_sdk', 'dartfmt_sdk', | |
| 124 'pub_sdk', 'dartdoc', 'dartdevc_sdk']: | |
| 125 CopyShellScript(os.path.join(home, 'sdk', 'bin', executable), | |
| 126 os.path.join(sdk_root, 'bin')) | |
| 127 | |
| 128 | |
| 129 def CopySnapshots(snapshots, sdk_root): | |
| 130 for snapshot in ['analysis_server', 'dart2js', 'dartanalyzer', 'dartfmt', | |
| 131 'utils_wrapper', 'pub', 'dartdoc', 'dartdevc']: | |
| 132 snapshot += '.dart.snapshot' | |
| 133 copyfile(join(snapshots, snapshot), | |
| 134 join(sdk_root, 'bin', 'snapshots', snapshot)) | |
| 135 | |
| 136 def CopyAnalyzerSources(home, lib_dir): | |
| 137 for library in ['analyzer', 'analysis_server', 'front_end', 'kernel']: | |
| 138 copytree(join(home, 'pkg', library), join(lib_dir, library), | |
| 139 ignore=ignore_patterns('*.svn', 'doc', '*.py', '*.gypi', '*.sh', | |
| 140 '.gitignore', 'packages')) | |
| 141 | |
| 142 def CopyDartdocResources(home, sdk_root): | |
| 143 RESOURCE_DIR = join(sdk_root, 'bin', 'snapshots', 'resources') | |
| 144 DARTDOC = join(RESOURCE_DIR, 'dartdoc') | |
| 145 | |
| 146 copytree(join(home, 'third_party', 'pkg', 'dartdoc', 'lib', 'templates'), | |
| 147 join(DARTDOC, 'templates')) | |
| 148 copytree(join(home, 'third_party', 'pkg', 'dartdoc', 'lib', 'resources'), | |
| 149 join(DARTDOC, 'resources')) | |
| 150 # write the .packages file | |
| 151 PACKAGES_FILE = join(DARTDOC, '.packages') | |
| 152 packages_file = open(PACKAGES_FILE, 'w') | |
| 153 packages_file.write('dartdoc:.') | |
| 154 packages_file.close() | |
| 155 | |
| 156 def CopyAnalysisSummaries(snapshots, lib): | |
| 157 copyfile(join(snapshots, 'spec.sum'), | |
| 158 join(lib, '_internal', 'spec.sum')) | |
| 159 copyfile(join(snapshots, 'strong.sum'), | |
| 160 join(lib, '_internal', 'strong.sum')) | |
| 161 | |
| 162 def CopyDevCompilerSdk(home, lib): | |
| 163 copyfile(join(home, 'pkg', 'dev_compiler', 'lib', 'sdk', 'ddc_sdk.sum'), | |
| 164 join(lib, '_internal', 'ddc_sdk.sum')) | |
| 165 copytree(join(home, 'pkg', 'dev_compiler', 'lib', 'js'), | |
| 166 join(lib, 'dev_compiler')) | |
| 167 copyfile(join(home, 'third_party', 'requirejs', 'require.js'), | |
| 168 join(lib, 'dev_compiler', 'amd', 'require.js')) | |
| 169 | |
| 170 def Main(): | |
| 171 # Pull in all of the gypi files which will be munged into the sdk. | |
| 172 HOME = dirname(dirname(realpath(__file__))) | |
| 173 | |
| 174 (options, args) = GetOptions() | |
| 175 | |
| 176 SDK = options.sdk_output_dir | |
| 177 SDK_tmp = '%s.tmp' % SDK | |
| 178 | |
| 179 SNAPSHOT = options.snapshot_location | |
| 180 | |
| 181 # TODO(dgrove) - deal with architectures that are not ia32. | |
| 182 | |
| 183 if exists(SDK): | |
| 184 rmtree(SDK) | |
| 185 | |
| 186 if exists(SDK_tmp): | |
| 187 rmtree(SDK_tmp) | |
| 188 | |
| 189 os.makedirs(SDK_tmp) | |
| 190 | |
| 191 # Create and populate sdk/bin. | |
| 192 BIN = join(SDK_tmp, 'bin') | |
| 193 os.makedirs(BIN) | |
| 194 | |
| 195 os.makedirs(join(BIN, 'snapshots')) | |
| 196 | |
| 197 # Copy the Dart VM binary and the Windows Dart VM link library | |
| 198 # into sdk/bin. | |
| 199 # | |
| 200 # TODO(dgrove) - deal with architectures that are not ia32. | |
| 201 build_dir = os.path.dirname(SDK) | |
| 202 dart_file_extension = '' | |
| 203 if HOST_OS == 'win32': | |
| 204 dart_file_extension = '.exe' | |
| 205 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') | |
| 206 dart_import_lib_dest = join(BIN, 'dart.lib') | |
| 207 copyfile(dart_import_lib_src, dart_import_lib_dest) | |
| 208 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) | |
| 209 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) | |
| 210 copyfile(dart_src_binary, dart_dest_binary) | |
| 211 copymode(dart_src_binary, dart_dest_binary) | |
| 212 # Strip the binaries on platforms where that is supported. | |
| 213 if HOST_OS == 'linux': | |
| 214 subprocess.call(['strip', dart_dest_binary]) | |
| 215 elif HOST_OS == 'macos': | |
| 216 subprocess.call(['strip', '-x', dart_dest_binary]) | |
| 217 | |
| 218 # | |
| 219 # Create and populate sdk/include. | |
| 220 # | |
| 221 INCLUDE = join(SDK_tmp, 'include') | |
| 222 os.makedirs(INCLUDE) | |
| 223 copyfile(join(HOME, 'runtime', 'include', 'dart_api.h'), | |
| 224 join(INCLUDE, 'dart_api.h')) | |
| 225 copyfile(join(HOME, 'runtime', 'include', 'dart_mirrors_api.h'), | |
| 226 join(INCLUDE, 'dart_mirrors_api.h')) | |
| 227 copyfile(join(HOME, 'runtime', 'include', 'dart_native_api.h'), | |
| 228 join(INCLUDE, 'dart_native_api.h')) | |
| 229 copyfile(join(HOME, 'runtime', 'include', 'dart_tools_api.h'), | |
| 230 join(INCLUDE, 'dart_tools_api.h')) | |
| 231 | |
| 232 # | |
| 233 # Create and populate sdk/lib. | |
| 234 # | |
| 235 | |
| 236 LIB = join(SDK_tmp, 'lib') | |
| 237 os.makedirs(LIB) | |
| 238 | |
| 239 # | |
| 240 # Create and populate lib/{async, core, isolate, ...}. | |
| 241 # | |
| 242 | |
| 243 os.makedirs(join(LIB, 'html')) | |
| 244 | |
| 245 for library in [join('_blink', 'dartium'), | |
| 246 join('_chrome', 'dart2js'), join('_chrome', 'dartium'), | |
| 247 join('_internal', 'js_runtime'), | |
| 248 join('_internal', 'sdk_library_metadata'), | |
| 249 'async', 'collection', 'convert', 'core', 'developer', | |
| 250 'internal', 'io', 'isolate', | |
| 251 join('html', 'dart2js'), join('html', 'dartium'), | |
| 252 join('html', 'html_common'), | |
| 253 join('indexed_db', 'dart2js'), join('indexed_db', 'dartium'), | |
| 254 'js', 'js_util', 'math', 'mirrors', 'profiler', 'typed_data', | |
| 255 join('svg', 'dart2js'), join('svg', 'dartium'), | |
| 256 join('web_audio', 'dart2js'), join('web_audio', 'dartium'), | |
| 257 join('web_gl', 'dart2js'), join('web_gl', 'dartium'), | |
| 258 join('web_sql', 'dart2js'), join('web_sql', 'dartium')]: | |
| 259 copytree(join(HOME, 'sdk', 'lib', library), join(LIB, library), | |
| 260 ignore=ignore_patterns('*.svn', 'doc', '*.py', '*.gypi', '*.sh', | |
| 261 '.gitignore')) | |
| 262 | |
| 263 # Copy the platform descriptors. | |
| 264 for file_name in ["dart_client.platform", | |
| 265 "dart_server.platform", | |
| 266 "dart_shared.platform"]: | |
| 267 copyfile(join(HOME, 'sdk', 'lib', file_name), join(LIB, file_name)); | |
| 268 | |
| 269 # Copy libraries.dart to lib/_internal/libraries.dart for backwards | |
| 270 # compatibility. | |
| 271 # | |
| 272 # TODO(sigmund): stop copying libraries.dart. Old versions (<=0.25.1-alpha.4) | |
| 273 # of the analyzer package do not support the new location of this file. We | |
| 274 # should be able to remove the old file once we release a newer version of | |
| 275 # analyzer and popular frameworks have migrated to use it. | |
| 276 copyfile(join(HOME, 'sdk', 'lib', '_internal', | |
| 277 'sdk_library_metadata', 'lib', 'libraries.dart'), | |
| 278 join(LIB, '_internal', 'libraries.dart')) | |
| 279 | |
| 280 # Create and copy tools. | |
| 281 UTIL = join(SDK_tmp, 'util') | |
| 282 os.makedirs(UTIL) | |
| 283 | |
| 284 RESOURCE = join(SDK_tmp, 'lib', '_internal', 'pub', 'asset') | |
| 285 os.makedirs(os.path.dirname(RESOURCE)) | |
| 286 copytree(join(HOME, 'third_party', 'pkg', 'pub', 'lib', 'src', | |
| 287 'asset'), | |
| 288 join(RESOURCE), | |
| 289 ignore=ignore_patterns('.svn')) | |
| 290 | |
| 291 # Copy in 7zip for Windows. | |
| 292 if HOST_OS == 'win32': | |
| 293 copytree(join(HOME, 'third_party', '7zip'), | |
| 294 join(RESOURCE, '7zip'), | |
| 295 ignore=ignore_patterns('.svn')) | |
| 296 | |
| 297 # Copy dart2js/pub. | |
| 298 CopyDartScripts(HOME, SDK_tmp) | |
| 299 | |
| 300 CopySnapshots(SNAPSHOT, SDK_tmp) | |
| 301 CopyDartdocResources(HOME, SDK_tmp) | |
| 302 CopyAnalyzerSources(HOME, LIB) | |
| 303 CopyAnalysisSummaries(SNAPSHOT, LIB) | |
| 304 CopyDevCompilerSdk(HOME, LIB) | |
| 305 | |
| 306 # Write the 'version' file | |
| 307 version = utils.GetVersion() | |
| 308 versionFile = open(os.path.join(SDK_tmp, 'version'), 'w') | |
| 309 versionFile.write(version + '\n') | |
| 310 versionFile.close() | |
| 311 | |
| 312 # Write the 'revision' file | |
| 313 revision = utils.GetGitRevision() | |
| 314 | |
| 315 if revision is not None: | |
| 316 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: | |
| 317 f.write('%s\n' % revision) | |
| 318 f.close() | |
| 319 | |
| 320 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) | |
| 321 Copy(join(HOME, 'LICENSE'), join(SDK_tmp, 'LICENSE')) | |
| 322 Copy(join(HOME, 'sdk', 'api_readme.md'), join(SDK_tmp, 'lib', 'api_readme.md')
) | |
| 323 | |
| 324 move(SDK_tmp, SDK) | |
| 325 | |
| 326 if __name__ == '__main__': | |
| 327 sys.exit(Main()) | |
| OLD | NEW |