Skip to content

Commit

Permalink
Fix duplicate import generation
Browse files Browse the repository at this point in the history
  • Loading branch information
syvb committed Apr 2, 2024
1 parent 63bba9c commit e734047
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,8 @@ class CGImports(CGWrapper):
"""
Generates the appropriate import/use statements.
"""
def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config):
def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config,
current_name=None):
"""
Adds a set of imports.
"""
Expand Down Expand Up @@ -2269,7 +2270,8 @@ def removeWrapperAndNullableTypes(types):
parentName = descriptor.getParentName()
while parentName:
descriptor = descriptorProvider.getDescriptor(parentName)
extras += [descriptor.path, descriptor.bindingPath]
if current_name != descriptor.ifaceName:
extras += [descriptor.path, descriptor.bindingPath]
parentName = descriptor.getParentName()
elif t.isType() and t.isRecord():
extras += ['crate::dom::bindings::record::Record']
Expand Down Expand Up @@ -6890,7 +6892,7 @@ class CGBindingRoot(CGThing):
DomRoot codegen class for binding generation. Instantiate the class, and call
declare or define to generate header or cpp code (respectively).
"""
def __init__(self, config, prefix, webIDLFile):
def __init__(self, config, prefix, webIDLFile, name):
descriptors = config.getDescriptors(webIDLFile=webIDLFile,
hasInterfaceObject=True)
# We also want descriptors that have an interface prototype object
Expand Down Expand Up @@ -6958,7 +6960,7 @@ def __init__(self, config, prefix, webIDLFile):
# These are the global imports (outside of the generated module)
curr = CGImports(curr, descriptors=callbackDescriptors, callbacks=mainCallbacks,
dictionaries=dictionaries, enums=enums, typedefs=typedefs,
imports=['crate::dom::bindings::import::base::*'], config=config)
imports=['crate::dom::bindings::import::base::*'], config=config, current_name=name)

# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT + ALLOWED_WARNINGS)
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/bindings/codegen/Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def __init__(self, config, interface, desc):
self.register = desc.get('register', True)
self.path = desc.get('path', pathDefault)
self.inRealmMethods = [name for name in desc.get('inRealms', [])]
self.ifaceName = ifaceName
self.bindingPath = f"crate::dom::bindings::codegen::Bindings::{ifaceName}Binding::{ifaceName}_Binding"
self.outerObjectHook = desc.get('outerObjectHook', 'None')
self.proxy = False
Expand Down
5 changes: 3 additions & 2 deletions components/script/dom/bindings/codegen/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def main():

for webidl in webidls:
filename = os.path.join(webidls_dir, webidl)
prefix = "Bindings/%sBinding" % webidl[:-len(".webidl")]
module = CGBindingRoot(config, prefix, filename).define()
name = webidl[:-len(".webidl")]
prefix = "Bindings/%sBinding" % name
module = CGBindingRoot(config, prefix, filename, name).define()
if module:
with open(os.path.join(out_dir, prefix + ".rs"), "wb") as f:
f.write(module.encode("utf-8"))
Expand Down

0 comments on commit e734047

Please sign in to comment.