OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 The IdlDefinitions object is guaranteed to contain a single | 66 The IdlDefinitions object is guaranteed to contain a single |
67 IdlInterface; it may also contain other definitions, such as | 67 IdlInterface; it may also contain other definitions, such as |
68 callback functions and enumerations.""" | 68 callback functions and enumerations.""" |
69 ast = blink_idl_parser.parse_file(self.parser, idl_filename) | 69 ast = blink_idl_parser.parse_file(self.parser, idl_filename) |
70 if not ast: | 70 if not ast: |
71 raise Exception('Failed to parse %s' % idl_filename) | 71 raise Exception('Failed to parse %s' % idl_filename) |
72 definitions = IdlDefinitions(ast) | 72 definitions = IdlDefinitions(ast) |
73 | 73 |
74 # Validate file contents with filename convention | 74 # Validate file contents with filename convention |
75 # The Blink IDL filenaming convention is that the file | 75 # The Blink IDL filenaming convention is that the file |
76 # <interface_name>.idl MUST contain exactly 1 interface (or exception), | 76 # <definition_name>.idl MUST contain exactly 1 definition |
77 # and the interface name must agree with the file's basename, | 77 # (interface, dictionary or exception), and the definition name must |
78 # unless it is a partial interface. | 78 # agree with the file's basename, unless it is a partial definition. |
79 # (e.g., 'partial interface Foo' can be in FooBar.idl). | 79 # (e.g., 'partial interface Foo' can be in FooBar.idl). |
80 number_of_interfaces = len(definitions.interfaces) | 80 targets = (definitions.interfaces.values() + |
81 if number_of_interfaces != 1: | 81 definitions.dictionaries.values()) |
| 82 number_of_targets = len(targets) |
| 83 if number_of_targets != 1: |
82 raise Exception( | 84 raise Exception( |
83 'Expected exactly 1 interface in file {0}, but found {1}' | 85 'Expected exactly 1 definition in file {0}, but found {1}' |
84 .format(idl_filename, number_of_interfaces)) | 86 .format(idl_filename, number_of_targets)) |
85 interface = next(definitions.interfaces.itervalues()) | 87 target = targets[0] |
86 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) | 88 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) |
87 if not interface.is_partial and interface.name != idl_file_basename: | 89 if not target.is_partial and target.name != idl_file_basename: |
88 raise Exception( | 90 raise Exception( |
89 'Interface name "{0}" disagrees with IDL file basename "{1}".' | 91 'Definition name "{0}" disagrees with IDL file basename "{1}".' |
90 .format(interface.name, idl_file_basename)) | 92 .format(target.name, idl_file_basename)) |
91 | 93 |
92 # Validate extended attributes | 94 # Validate extended attributes |
93 if not self.extended_attribute_validator: | 95 if not self.extended_attribute_validator: |
94 return definitions | 96 return definitions |
95 | 97 |
96 try: | 98 try: |
97 self.extended_attribute_validator.validate_extended_attributes(defin
itions) | 99 self.extended_attribute_validator.validate_extended_attributes(defin
itions) |
98 except IDLInvalidExtendedAttributeError as error: | 100 except IDLInvalidExtendedAttributeError as error: |
99 raise IDLInvalidExtendedAttributeError(""" | 101 raise IDLInvalidExtendedAttributeError(""" |
100 IDL ATTRIBUTE ERROR in file: | 102 IDL ATTRIBUTE ERROR in file: |
101 %s: | 103 %s: |
102 %s | 104 %s |
103 If you want to add a new IDL extended attribute, please add it to: | 105 If you want to add a new IDL extended attribute, please add it to: |
104 %s | 106 %s |
105 and add an explanation to the Blink IDL documentation at: | 107 and add an explanation to the Blink IDL documentation at: |
106 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes | 108 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes |
107 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH)) | 109 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH)) |
108 | 110 |
109 return definitions | 111 return definitions |
OLD | NEW |