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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_dart_generator.py

Issue 1826063002: Generated dart code should import transitive imports. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generates dart source files from a mojom.Module.""" 5 """Generates dart source files from a mojom.Module."""
6 6
7 import errno 7 import errno
8 import os 8 import os
9 import re 9 import re
10 import shutil 10 import shutil
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 else: 594 else:
595 os.symlink(full_gen_path, full_link_path) 595 os.symlink(full_gen_path, full_link_path)
596 except OSError as e: 596 except OSError as e:
597 # Errno 17 is file already exists. If the link fails because file already 597 # Errno 17 is file already exists. If the link fails because file already
598 # exists assume another instance of this script tried to create the same 598 # exists assume another instance of this script tried to create the same
599 # file and continue on. 599 # file and continue on.
600 if e.errno != 17: 600 if e.errno != 17:
601 raise e 601 raise e
602 602
603 def GetImports(self, args): 603 def GetImports(self, args):
604 used_imports = self.GetUsedImports(self.module)
604 used_names = set() 605 used_names = set()
605 for each_import in self.module.transitive_imports: 606 for each_import in used_imports.values():
606 simple_name = each_import["module_name"].split(".")[0] 607 simple_name = each_import["module_name"].split(".")[0]
607 608
608 # Since each import is assigned a library in Dart, they need to have 609 # Since each import is assigned a library in Dart, they need to have
609 # unique names. 610 # unique names.
610 unique_name = simple_name 611 unique_name = simple_name
611 counter = 0 612 counter = 0
612 while unique_name in used_names: 613 while unique_name in used_names:
613 counter += 1 614 counter += 1
614 unique_name = simple_name + str(counter) 615 unique_name = simple_name + str(counter)
615 616
616 used_names.add(unique_name) 617 used_names.add(unique_name)
617 each_import["unique_name"] = unique_name + '_mojom' 618 each_import["unique_name"] = unique_name + '_mojom'
618 counter += 1 619 counter += 1
619 620
620 each_import["rebased_path"] = GetImportUri(each_import['module']) 621 each_import["rebased_path"] = GetImportUri(each_import['module'])
621 return self.module.imports 622 return sorted(used_imports.values(), key=lambda x: x['rebased_path'])
622 623
623 def GetImportedInterfaces(self): 624 def GetImportedInterfaces(self):
624 interface_to_import = {} 625 interface_to_import = {}
625 for each_import in self.module.imports: 626 for each_import in self.module.imports:
626 for each_interface in each_import["module"].interfaces: 627 for each_interface in each_import["module"].interfaces:
627 name = each_interface.name 628 name = each_interface.name
628 interface_to_import[name] = each_import["unique_name"] + "." + name 629 interface_to_import[name] = each_import["unique_name"] + "." + name
629 return interface_to_import 630 return interface_to_import
630 631
631 def ImportedFrom(self): 632 def ImportedFrom(self):
632 interface_to_import = {} 633 interface_to_import = {}
633 for each_import in self.module.imports: 634 for each_import in self.module.imports:
634 for each_interface in each_import["module"].interfaces: 635 for each_interface in each_import["module"].interfaces:
635 name = each_interface.name 636 name = each_interface.name
636 interface_to_import[name] = each_import["unique_name"] + "." 637 interface_to_import[name] = each_import["unique_name"] + "."
637 return interface_to_import 638 return interface_to_import
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698