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

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

Issue 469253004: Blink-in-JS: A very simple refactoring about a way to get a basename of an IDL file (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 def read_idl_file(self, idl_filename): 63 def read_idl_file(self, idl_filename):
64 """Returns an IdlDefinitions object for an IDL file, without any depende ncies. 64 """Returns an IdlDefinitions object for an IDL file, without any depende ncies.
65 65
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 idl_name = os.path.basename(idl_filename) 72 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
73 definitions = IdlDefinitions(idl_name, ast) 73 definitions = IdlDefinitions(idl_file_basename, ast)
74 74
75 # Validate file contents with filename convention 75 # Validate file contents with filename convention
76 # The Blink IDL filenaming convention is that the file 76 # The Blink IDL filenaming convention is that the file
77 # <definition_name>.idl MUST contain exactly 1 definition 77 # <definition_name>.idl MUST contain exactly 1 definition
78 # (interface, dictionary or exception), and the definition name must 78 # (interface, dictionary or exception), and the definition name must
79 # agree with the file's basename, unless it is a partial definition. 79 # agree with the file's basename, unless it is a partial definition.
80 # (e.g., 'partial interface Foo' can be in FooBar.idl). 80 # (e.g., 'partial interface Foo' can be in FooBar.idl).
81 targets = (definitions.interfaces.values() + 81 targets = (definitions.interfaces.values() +
82 definitions.dictionaries.values()) 82 definitions.dictionaries.values())
83 number_of_targets = len(targets) 83 number_of_targets = len(targets)
84 if number_of_targets != 1: 84 if number_of_targets != 1:
85 raise Exception( 85 raise Exception(
86 'Expected exactly 1 definition in file {0}, but found {1}' 86 'Expected exactly 1 definition in file {0}, but found {1}'
87 .format(idl_filename, number_of_targets)) 87 .format(idl_filename, number_of_targets))
88 target = targets[0] 88 target = targets[0]
89 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
90 if not target.is_partial and target.name != idl_file_basename: 89 if not target.is_partial and target.name != idl_file_basename:
91 raise Exception( 90 raise Exception(
92 'Definition name "{0}" disagrees with IDL file basename "{1}".' 91 'Definition name "{0}" disagrees with IDL file basename "{1}".'
93 .format(target.name, idl_file_basename)) 92 .format(target.name, idl_file_basename))
94 93
95 # Validate extended attributes 94 # Validate extended attributes
96 if not self.extended_attribute_validator: 95 if not self.extended_attribute_validator:
97 return definitions 96 return definitions
98 97
99 try: 98 try:
100 self.extended_attribute_validator.validate_extended_attributes(defin itions) 99 self.extended_attribute_validator.validate_extended_attributes(defin itions)
101 except IDLInvalidExtendedAttributeError as error: 100 except IDLInvalidExtendedAttributeError as error:
102 raise IDLInvalidExtendedAttributeError(""" 101 raise IDLInvalidExtendedAttributeError("""
103 IDL ATTRIBUTE ERROR in file: 102 IDL ATTRIBUTE ERROR in file:
104 %s: 103 %s:
105 %s 104 %s
106 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:
107 %s 106 %s
108 and add an explanation to the Blink IDL documentation at: 107 and add an explanation to the Blink IDL documentation at:
109 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes 108 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
110 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH)) 109 """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH))
111 110
112 return definitions 111 return definitions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698