OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Miscellaneous node types. | 6 """Miscellaneous node types. |
7 """ | 7 """ |
8 | 8 |
9 import os.path | 9 import os.path |
10 import re | 10 import re |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 Returns a tuple, the absolute path of SRCDIR followed by the | 42 Returns a tuple, the absolute path of SRCDIR followed by the |
43 first_ids dictionary. | 43 first_ids dictionary. |
44 """ | 44 """ |
45 first_ids_dict = eval(util.ReadFile(filename, util.RAW_TEXT)) | 45 first_ids_dict = eval(util.ReadFile(filename, util.RAW_TEXT)) |
46 src_root_dir = os.path.abspath(os.path.join(os.path.dirname(filename), | 46 src_root_dir = os.path.abspath(os.path.join(os.path.dirname(filename), |
47 first_ids_dict['SRCDIR'])) | 47 first_ids_dict['SRCDIR'])) |
48 | 48 |
49 def ReplaceVariable(matchobj): | 49 def ReplaceVariable(matchobj): |
50 for key, value in defines.iteritems(): | 50 for key, value in defines.iteritems(): |
51 if matchobj.group(1) == key: | 51 if matchobj.group(1) == key: |
52 value = os.path.abspath(value)[len(src_root_dir) + 1:] | |
53 return value | 52 return value |
54 return '' | 53 return '' |
55 | 54 |
56 renames = [] | 55 renames = [] |
57 for grd_filename in first_ids_dict: | 56 for grd_filename in first_ids_dict: |
58 new_grd_filename = re.sub(r'<\(([A-Za-z_]+)\)', ReplaceVariable, | 57 new_grd_filename = re.sub(r'<\(([A-Za-z_]+)\)', ReplaceVariable, |
59 grd_filename) | 58 grd_filename) |
60 if new_grd_filename != grd_filename: | 59 if new_grd_filename != grd_filename: |
61 new_grd_filename = new_grd_filename.replace('\\', '/') | 60 abs_grd_filename = os.path.abspath(new_grd_filename) |
| 61 if abs_grd_filename[:len(src_root_dir)] != src_root_dir: |
| 62 new_grd_filename = os.path.basename(abs_grd_filename) |
| 63 else: |
| 64 new_grd_filename = abs_grd_filename[len(src_root_dir) + 1:] |
| 65 new_grd_filename = new_grd_filename.replace('\\', '/') |
62 renames.append((grd_filename, new_grd_filename)) | 66 renames.append((grd_filename, new_grd_filename)) |
63 | 67 |
64 for grd_filename, new_grd_filename in renames: | 68 for grd_filename, new_grd_filename in renames: |
65 first_ids_dict[new_grd_filename] = first_ids_dict[grd_filename] | 69 first_ids_dict[new_grd_filename] = first_ids_dict[grd_filename] |
66 del(first_ids_dict[grd_filename]) | 70 del(first_ids_dict[grd_filename]) |
67 | 71 |
68 return (src_root_dir, first_ids_dict) | 72 return (src_root_dir, first_ids_dict) |
69 | 73 |
70 | 74 |
71 class SplicingNode(base.Node): | 75 class SplicingNode(base.Node): |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 by parameters of the same name. | 514 by parameters of the same name. |
511 """ | 515 """ |
512 node = IdentifierNode() | 516 node = IdentifierNode() |
513 node.StartParsing('identifier', parent) | 517 node.StartParsing('identifier', parent) |
514 node.HandleAttribute('name', name) | 518 node.HandleAttribute('name', name) |
515 node.HandleAttribute('id', id) | 519 node.HandleAttribute('id', id) |
516 node.HandleAttribute('comment', comment) | 520 node.HandleAttribute('comment', comment) |
517 node.HandleAttribute('systemid', systemid) | 521 node.HandleAttribute('systemid', systemid) |
518 node.EndParsing() | 522 node.EndParsing() |
519 return node | 523 return node |
OLD | NEW |