| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 # |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 | 53 |
| 54 | 54 |
| 55 import os | 55 import os |
| 56 import re | 56 import re |
| 57 import sys | 57 import sys |
| 58 import subprocess | 58 import subprocess |
| 59 import tempfile | 59 import tempfile |
| 60 import utils | 60 import utils |
| 61 | 61 |
| 62 HOST_OS = utils.GuessOS() |
| 63 |
| 62 # TODO(dgrove): Only import modules following Google style guide. | 64 # TODO(dgrove): Only import modules following Google style guide. |
| 63 from os.path import basename, dirname, join, realpath, exists, isdir | 65 from os.path import basename, dirname, join, realpath, exists, isdir |
| 64 | 66 |
| 65 # TODO(dgrove): Only import modules following Google style guide. | 67 # TODO(dgrove): Only import modules following Google style guide. |
| 66 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | 68 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move |
| 67 | 69 |
| 68 def ReplaceInFiles(paths, subs): | 70 def ReplaceInFiles(paths, subs): |
| 69 '''Reads a series of files, applies a series of substitutions to each, and | 71 '''Reads a series of files, applies a series of substitutions to each, and |
| 70 saves them back out. subs should by a list of (pattern, replace) tuples.''' | 72 saves them back out. subs should by a list of (pattern, replace) tuples.''' |
| 71 for path in paths: | 73 for path in paths: |
| 72 contents = open(path).read() | 74 contents = open(path).read() |
| 73 for pattern, replace in subs: | 75 for pattern, replace in subs: |
| 74 contents = re.sub(pattern, replace, contents) | 76 contents = re.sub(pattern, replace, contents) |
| 75 | 77 |
| 76 dest = open(path, 'w') | 78 dest = open(path, 'w') |
| 77 dest.write(contents) | 79 dest.write(contents) |
| 78 dest.close() | 80 dest.close() |
| 79 | 81 |
| 80 | 82 |
| 81 def Copy(src, dest): | 83 def Copy(src, dest): |
| 82 copyfile(src, dest) | 84 copyfile(src, dest) |
| 83 copymode(src, dest) | 85 copymode(src, dest) |
| 84 | 86 |
| 85 # TODO(zundel): this excludes the analyzer from the sdk build until builders | 87 # TODO(zundel): this excludes the analyzer from the sdk build until builders |
| 86 # have all prerequisite software installed. Also update dart.gyp. | 88 # have all prerequisite software installed. Also update dart.gyp. |
| 87 def ShouldCopyAnalyzer(): | 89 def ShouldCopyAnalyzer(): |
| 88 os = utils.GuessOS() | 90 return HOST_OS == 'linux' or HOST_OS == 'macos' |
| 89 return os == 'linux' or os == 'macos' | |
| 90 | 91 |
| 91 | 92 |
| 92 def CopyShellScript(src_file, dest_dir): | 93 def CopyShellScript(src_file, dest_dir): |
| 93 '''Copies a shell/batch script to the given destination directory. Handles | 94 '''Copies a shell/batch script to the given destination directory. Handles |
| 94 using the appropriate platform-specific file extension.''' | 95 using the appropriate platform-specific file extension.''' |
| 95 file_extension = '' | 96 file_extension = '' |
| 96 if utils.GuessOS() == 'win32': | 97 if HOST_OS == 'win32': |
| 97 file_extension = '.bat' | 98 file_extension = '.bat' |
| 98 | 99 |
| 99 src = src_file + file_extension | 100 src = src_file + file_extension |
| 100 dest = join(dest_dir, basename(src_file) + file_extension) | 101 dest = join(dest_dir, basename(src_file) + file_extension) |
| 101 Copy(src, dest) | 102 Copy(src, dest) |
| 102 | 103 |
| 103 | 104 |
| 104 def CopyDartScripts(home, build_dir, sdk_root, version): | 105 def CopyDartScripts(home, build_dir, sdk_root, version): |
| 105 if version: | 106 if version: |
| 106 ReplaceInFiles([os.path.join(sdk_root, 'lib', '_internal', 'compiler', | 107 ReplaceInFiles([os.path.join(sdk_root, 'lib', '_internal', 'compiler', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 BIN = join(SDK_tmp, 'bin') | 143 BIN = join(SDK_tmp, 'bin') |
| 143 os.makedirs(BIN) | 144 os.makedirs(BIN) |
| 144 | 145 |
| 145 # Copy the Dart VM binary and the Windows Dart VM link library | 146 # Copy the Dart VM binary and the Windows Dart VM link library |
| 146 # into sdk/bin. | 147 # into sdk/bin. |
| 147 # | 148 # |
| 148 # TODO(dgrove) - deal with architectures that are not ia32. | 149 # TODO(dgrove) - deal with architectures that are not ia32. |
| 149 build_dir = os.path.dirname(argv[1]) | 150 build_dir = os.path.dirname(argv[1]) |
| 150 dart_file_extension = '' | 151 dart_file_extension = '' |
| 151 analyzer_file_extension = '' | 152 analyzer_file_extension = '' |
| 152 if utils.GuessOS() == 'win32': | 153 if HOST_OS == 'win32': |
| 153 dart_file_extension = '.exe' | 154 dart_file_extension = '.exe' |
| 154 analyzer_file_extension = '.bat' # TODO(zundel): test on Windows | 155 analyzer_file_extension = '.bat' # TODO(zundel): test on Windows |
| 155 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') | 156 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') |
| 156 dart_import_lib_dest = join(BIN, 'dart.lib') | 157 dart_import_lib_dest = join(BIN, 'dart.lib') |
| 157 copyfile(dart_import_lib_src, dart_import_lib_dest) | 158 copyfile(dart_import_lib_src, dart_import_lib_dest) |
| 158 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) | 159 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) |
| 159 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) | 160 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) |
| 160 copyfile(dart_src_binary, dart_dest_binary) | 161 copyfile(dart_src_binary, dart_dest_binary) |
| 161 copymode(dart_src_binary, dart_dest_binary) | 162 copymode(dart_src_binary, dart_dest_binary) |
| 162 if utils.GuessOS() != 'win32': | 163 # Strip the binaries on platforms where that is supported. |
| 164 if HOST_OS == 'linux': |
| 163 subprocess.call(['strip', dart_dest_binary]) | 165 subprocess.call(['strip', dart_dest_binary]) |
| 166 elif HOST_OS == 'macos': |
| 167 subprocess.call(['strip', '-x', dart_dest_binary]) |
| 164 | 168 |
| 165 if ShouldCopyAnalyzer(): | 169 if ShouldCopyAnalyzer(): |
| 166 # Copy analyzer into sdk/bin | 170 # Copy analyzer into sdk/bin |
| 167 ANALYZER_HOME = join(HOME, build_dir, 'analyzer') | 171 ANALYZER_HOME = join(HOME, build_dir, 'analyzer') |
| 168 dart_analyzer_src_binary = join(ANALYZER_HOME, 'bin', 'dart_analyzer') | 172 dart_analyzer_src_binary = join(ANALYZER_HOME, 'bin', 'dart_analyzer') |
| 169 dart_analyzer_dest_binary = join(BIN, | 173 dart_analyzer_dest_binary = join(BIN, |
| 170 'dart_analyzer' + analyzer_file_extension) | 174 'dart_analyzer' + analyzer_file_extension) |
| 171 copyfile(dart_analyzer_src_binary, dart_analyzer_dest_binary) | 175 copyfile(dart_analyzer_src_binary, dart_analyzer_dest_binary) |
| 172 copymode(dart_analyzer_src_binary, dart_analyzer_dest_binary) | 176 copymode(dart_analyzer_src_binary, dart_analyzer_dest_binary) |
| 173 | 177 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 os.makedirs(dest_dir) | 246 os.makedirs(dest_dir) |
| 243 dest_file = join (ANALYZER_DEST, jarToCopy) | 247 dest_file = join (ANALYZER_DEST, jarToCopy) |
| 244 src_file = join(ANALYZER_HOME, 'util', 'analyzer', jarToCopy) | 248 src_file = join(ANALYZER_HOME, 'util', 'analyzer', jarToCopy) |
| 245 copyfile(src_file, dest_file) | 249 copyfile(src_file, dest_file) |
| 246 | 250 |
| 247 # Create and populate util/pub. | 251 # Create and populate util/pub. |
| 248 copytree(join(HOME, 'utils', 'pub'), join(UTIL, 'pub'), | 252 copytree(join(HOME, 'utils', 'pub'), join(UTIL, 'pub'), |
| 249 ignore=ignore_patterns('.svn', 'sdk')) | 253 ignore=ignore_patterns('.svn', 'sdk')) |
| 250 | 254 |
| 251 # Copy in 7zip for Windows. | 255 # Copy in 7zip for Windows. |
| 252 if utils.GuessOS() == 'win32': | 256 if HOST_OS == 'win32': |
| 253 copytree(join(HOME, 'third_party', '7zip'), | 257 copytree(join(HOME, 'third_party', '7zip'), |
| 254 join(join(UTIL, 'pub'), '7zip'), | 258 join(join(UTIL, 'pub'), '7zip'), |
| 255 ignore=ignore_patterns('.svn')) | 259 ignore=ignore_patterns('.svn')) |
| 256 | 260 |
| 257 ReplaceInFiles([ | 261 ReplaceInFiles([ |
| 258 join(UTIL, 'pub', 'io.dart'), | 262 join(UTIL, 'pub', 'io.dart'), |
| 259 ], [ | 263 ], [ |
| 260 ("var pathTo7zip = '../../third_party/7zip/7za.exe';", | 264 ("var pathTo7zip = '../../third_party/7zip/7za.exe';", |
| 261 "var pathTo7zip = '7zip/7za.exe';"), | 265 "var pathTo7zip = '7zip/7za.exe';"), |
| 262 ]) | 266 ]) |
| 263 | 267 |
| 264 # Copy in cURL on all operating systems, since we need the certificates file | 268 # Copy in cURL on all operating systems, since we need the certificates file |
| 265 # even outside Windows. Leave out the EXE on non-Windows systems, though. | 269 # even outside Windows. Leave out the EXE on non-Windows systems, though. |
| 266 curl_ignore_patterns = ignore_patterns('.svn') if utils.GuessOS() == 'win32' \ | 270 curl_ignore_patterns = ignore_patterns('.svn') if HOST_OS == 'win32' \ |
| 267 else ignore_patterns('.svn', '*.exe') | 271 else ignore_patterns('.svn', '*.exe') |
| 268 copytree(join(HOME, 'third_party', 'curl'), | 272 copytree(join(HOME, 'third_party', 'curl'), |
| 269 join(join(UTIL, 'pub'), 'curl'), | 273 join(join(UTIL, 'pub'), 'curl'), |
| 270 ignore=curl_ignore_patterns) | 274 ignore=curl_ignore_patterns) |
| 271 | 275 |
| 272 ReplaceInFiles([ | 276 ReplaceInFiles([ |
| 273 join(UTIL, 'pub', 'curl_client.dart'), | 277 join(UTIL, 'pub', 'curl_client.dart'), |
| 274 ], [ | 278 ], [ |
| 275 ("var pathToCurl = '../../third_party/curl/curl.exe';", | 279 ("var pathToCurl = '../../third_party/curl/curl.exe';", |
| 276 "var pathToCurl = 'curl/curl.exe';"), | 280 "var pathToCurl = 'curl/curl.exe';"), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 302 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: | 306 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: |
| 303 f.write(revision + '\n') | 307 f.write(revision + '\n') |
| 304 f.close() | 308 f.close() |
| 305 | 309 |
| 306 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) | 310 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) |
| 307 | 311 |
| 308 move(SDK_tmp, SDK) | 312 move(SDK_tmp, SDK) |
| 309 | 313 |
| 310 if __name__ == '__main__': | 314 if __name__ == '__main__': |
| 311 sys.exit(Main(sys.argv)) | 315 sys.exit(Main(sys.argv)) |
| OLD | NEW |