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): |