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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 # TODO(dgrove): Only import modules following Google style guide. | 87 # TODO(dgrove): Only import modules following Google style guide. |
88 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | 88 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move |
89 | 89 |
90 | 90 |
91 def GetOptions(): | 91 def GetOptions(): |
92 options = optparse.OptionParser(usage='usage: %prog [options]') | 92 options = optparse.OptionParser(usage='usage: %prog [options]') |
93 options.add_option("--sdk_output_dir", | 93 options.add_option("--sdk_output_dir", |
94 help='Where to output the sdk') | 94 help='Where to output the sdk') |
95 options.add_option("--snapshot_location", | 95 options.add_option("--snapshot_location", |
96 help='Location of the snapshots.') | 96 help='Location of the snapshots.') |
97 options.add_option("--copy_libs", | |
98 action="store_true", default=False, | |
99 help='Copy dynamically linked libraries to the SDK bin directory.') | |
100 options.add_option("--disable_stripping", | |
101 action="store_true", default=False, | |
102 help='Do not try to strip binaries. Use when they are already stripped') | |
103 return options.parse_args() | 97 return options.parse_args() |
104 | 98 |
105 | 99 |
106 def ReplaceInFiles(paths, subs): | |
107 """Reads a series of files, applies a series of substitutions to each, and | |
108 saves them back out. subs should by a list of (pattern, replace) tuples.""" | |
109 for path in paths: | |
110 contents = open(path).read() | |
111 for pattern, replace in subs: | |
112 contents = re.sub(pattern, replace, contents) | |
113 | |
114 dest = open(path, 'w') | |
115 dest.write(contents) | |
116 dest.close() | |
117 | |
118 | |
119 def Copy(src, dest): | 100 def Copy(src, dest): |
120 copyfile(src, dest) | 101 copyfile(src, dest) |
121 copymode(src, dest) | 102 copymode(src, dest) |
122 | 103 |
123 | 104 |
124 def CopyShellScript(src_file, dest_dir): | 105 def CopyShellScript(src_file, dest_dir): |
125 """Copies a shell/batch script to the given destination directory. Handles | 106 """Copies a shell/batch script to the given destination directory. Handles |
126 using the appropriate platform-specific file extension.""" | 107 using the appropriate platform-specific file extension.""" |
127 file_extension = '' | 108 file_extension = '' |
128 if HOST_OS == 'win32': | 109 if HOST_OS == 'win32': |
129 file_extension = '.bat' | 110 file_extension = '.bat' |
130 | 111 |
131 # If we're copying an SDK-specific shell script, strip off the suffix. | 112 # If we're copying an SDK-specific shell script, strip off the suffix. |
132 dest_file = basename(src_file) | 113 dest_file = basename(src_file) |
133 if dest_file.endswith('_sdk'): | 114 if dest_file.endswith('_sdk'): |
134 dest_file = dest_file.replace('_sdk', '') | 115 dest_file = dest_file.replace('_sdk', '') |
135 | 116 |
136 src = src_file + file_extension | 117 src = src_file + file_extension |
137 dest = join(dest_dir, dest_file + file_extension) | 118 dest = join(dest_dir, dest_file + file_extension) |
138 Copy(src, dest) | 119 Copy(src, dest) |
139 | 120 |
140 | 121 |
141 def CopyLibs(out_dir, bin_dir): | |
142 for library in ['libcrypto', 'libssl']: | |
143 ext = '.so' | |
144 if HOST_OS == 'macos': | |
145 ext = '.dylib' | |
146 elif HOST_OS == 'win32': | |
147 ext = '.dll' | |
148 src = os.path.join(out_dir, library + ext) | |
149 dst = os.path.join(bin_dir, library + ext) | |
150 if os.path.isfile(src): | |
151 copyfile(src, dst) | |
152 copymode(src, dst) | |
153 | |
154 | |
155 def CopyDartScripts(home, sdk_root): | 122 def CopyDartScripts(home, sdk_root): |
156 for executable in ['dart2js_sdk', 'dartanalyzer_sdk', 'dartfmt_sdk', | 123 for executable in ['dart2js_sdk', 'dartanalyzer_sdk', 'dartfmt_sdk', |
157 'pub_sdk', 'dartdoc', 'dartdevc_sdk']: | 124 'pub_sdk', 'dartdoc', 'dartdevc_sdk']: |
158 CopyShellScript(os.path.join(home, 'sdk', 'bin', executable), | 125 CopyShellScript(os.path.join(home, 'sdk', 'bin', executable), |
159 os.path.join(sdk_root, 'bin')) | 126 os.path.join(sdk_root, 'bin')) |
160 | 127 |
161 | 128 |
162 def CopySnapshots(snapshots, sdk_root): | 129 def CopySnapshots(snapshots, sdk_root): |
163 for snapshot in ['analysis_server', 'dart2js', 'dartanalyzer', 'dartfmt', | 130 for snapshot in ['analysis_server', 'dart2js', 'dartanalyzer', 'dartfmt', |
164 'utils_wrapper', 'pub', 'dartdoc', 'dartdevc']: | 131 'utils_wrapper', 'pub', 'dartdoc', 'dartdevc']: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if HOST_OS == 'win32': | 203 if HOST_OS == 'win32': |
237 dart_file_extension = '.exe' | 204 dart_file_extension = '.exe' |
238 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') | 205 dart_import_lib_src = join(HOME, build_dir, 'dart.lib') |
239 dart_import_lib_dest = join(BIN, 'dart.lib') | 206 dart_import_lib_dest = join(BIN, 'dart.lib') |
240 copyfile(dart_import_lib_src, dart_import_lib_dest) | 207 copyfile(dart_import_lib_src, dart_import_lib_dest) |
241 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) | 208 dart_src_binary = join(HOME, build_dir, 'dart' + dart_file_extension) |
242 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) | 209 dart_dest_binary = join(BIN, 'dart' + dart_file_extension) |
243 copyfile(dart_src_binary, dart_dest_binary) | 210 copyfile(dart_src_binary, dart_dest_binary) |
244 copymode(dart_src_binary, dart_dest_binary) | 211 copymode(dart_src_binary, dart_dest_binary) |
245 # Strip the binaries on platforms where that is supported. | 212 # Strip the binaries on platforms where that is supported. |
246 if HOST_OS == 'linux' and not options.disable_stripping: | 213 if HOST_OS == 'linux': |
247 subprocess.call(['strip', dart_dest_binary]) | 214 subprocess.call(['strip', dart_dest_binary]) |
248 elif HOST_OS == 'macos' and not options.disable_stripping: | 215 elif HOST_OS == 'macos': |
249 subprocess.call(['strip', '-x', dart_dest_binary]) | 216 subprocess.call(['strip', '-x', dart_dest_binary]) |
250 | 217 |
251 # | 218 # |
252 # Create and populate sdk/include. | 219 # Create and populate sdk/include. |
253 # | 220 # |
254 INCLUDE = join(SDK_tmp, 'include') | 221 INCLUDE = join(SDK_tmp, 'include') |
255 os.makedirs(INCLUDE) | 222 os.makedirs(INCLUDE) |
256 copyfile(join(HOME, 'runtime', 'include', 'dart_api.h'), | 223 copyfile(join(HOME, 'runtime', 'include', 'dart_api.h'), |
257 join(INCLUDE, 'dart_api.h')) | 224 join(INCLUDE, 'dart_api.h')) |
258 copyfile(join(HOME, 'runtime', 'include', 'dart_mirrors_api.h'), | 225 copyfile(join(HOME, 'runtime', 'include', 'dart_mirrors_api.h'), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 296 |
330 # Copy dart2js/pub. | 297 # Copy dart2js/pub. |
331 CopyDartScripts(HOME, SDK_tmp) | 298 CopyDartScripts(HOME, SDK_tmp) |
332 | 299 |
333 CopySnapshots(SNAPSHOT, SDK_tmp) | 300 CopySnapshots(SNAPSHOT, SDK_tmp) |
334 CopyDartdocResources(HOME, SDK_tmp) | 301 CopyDartdocResources(HOME, SDK_tmp) |
335 CopyAnalyzerSources(HOME, LIB) | 302 CopyAnalyzerSources(HOME, LIB) |
336 CopyAnalysisSummaries(SNAPSHOT, LIB) | 303 CopyAnalysisSummaries(SNAPSHOT, LIB) |
337 CopyDevCompilerSdk(HOME, LIB) | 304 CopyDevCompilerSdk(HOME, LIB) |
338 | 305 |
339 if options.copy_libs: | |
340 CopyLibs(build_dir, BIN) | |
341 | |
342 # Write the 'version' file | 306 # Write the 'version' file |
343 version = utils.GetVersion() | 307 version = utils.GetVersion() |
344 versionFile = open(os.path.join(SDK_tmp, 'version'), 'w') | 308 versionFile = open(os.path.join(SDK_tmp, 'version'), 'w') |
345 versionFile.write(version + '\n') | 309 versionFile.write(version + '\n') |
346 versionFile.close() | 310 versionFile.close() |
347 | 311 |
348 # Write the 'revision' file | 312 # Write the 'revision' file |
349 revision = utils.GetGitRevision() | 313 revision = utils.GetGitRevision() |
350 | 314 |
351 if revision is not None: | 315 if revision is not None: |
352 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: | 316 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: |
353 f.write('%s\n' % revision) | 317 f.write('%s\n' % revision) |
354 f.close() | 318 f.close() |
355 | 319 |
356 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) | 320 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) |
357 Copy(join(HOME, 'LICENSE'), join(SDK_tmp, 'LICENSE')) | 321 Copy(join(HOME, 'LICENSE'), join(SDK_tmp, 'LICENSE')) |
358 Copy(join(HOME, 'sdk', 'api_readme.md'), join(SDK_tmp, 'lib', 'api_readme.md')
) | 322 Copy(join(HOME, 'sdk', 'api_readme.md'), join(SDK_tmp, 'lib', 'api_readme.md')
) |
359 | 323 |
360 move(SDK_tmp, SDK) | 324 move(SDK_tmp, SDK) |
361 | 325 |
362 if __name__ == '__main__': | 326 if __name__ == '__main__': |
363 sys.exit(Main()) | 327 sys.exit(Main()) |
OLD | NEW |