OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 """Used to merge and copy dart source files for deployment to AppEngine""" | 5 """Used to merge and copy dart source files for deployment to AppEngine""" |
6 | 6 |
7 import fileinput | 7 import fileinput |
8 import sys | 8 import sys |
9 import shutil | |
10 import os | 9 import os |
11 import re | 10 import re |
12 from os.path import abspath, basename, dirname, exists, isabs, join | 11 from os.path import basename, dirname, exists, isabs, join |
13 from glob import glob | 12 from glob import glob |
14 | 13 |
15 re_directive = re.compile( | 14 re_directive = re.compile( |
16 r'^(library|import|part|native|resource)\s+(.*);$') | 15 r'^(library|import|part|native|resource)\s+(.*);$') |
17 re_comment = re.compile( | 16 re_comment = re.compile( |
18 r'^(///|/\*| \*).*$') | 17 r'^(///|/\*| \*).*$') |
19 | 18 |
20 class Library(object): | 19 class Library(object): |
21 def __init__(self, name, imports, sources, natives, code, comment): | 20 def __init__(self, name, imports, sources, natives, code, comment): |
22 self.name = name | 21 self.name = name |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 68 |
70 def mergefiles(srcs, dstfile): | 69 def mergefiles(srcs, dstfile): |
71 for src in srcs: | 70 for src in srcs: |
72 with open(src, 'r') as s: | 71 with open(src, 'r') as s: |
73 for line in s: | 72 for line in s: |
74 if not line.startswith('part of '): | 73 if not line.startswith('part of '): |
75 dstfile.write(line) | 74 dstfile.write(line) |
76 | 75 |
77 def main(outdir = None, *inputs): | 76 def main(outdir = None, *inputs): |
78 if not outdir or not inputs: | 77 if not outdir or not inputs: |
79 print "Usage: %s OUTDIR INPUTS" % args[0] | 78 print "Usage: %s OUTDIR INPUTS" % sys.argv[0] |
80 print " OUTDIR is the war directory to copy to" | 79 print " OUTDIR is the war directory to copy to" |
81 print " INPUTS is a list of files or patterns used to specify the input" | 80 print " INPUTS is a list of files or patterns used to specify the input" |
82 print " .dart files" | 81 print " .dart files" |
83 print "This script should be run from the client root directory." | 82 print "This script should be run from the client root directory." |
84 print "Files will be merged and copied to: OUTDIR/relative-path-of-file," | 83 print "Files will be merged and copied to: OUTDIR/relative-path-of-file," |
85 print "except for dart files with absolute paths, which will be copied to" | 84 print "except for dart files with absolute paths, which will be copied to" |
86 print " OUTDIR/absolute-path-as-directories" | 85 print " OUTDIR/absolute-path-as-directories" |
87 return 1 | 86 return 1 |
88 | 87 |
89 entry_libraries = [] | 88 entry_libraries = [] |
(...skipping 27 matching lines...) Expand all Loading... |
117 | 116 |
118 # Create file containing all imports, and inlining all sources | 117 # Create file containing all imports, and inlining all sources |
119 with open(outpath, 'w') as f: | 118 with open(outpath, 'w') as f: |
120 if library.name: | 119 if library.name: |
121 if library.comment: | 120 if library.comment: |
122 f.write('%s' % (''.join(library.comment))) | 121 f.write('%s' % (''.join(library.comment))) |
123 f.write("library %s;\n\n" % library.name) | 122 f.write("library %s;\n\n" % library.name) |
124 else: | 123 else: |
125 f.write("library %s;\n\n" % basename(lib)) | 124 f.write("library %s;\n\n" % basename(lib)) |
126 for importfile in library.imports: | 125 for importfile in library.imports: |
127 f.write("import %s;\n" % (importfile)) | 126 f.write("import %s;\n" % importfile) |
128 f.write('%s' % (''.join(library.code))) | 127 f.write('%s' % (''.join(library.code))) |
129 mergefiles([normjoin(dirname(lib), s) for s in library.sources], f) | 128 mergefiles([normjoin(dirname(lib), s) for s in library.sources], f) |
130 | 129 |
131 for suffix in library.imports: | 130 for suffix in library.imports: |
132 m = re.match(r'[\'"]([^\'"]+)[\'"](\s+as\s+\w+)?.*$', suffix) | 131 m = re.match(r'[\'"]([^\'"]+)[\'"](\s+as\s+\w+)?.*$', suffix) |
133 uri = m.group(1) | 132 uri = m.group(1) |
134 if not uri.startswith('dart:'): | 133 if not uri.startswith('dart:'): |
135 worklist.append(normjoin(dirname(lib), uri)); | 134 worklist.append(normjoin(dirname(lib), uri)) |
136 | 135 |
137 return 0 | 136 return 0 |
138 | 137 |
139 if __name__ == '__main__': | 138 if __name__ == '__main__': |
140 sys.exit(main(*sys.argv[1:])) | 139 sys.exit(main(*sys.argv[1:])) |
OLD | NEW |