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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator.py

Issue 1423213002: Fix the path for modules before passing them to the generator. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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 | « mojo/public/tools/bindings/invoke_code_generators.py ('k') | 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 # 5 #
6 # This module is responsible for translating a MojomFileGraph (see 6 # This module is responsible for translating a MojomFileGraph (see
7 # mojom_files.mojom) to one or more module.Module. 7 # mojom_files.mojom) to one or more module.Module.
8 # 8 #
9 # This module takes the output of the mojom parser, a MojomFileGraph and 9 # This module takes the output of the mojom parser, a MojomFileGraph and
10 # translates it to the input of the code generators, a module.Module object. 10 # translates it to the input of the code generators, a module.Module object.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 {module.Module} representing the translated file. 54 {module.Module} representing the translated file.
55 """ 55 """
56 mojom_file = self._graph.files[self._file_name] 56 mojom_file = self._graph.files[self._file_name]
57 57
58 mod = self._module 58 mod = self._module
59 self.PopulateModuleMetadata(mod, mojom_file) 59 self.PopulateModuleMetadata(mod, mojom_file)
60 60
61 mod.imports = [] 61 mod.imports = []
62 if mojom_file.imports: 62 if mojom_file.imports:
63 mod.imports = [self.ImportFromMojom(imp) for imp in mojom_file.imports] 63 mod.imports = [self.ImportFromMojom(imp) for imp in mojom_file.imports]
64 # TODO(azani): The key should be equal to SourceFileInfo.file_name of 64 # When translating an imported type, its SourceFileInfo.file_name is a key
65 # imported types. 65 # into self._imports. The value is the module from which the type was
66 # imported.
66 self._imports = {imp['module'].path: imp for imp in mod.imports} 67 self._imports = {imp['module'].path: imp for imp in mod.imports}
67 68
68 if mojom_file.declared_mojom_objects: 69 if mojom_file.declared_mojom_objects:
69 if mojom_file.declared_mojom_objects.top_level_constants: 70 if mojom_file.declared_mojom_objects.top_level_constants:
70 mod.constants = [ 71 mod.constants = [
71 self.ConstFromMojom( 72 self.ConstFromMojom(
72 self._graph.resolved_values[key].declared_constant, None) 73 self._graph.resolved_values[key].declared_constant, None)
73 for key in mojom_file.declared_mojom_objects.top_level_constants] 74 for key in mojom_file.declared_mojom_objects.top_level_constants]
74 75
75 user_defined_types = ['interfaces', 'structs', 'unions'] 76 user_defined_types = ['interfaces', 'structs', 'unions']
(...skipping 11 matching lines...) Expand all
87 def PopulateModuleMetadata(self, mod, mojom_file): 88 def PopulateModuleMetadata(self, mod, mojom_file):
88 """Populates some fields of a module.Module based on a MojomFile. 89 """Populates some fields of a module.Module based on a MojomFile.
89 90
90 Populates name, path, namespace and attributes of mod. 91 Populates name, path, namespace and attributes of mod.
91 92
92 Args: 93 Args:
93 mod: {module.Module} the module to be populated. 94 mod: {module.Module} the module to be populated.
94 mojom_file: {MojomFile} the file to be translated. 95 mojom_file: {MojomFile} the file to be translated.
95 """ 96 """
96 mod.name = os.path.basename(mojom_file.file_name) 97 mod.name = os.path.basename(mojom_file.file_name)
97 # TODO(azani): Fix the path here!
98 mod.path = mojom_file.file_name 98 mod.path = mojom_file.file_name
99 mod.namespace = mojom_file.module_namespace 99 mod.namespace = mojom_file.module_namespace
100 if mojom_file.attributes: 100 if mojom_file.attributes:
101 mod.attributes = {attr.key: attr.value for attr in mojom_file.attributes} 101 mod.attributes = {attr.key: attr.value for attr in mojom_file.attributes}
102 102
103 def ImportFromMojom(self, import_name): 103 def ImportFromMojom(self, import_name):
104 """Builds a dict representing an import. 104 """Builds a dict representing an import.
105 105
106 Args: 106 Args:
107 import_name: {str} key to the imported file in graph.files. 107 import_name: {str} key to the imported file in graph.files.
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 594
595 Args: 595 Args:
596 graph: {mojom_types_mojom.MojomFileGraph} to be translated. 596 graph: {mojom_types_mojom.MojomFileGraph} to be translated.
597 597
598 Return: 598 Return:
599 {dict<str, module.Module>} mapping the file's name to its module.Module 599 {dict<str, module.Module>} mapping the file's name to its module.Module
600 translation for all files in graph.files. 600 translation for all files in graph.files.
601 """ 601 """
602 return {file_name: FileTranslator(graph, file_name).Translate() 602 return {file_name: FileTranslator(graph, file_name).Translate()
603 for file_name in graph.files} 603 for file_name in graph.files}
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/invoke_code_generators.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698