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) 2014, 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 # |
(...skipping 27 matching lines...) Expand all Loading... |
41 # ......io/ | 41 # ......io/ |
42 # ......isolate/ | 42 # ......isolate/ |
43 # ......js/ | 43 # ......js/ |
44 # ......math/ | 44 # ......math/ |
45 # ......mirrors/ | 45 # ......mirrors/ |
46 # ......typed_data/ | 46 # ......typed_data/ |
47 # ....util/ | 47 # ....util/ |
48 # ......(more will come here) | 48 # ......(more will come here) |
49 | 49 |
50 | 50 |
51 import glob | |
52 import optparse | 51 import optparse |
53 import os | 52 import os |
54 import re | 53 import re |
55 import sys | 54 import sys |
56 import subprocess | 55 import subprocess |
57 import tempfile | 56 |
58 import utils | 57 import utils |
59 | 58 |
| 59 |
60 HOST_OS = utils.GuessOS() | 60 HOST_OS = utils.GuessOS() |
61 | 61 |
62 # TODO(dgrove): Only import modules following Google style guide. | 62 # TODO(dgrove): Only import modules following Google style guide. |
63 from os.path import basename, dirname, join, realpath, exists, isdir | 63 from os.path import basename, dirname, join, realpath, exists |
64 | 64 |
65 # TODO(dgrove): Only import modules following Google style guide. | 65 # TODO(dgrove): Only import modules following Google style guide. |
66 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move | 66 from shutil import copyfile, copymode, copytree, ignore_patterns, rmtree, move |
67 | 67 |
68 | 68 |
69 def GetOptions(): | 69 def GetOptions(): |
70 options = optparse.OptionParser(usage='usage: %prog [options]') | 70 options = optparse.OptionParser(usage='usage: %prog [options]') |
71 options.add_option("--sdk_output_dir", | 71 options.add_option("--sdk_output_dir", |
72 help='Where to output the sdk') | 72 help='Where to output the sdk') |
73 options.add_option("--snapshot_location", | 73 options.add_option("--snapshot_location", |
74 help='Location of the snapshots.') | 74 help='Location of the snapshots.') |
75 return options.parse_args() | 75 return options.parse_args() |
76 | 76 |
77 | 77 |
78 def ReplaceInFiles(paths, subs): | 78 def ReplaceInFiles(paths, subs): |
79 '''Reads a series of files, applies a series of substitutions to each, and | 79 """Reads a series of files, applies a series of substitutions to each, and |
80 saves them back out. subs should by a list of (pattern, replace) tuples.''' | 80 saves them back out. subs should by a list of (pattern, replace) tuples.""" |
81 for path in paths: | 81 for path in paths: |
82 contents = open(path).read() | 82 contents = open(path).read() |
83 for pattern, replace in subs: | 83 for pattern, replace in subs: |
84 contents = re.sub(pattern, replace, contents) | 84 contents = re.sub(pattern, replace, contents) |
85 | 85 |
86 dest = open(path, 'w') | 86 dest = open(path, 'w') |
87 dest.write(contents) | 87 dest.write(contents) |
88 dest.close() | 88 dest.close() |
89 | 89 |
90 | 90 |
91 def Copy(src, dest): | 91 def Copy(src, dest): |
92 copyfile(src, dest) | 92 copyfile(src, dest) |
93 copymode(src, dest) | 93 copymode(src, dest) |
94 | 94 |
95 | 95 |
96 def CopyShellScript(src_file, dest_dir): | 96 def CopyShellScript(src_file, dest_dir): |
97 '''Copies a shell/batch script to the given destination directory. Handles | 97 """Copies a shell/batch script to the given destination directory. Handles |
98 using the appropriate platform-specific file extension.''' | 98 using the appropriate platform-specific file extension.""" |
99 file_extension = '' | 99 file_extension = '' |
100 if HOST_OS == 'win32': | 100 if HOST_OS == 'win32': |
101 file_extension = '.bat' | 101 file_extension = '.bat' |
102 | 102 |
103 src = src_file + file_extension | 103 src = src_file + file_extension |
104 dest = join(dest_dir, basename(src_file) + file_extension) | 104 dest = join(dest_dir, basename(src_file) + file_extension) |
105 Copy(src, dest) | 105 Copy(src, dest) |
106 | 106 |
107 | 107 |
108 def CopyDartScripts(home, sdk_root): | 108 def CopyDartScripts(home, sdk_root): |
109 for executable in ['dart2js', 'dartanalyzer', 'dartfmt', 'docgen', 'pub']: | 109 for executable in ['dart2js', 'dartanalyzer', 'dartfmt', 'docgen', 'pub']: |
110 CopyShellScript(os.path.join(home, 'sdk', 'bin', executable), | 110 CopyShellScript(os.path.join(home, 'sdk', 'bin', executable), |
111 os.path.join(sdk_root, 'bin')) | 111 os.path.join(sdk_root, 'bin')) |
112 | 112 |
113 | 113 |
114 def CopySnapshots(snapshots, sdk_root): | 114 def CopySnapshots(snapshots, sdk_root): |
115 for snapshot in ['dart2js', 'dartanalyzer', 'dartfmt', 'utils_wrapper', | 115 for snapshot in ['dart2js', 'dartanalyzer', 'dartfmt', 'utils_wrapper', |
116 'pub']: | 116 'pub']: |
117 snapshot += '.dart.snapshot' | 117 snapshot += '.dart.snapshot' |
118 copyfile(join(snapshots, snapshot), | 118 copyfile(join(snapshots, snapshot), |
119 join(sdk_root, 'bin', 'snapshots', snapshot)) | 119 join(sdk_root, 'bin', 'snapshots', snapshot)) |
120 | 120 |
121 | 121 |
122 def Main(argv): | 122 def Main(): |
123 # Pull in all of the gypi files which will be munged into the sdk. | 123 # Pull in all of the gypi files which will be munged into the sdk. |
124 HOME = dirname(dirname(realpath(__file__))) | 124 HOME = dirname(dirname(realpath(__file__))) |
125 | 125 |
126 (options, args) = GetOptions() | 126 (options, args) = GetOptions() |
127 | 127 |
128 SDK = options.sdk_output_dir | 128 SDK = options.sdk_output_dir |
129 SDK_tmp = '%s.tmp' % SDK | 129 SDK_tmp = '%s.tmp' % SDK |
130 | 130 |
131 SNAPSHOT = options.snapshot_location | 131 SNAPSHOT = options.snapshot_location |
132 | 132 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 if revision is not None: | 248 if revision is not None: |
249 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: | 249 with open(os.path.join(SDK_tmp, 'revision'), 'w') as f: |
250 f.write(revision + '\n') | 250 f.write(revision + '\n') |
251 f.close() | 251 f.close() |
252 | 252 |
253 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) | 253 Copy(join(HOME, 'README.dart-sdk'), join(SDK_tmp, 'README')) |
254 | 254 |
255 move(SDK_tmp, SDK) | 255 move(SDK_tmp, SDK) |
256 | 256 |
257 if __name__ == '__main__': | 257 if __name__ == '__main__': |
258 sys.exit(Main(sys.argv)) | 258 sys.exit(Main()) |
OLD | NEW |