Index: runtime/tools/concat_library.py |
diff --git a/runtime/tools/concat_library.py b/runtime/tools/concat_library.py |
index dfb574a3402df11f70338fbdcc6123208f450db5..ca498a69d6867832d7c21a0047551bc88af24f6e 100644 |
--- a/runtime/tools/concat_library.py |
+++ b/runtime/tools/concat_library.py |
@@ -3,6 +3,7 @@ |
# 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. |
+from os import path |
import optparse |
import shutil |
import sys |
@@ -21,6 +22,25 @@ def parse_options(argv): |
return (options, arguments) |
+def concatenate_parts(source, output): |
+ with open(source, 'r') as inpt: |
+ for line in inpt: |
+ # Concatenate all the parts into one big file and |
+ # remove all the 'part of' declarations as everything |
+ # is in one file. |
+ if line.startswith('part '): |
+ rest = (line[5:]).strip() |
+ if rest.startswith('of'): |
+ output.write('// %s' % line) |
+ else: |
+ file_name = rest[1:-2] |
+ dir_name = path.dirname(source) |
+ expanded_file_name = path.join(dir_name, file_name) |
+ concatenate_parts(expanded_file_name, output) |
+ else: |
+ output.write(line) |
+ |
+ |
def main(): |
# Print the command that is being run. This is helpful when |
# debugging build errors. |
@@ -29,14 +49,7 @@ def main(): |
tmp_name = '%s.tmp' % options.output |
with open(tmp_name, 'w') as output: |
for source in arguments: |
- with open(source, 'r') as inpt: |
- for line in inpt: |
- # Drop unneeded library tags as all the library's files |
- # are concatenated into one big file here: |
- # The 'part' and 'part of' library tags are removed. |
- if line.startswith('#source') or line.startswith('part '): |
- line = '// %s' % line |
- output.write(line) |
+ concatenate_parts(source, output) |
shutil.move(tmp_name, options.output) |
if __name__ == '__main__': |