Chromium Code Reviews| Index: dart/editor/build/generate_sources.py |
| diff --git a/dart/editor/build/generate_sources.py b/dart/editor/build/generate_sources.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a5bef26d9e82321eacdc7742aa361f14c937ea2 |
| --- /dev/null |
| +++ b/dart/editor/build/generate_sources.py |
| @@ -0,0 +1,160 @@ |
| +'touch_file'#!/usr/bin/env python |
|
kustermann
2013/01/31 14:35:53
What is this 'touch_file' doing there?
ricow1
2013/01/31 14:42:11
remove 'touch_file'
ahe
2013/02/04 11:12:05
Done.
ahe
2013/02/04 11:12:05
Done.
|
| +# Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +# for details. All rights reserved. Use of this source code is governed by a |
| +# BSD-style license that can be found in the LICENSE file. |
| + |
| +import StringIO |
| +import os |
| +import sys |
| + |
| +from os.path import join |
| + |
| + |
| +def _print_gypi_files(out, name, files): |
| + out.write(" '%s': [\n" % name) |
| + for filename in files: |
| + out.write(''' r'%s',%s''' % (filename, '\n')) |
| + out.write(" ],\n") |
| + |
| + |
| +def _close(file_name, output): |
| + if not isinstance(output, StringIO.StringIO): |
| + output.close() |
| + return |
| + new_text = output.getvalue() |
| + output.close() |
| + with open(file_name, 'r') as f: |
| + old_text = f.read() |
| + if old_text == new_text: |
| + return |
| + with open(file_name, 'w') as f: |
| + f.write(new_text) |
| + |
| + |
| +def _make_output(fileName): |
| + if os.path.exists(fileName): |
| + return StringIO.StringIO() |
|
ricow1
2013/01/31 14:42:11
Is it really worth it to create a memory file here
ahe
2013/02/04 11:12:05
I don't understand what you see the alternative is
|
| + else: |
| + return file(fileName, 'w') |
| + |
| + |
| +def GenerateGypiFile(sources, outputFile): |
| + gypi = _make_output(outputFile) |
| + gypi.write("{\n 'variables': {\n") |
| + _print_gypi_files(gypi, 'sources', sources) |
| + gypi.write(" },\n}\n") |
| + _close(outputFile, gypi) |
| + |
| + |
| +def _list_sources(path, extension): |
| + sources = [] |
| + for fullpath, dirs, filenames in os.walk(path): |
| + remove_me = [d for d in dirs if d.startswith('.')] |
| + for d in remove_me: |
|
ricow1
2013/01/31 14:42:11
what does this do? remove .svn directories?
ahe
2013/02/04 11:12:05
It filters out all directories that start with a d
|
| + dirs.remove(d) |
| + for filename in filenames: |
| + if (filename.endswith(extension)): |
| + sources.append(os.path.relpath(join(fullpath, filename), |
| + start='editor/build/generated/')) |
| + sources.sort() |
| + return sources |
| + |
| + |
| +def _list_pkgs(path): |
| + result = None |
| + for dirpath, dirnames, filenames in os.walk(path): |
| + result = dirnames[:] # Copy array. |
| + del dirnames[:] # Stop recursion by clearing array. |
| + return result |
| + |
| + |
| +def _split_sources(path, extension): |
| + result = [] |
| + count = 100 |
| + segment = -1 |
| + sources = None |
| + for source in _list_sources(path, extension): |
| + if count == 100: |
| + count = 0 |
| + segment += 1 |
| + sources = [] |
| + result.append(('chunk%s' % segment, sources)) |
| + sources.append(source) |
| + count += 1 |
| + return result |
| + |
| +def _print_pkg_action(pkg, out): |
| + print >> out, """ |
| + { |
| + 'includes': [ |
| + '%(pkg)s_sources.gypi', |
| + ], |
| + 'action_name': '%(pkg)s_action', |
| + 'inputs': [ |
| + '%(pkg)s_sources.gypi', |
| + '<@(sources)', |
| + ], |
| + 'outputs': [ |
| + '<(SHARED_INTERMEDIATE_DIR)/editor_deps/%(pkg)s.stamp', |
| + ], |
| + 'action': [ |
| + 'python', |
| + '../touch_file.py', |
| + '<@(_outputs)', |
| + '<@(_inputs)', |
| + ], |
| + 'message': 'Creating %(pkg)s time stamp.', |
| + }, |
| +""" % {'pkg':pkg} |
| + |
| + |
| +def Main(argv): |
| + # move up to the parent 'dart' directory |
| + base_directory = join(os.path.dirname(argv[0]), '..', '..') |
| + os.chdir(base_directory) |
| + |
| + pkg_dir = join('editor', 'tools', 'plugins') |
| + out_dir = join('editor', 'build', 'generated') |
| + |
| + if not os.path.exists(out_dir): |
| + os.mkdir(out_dir) |
| + |
| + with open(join(out_dir, 'editor_deps.gyp'), 'w') as gyp: |
| + stamps = [] |
| + print >> gyp, """ |
| +{ |
| + 'targets': [ |
| + { |
| + 'target_name': 'editor_deps', |
| + 'type': 'none', |
| + 'actions': [""" |
| + for pkg, sources in _split_sources(pkg_dir, '.java'): |
|
ricow1
2013/01/31 14:42:11
add a blank line before this, it is hard to read o
ahe
2013/02/04 11:12:05
Done.
|
| + GenerateGypiFile(sources, join(out_dir, '%s_sources.gypi' % pkg)) |
| + _print_pkg_action(pkg, gyp) |
| + stamps.append("'<(SHARED_INTERMEDIATE_DIR)/editor_deps/%s.stamp'" % pkg) |
| + |
| + |
| + print >> gyp, """ |
| + { |
| + 'action_name': 'editor_stamp_action', |
| + 'inputs': [ |
| + %s, |
| + ], |
| + 'outputs': [ |
| + '<(SHARED_INTERMEDIATE_DIR)/editor_deps/editor.stamp', |
| + ], |
| + 'action': [ |
| + 'python', |
| + '../touch_file.py', |
| + '<@(_outputs)', |
| + ], |
| + 'message': 'Creating editor time stamp.', |
| + }, |
| + ], |
| + }, |
| + ], |
| +} |
| +""" % (",\n".join(stamps)) |
| + |
| +if __name__ == '__main__': |
| + sys.exit(Main(sys.argv)) |