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

Side by Side Diff: bindings/scripts/idl_reader.py

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 years, 10 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
« no previous file with comments | « bindings/scripts/idl_definitions.py ('k') | bindings/scripts/idl_types.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24 matching lines...) Expand all
35 import os 35 import os
36 36
37 import blink_idl_parser 37 import blink_idl_parser
38 from blink_idl_parser import BlinkIDLParser 38 from blink_idl_parser import BlinkIDLParser
39 from idl_definitions import IdlDefinitions 39 from idl_definitions import IdlDefinitions
40 from idl_validator import EXTENDED_ATTRIBUTES_RELATIVE_PATH, IDLInvalidExtendedA ttributeError, IDLExtendedAttributeValidator 40 from idl_validator import EXTENDED_ATTRIBUTES_RELATIVE_PATH, IDLInvalidExtendedA ttributeError, IDLExtendedAttributeValidator
41 from interface_dependency_resolver import InterfaceDependencyResolver 41 from interface_dependency_resolver import InterfaceDependencyResolver
42 from utilities import idl_filename_to_component 42 from utilities import idl_filename_to_component
43 43
44 44
45 def validate_blink_idl_definitions(idl_filename, idl_file_basename,
46 definitions):
47 """Validate file contents with filename convention.
48
49 The Blink IDL conventions are:
50 - If an IDL file defines an interface, a dictionary, or an exception,
51 the IDL file must contain exactly one definition. The definition
52 name must agree with the file's basename, unless it is a partial
53 definition. (e.g., 'partial interface Foo' can be in FooBar.idl).
54 - An IDL file can contain typedefs and enums without having other
55 definitions. There is no filename convention in this case.
56 - Otherwise, an IDL file is invalid.
57 """
58 targets = (definitions.interfaces.values() +
59 definitions.dictionaries.values())
60 number_of_targets = len(targets)
61 if number_of_targets > 1:
62 raise Exception(
63 'Expected exactly 1 definition in file {0}, but found {1}'
64 .format(idl_filename, number_of_targets))
65 if number_of_targets == 0:
66 if not (definitions.enumerations or definitions.typedefs):
67 raise Exception(
68 'No definition found in %s' % idl_filename)
69 return
70 target = targets[0]
71 if not target.is_partial and target.name != idl_file_basename:
72 raise Exception(
73 'Definition name "{0}" disagrees with IDL file basename "{1}".'
74 .format(target.name, idl_file_basename))
75
76
45 class IdlReader(object): 77 class IdlReader(object):
46 def __init__(self, interfaces_info=None, outputdir='', multi_interface=False ): 78 def __init__(self, interfaces_info=None, outputdir='', multi_interface=False ):
47 self.multi_interface = multi_interface 79 self.multi_interface = multi_interface
48 self.extended_attribute_validator = IDLExtendedAttributeValidator() 80 self.extended_attribute_validator = IDLExtendedAttributeValidator()
49 self.interfaces_info = interfaces_info 81 self.interfaces_info = interfaces_info
50 82
51 if interfaces_info: 83 if interfaces_info:
52 self.interface_dependency_resolver = InterfaceDependencyResolver(int erfaces_info, self) 84 self.interface_dependency_resolver = InterfaceDependencyResolver(int erfaces_info, self)
53 else: 85 else:
54 self.interface_dependency_resolver = None 86 self.interface_dependency_resolver = None
(...skipping 21 matching lines...) Expand all
76 The IdlDefinitions object is guaranteed to contain a single 108 The IdlDefinitions object is guaranteed to contain a single
77 IdlInterface; it may also contain other definitions, such as 109 IdlInterface; it may also contain other definitions, such as
78 callback functions and enumerations.""" 110 callback functions and enumerations."""
79 ast = blink_idl_parser.parse_file(self.parser, idl_filename) 111 ast = blink_idl_parser.parse_file(self.parser, idl_filename)
80 if not ast: 112 if not ast:
81 raise Exception('Failed to parse %s' % idl_filename) 113 raise Exception('Failed to parse %s' % idl_filename)
82 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) 114 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
83 definitions = IdlDefinitions(idl_file_basename, ast) 115 definitions = IdlDefinitions(idl_file_basename, ast)
84 116
85 if not self.multi_interface: 117 if not self.multi_interface:
86 # Validate file contents with filename convention 118 validate_blink_idl_definitions(idl_filename, idl_file_basename, defi nitions)
87 # The Blink IDL filenaming convention is that the file
88 # <definition_name>.idl MUST contain exactly 1 definition
89 # (interface, dictionary or exception), and the definition name must
90 # agree with the file's basename, unless it is a partial definition.
91 # (e.g., 'partial interface Foo' can be in FooBar.idl).
92 targets = (definitions.interfaces.values() +
93 definitions.dictionaries.values())
94 number_of_targets = len(targets)
95 if number_of_targets != 1:
96 raise Exception(
97 'Expected exactly 1 definition in file {0}, but found {1}'
98 .format(idl_filename, number_of_targets))
99 target = targets[0]
100 if not target.is_partial and target.name != idl_file_basename:
101 raise Exception(
102 'Definition name "{0}" disagrees with IDL file basename "{1} ".'
103 .format(target.name, idl_file_basename))
104 else: 119 else:
105 if len(definitions.interfaces) > 1: 120 if len(definitions.interfaces) > 1:
106 print '----- Supplemental interfaces %s' % len(definitions.inter faces) 121 print '----- Supplemental interfaces %s' % len(definitions.inter faces)
107 122
108 # Validate extended attributes 123 # Validate extended attributes
109 if not self.extended_attribute_validator: 124 if not self.extended_attribute_validator:
110 return definitions 125 return definitions
111 126
112 try: 127 try:
113 self.extended_attribute_validator.validate_extended_attributes(defin itions) 128 self.extended_attribute_validator.validate_extended_attributes(defin itions)
114 except IDLInvalidExtendedAttributeError as error: 129 except IDLInvalidExtendedAttributeError as error:
115 raise IDLInvalidExtendedAttributeError(""" 130 raise IDLInvalidExtendedAttributeError("""
116 IDL ATTRIBUTE ERROR in file: 131 IDL ATTRIBUTE ERROR in file:
117 %s: 132 %s:
118 %s 133 %s
119 If you want to add a new IDL extended attribute, please add it to: 134 If you want to add a new IDL extended attribute, please add it to:
120 %s 135 %s
121 and add an explanation to the Blink IDL documentation at: 136 and add an explanation to the Blink IDL documentation at:
122 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes 137 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
123 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH)) 138 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH))
124 139
125 return definitions 140 return definitions
OLDNEW
« no previous file with comments | « bindings/scripts/idl_definitions.py ('k') | bindings/scripts/idl_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698