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

Unified Diff: mojo/public/tools/bindings/generators/mojom_dart_generator.py

Issue 1071693003: Uses mojom module names as Dart's package: import URI (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/mojom_dart_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_dart_generator.py b/mojo/public/tools/bindings/generators/mojom_dart_generator.py
index fb1cfd4aca742e274329ad5be75de9d2b33ec486..33c94bf53973582a6cc482ffefbecf03629c4481 100644
--- a/mojo/public/tools/bindings/generators/mojom_dart_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_dart_generator.py
@@ -352,6 +352,16 @@ def IsPointerArrayKind(kind):
sub_kind = kind.kind
return mojom.IsObjectKind(sub_kind)
+def ParseStringAttribute(attribute):
+ assert isinstance(attribute, basestring)
+ return attribute
+
+def GetDartUriBase(module):
+ if module.attributes and 'DartUriBase' in module.attributes:
+ return ParseStringAttribute(module.attributes['DartUriBase'])
+ # Default Uri is the module's path in the host repo.
+ return os.path.dirname(module.path)
+
class Generator(generator.Generator):
dart_filters = {
@@ -396,12 +406,6 @@ class Generator(generator.Generator):
self.MatchMojomFilePath("%s.dart" % self.module.name))
def GetImports(self, args):
- mojo_root_arg = next(
- (x for x in args if x.startswith("--dart_mojo_root")), "")
- (_, _, mojo_root_path) = mojo_root_arg.partition("=")
- if not mojo_root_path.startswith("//"):
- raise Exception("Malformed mojo SDK root: " + mojo_root_path)
- mojo_root_path = mojo_root_path[2:] # strip //
used_names = set()
for each_import in self.module.imports:
simple_name = each_import["module_name"].split(".")[0]
@@ -418,15 +422,11 @@ class Generator(generator.Generator):
each_import["unique_name"] = unique_name + '_mojom'
counter += 1
- # At this point, a module's path is reletive to the root of the repo.
- # However, imports of libraries from the Mojo SDK are always reletive to
- # root of the Mojo SDK, which may be different from the root of the repo.
- # This code uses the --dart_mojo_root argument to ensure that Mojo SDK
- # imports are reletive to the Mojo SDK root.
path = each_import['module'].path
- if os.path.commonprefix([mojo_root_path, path]) == mojo_root_path:
- path = os.path.relpath(path, mojo_root_path)
- each_import["rebased_path"] = path
+ dart_uri = (GetDartUriBase(each_import['module']) + '/' +
+ os.path.basename(path))
+
+ each_import["rebased_path"] = dart_uri
return self.module.imports
def GetImportedInterfaces(self):

Powered by Google App Engine
This is Rietveld 408576698