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

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

Issue 1092793005: Dart: Put generated .mojom.dart files under mojoms pacakge. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge 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 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 os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import sys 10 import sys
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 353
354 def IsPointerArrayKind(kind): 354 def IsPointerArrayKind(kind):
355 if not mojom.IsArrayKind(kind): 355 if not mojom.IsArrayKind(kind):
356 return False 356 return False
357 sub_kind = kind.kind 357 sub_kind = kind.kind
358 return mojom.IsObjectKind(sub_kind) 358 return mojom.IsObjectKind(sub_kind)
359 359
360 def GetImportUri(module): 360 def GetImportUri(module):
361 elements = module.namespace.split('.') 361 elements = module.namespace.split('.')
362 elements.append("%s" % module.name) 362 elements.append("%s" % module.name)
363 return os.path.join(*elements) 363 return os.path.join("mojoms", *elements)
364 364
365 class Generator(generator.Generator): 365 class Generator(generator.Generator):
366 366
367 dart_filters = { 367 dart_filters = {
368 'array_expected_length': GetArrayExpectedLength, 368 'array_expected_length': GetArrayExpectedLength,
369 'array': GetArrayKind, 369 'array': GetArrayKind,
370 'decode_method': DecodeMethod, 370 'decode_method': DecodeMethod,
371 'default_value': DartDefaultValue, 371 'default_value': DartDefaultValue,
372 'encode_method': EncodeMethod, 372 'encode_method': EncodeMethod,
373 'expression_to_text': ExpressionToText, 373 'expression_to_text': ExpressionToText,
(...skipping 21 matching lines...) Expand all
395 "imported_from": self.ImportedFrom(), 395 "imported_from": self.ImportedFrom(),
396 } 396 }
397 397
398 @UseJinja("dart_templates/module.lib.tmpl", filters=dart_filters) 398 @UseJinja("dart_templates/module.lib.tmpl", filters=dart_filters)
399 def GenerateLibModule(self, args): 399 def GenerateLibModule(self, args):
400 return self.GetParameters(args) 400 return self.GetParameters(args)
401 401
402 def GenerateFiles(self, args): 402 def GenerateFiles(self, args):
403 elements = self.module.namespace.split('.') 403 elements = self.module.namespace.split('.')
404 elements.append("%s.dart" % self.module.name) 404 elements.append("%s.dart" % self.module.name)
405 path = os.path.join("dart-gen", *elements) 405 path = os.path.join("dart-gen", "mojoms", *elements)
406 self.Write(self.GenerateLibModule(args), path) 406 self.Write(self.GenerateLibModule(args), path)
407 link = self.MatchMojomFilePath("%s.dart" % self.module.name) 407 link = self.MatchMojomFilePath("%s.dart" % self.module.name)
408 if os.path.exists(os.path.join(self.output_dir, link)): 408 if os.path.exists(os.path.join(self.output_dir, link)):
409 os.unlink(os.path.join(self.output_dir, link)) 409 os.unlink(os.path.join(self.output_dir, link))
410 if sys.platform == "win32": 410 if sys.platform == "win32":
411 shutil.copy(os.path.join(self.output_dir, path), 411 shutil.copy(os.path.join(self.output_dir, path),
412 os.path.join(self.output_dir, link)) 412 os.path.join(self.output_dir, link))
413 else: 413 else:
414 os.symlink(os.path.join(self.output_dir, path), 414 os.symlink(os.path.join(self.output_dir, path),
415 os.path.join(self.output_dir, link)) 415 os.path.join(self.output_dir, link))
(...skipping 26 matching lines...) Expand all
442 interface_to_import[name] = each_import["unique_name"] + "." + name 442 interface_to_import[name] = each_import["unique_name"] + "." + name
443 return interface_to_import 443 return interface_to_import
444 444
445 def ImportedFrom(self): 445 def ImportedFrom(self):
446 interface_to_import = {} 446 interface_to_import = {}
447 for each_import in self.module.imports: 447 for each_import in self.module.imports:
448 for each_interface in each_import["module"].interfaces: 448 for each_interface in each_import["module"].interfaces:
449 name = each_interface.name 449 name = each_interface.name
450 interface_to_import[name] = each_import["unique_name"] + "." 450 interface_to_import[name] = each_import["unique_name"] + "."
451 return interface_to_import 451 return interface_to_import
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698