Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: runtime/tools/concat_library.py

Issue 12321129: Expand part declarations in the builtin library python scripts to avoid having to repeat part decla… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/io_sources.gypi ('k') | sdk/lib/_collection_dev/collection_dev_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, 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 5
6 from os import path
6 import optparse 7 import optparse
7 import shutil 8 import shutil
8 import sys 9 import sys
9 10
10 def parse_options(argv): 11 def parse_options(argv):
11 parser = optparse.OptionParser(usage="Usage: %prog [options] files") 12 parser = optparse.OptionParser(usage="Usage: %prog [options] files")
12 parser.add_option("--output", 13 parser.add_option("--output",
13 dest="output", 14 dest="output",
14 help="Write output to FILE.", 15 help="Write output to FILE.",
15 metavar="FILE") 16 metavar="FILE")
16 (options, arguments) = parser.parse_args(argv[1:]) 17 (options, arguments) = parser.parse_args(argv[1:])
17 if not arguments: 18 if not arguments:
18 parser.error("At least one input file must be provided.") 19 parser.error("At least one input file must be provided.")
19 if not options.output: 20 if not options.output:
20 parser.error("No --output provided.") 21 parser.error("No --output provided.")
21 return (options, arguments) 22 return (options, arguments)
22 23
23 24
25 def concatenate_parts(source, output):
26 with open(source, 'r') as inpt:
27 for line in inpt:
28 # Concatenate all the parts into one big file and
29 # remove all the 'part of' declarations as everything
30 # is in one file.
31 if line.startswith('part '):
32 rest = (line[5:]).strip()
33 if rest.startswith('of'):
34 output.write('// %s' % line)
35 else:
36 file_name = rest[1:-2]
37 dir_name = path.dirname(source)
38 expanded_file_name = path.join(dir_name, file_name)
39 concatenate_parts(expanded_file_name, output)
40 else:
41 output.write(line)
42
43
24 def main(): 44 def main():
25 # Print the command that is being run. This is helpful when 45 # Print the command that is being run. This is helpful when
26 # debugging build errors. 46 # debugging build errors.
27 sys.stderr.write('%s\n' % ' '.join(sys.argv)) 47 sys.stderr.write('%s\n' % ' '.join(sys.argv))
28 (options, arguments) = parse_options(sys.argv) 48 (options, arguments) = parse_options(sys.argv)
29 tmp_name = '%s.tmp' % options.output 49 tmp_name = '%s.tmp' % options.output
30 with open(tmp_name, 'w') as output: 50 with open(tmp_name, 'w') as output:
31 for source in arguments: 51 for source in arguments:
32 with open(source, 'r') as inpt: 52 concatenate_parts(source, output)
33 for line in inpt:
34 # Drop unneeded library tags as all the library's files
35 # are concatenated into one big file here:
36 # The 'part' and 'part of' library tags are removed.
37 if line.startswith('#source') or line.startswith('part '):
38 line = '// %s' % line
39 output.write(line)
40 shutil.move(tmp_name, options.output) 53 shutil.move(tmp_name, options.output)
41 54
42 if __name__ == '__main__': 55 if __name__ == '__main__':
43 main() 56 main()
OLDNEW
« no previous file with comments | « runtime/bin/io_sources.gypi ('k') | sdk/lib/_collection_dev/collection_dev_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698