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

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

Issue 1945103002: Go bindings: Don't import 'fmt' unless it is needed. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « mojo/go/tests/test_enums.mojom ('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 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 Go source files from a mojom.Module.''' 5 '''Generates Go source files from a mojom.Module.'''
6 6
7 from itertools import chain 7 from itertools import chain
8 import os 8 import os
9 import re 9 import re
10 10
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 # Imported kinds can only be referred to in structs, constants, enums, 363 # Imported kinds can only be referred to in structs, constants, enums,
364 # unions and interfaces. 364 # unions and interfaces.
365 all_structs = list(self.module.structs) 365 all_structs = list(self.module.structs)
366 for i in self.module.interfaces: 366 for i in self.module.interfaces:
367 for method in i.methods: 367 for method in i.methods:
368 all_structs.append(self._GetStructFromMethod(method)) 368 all_structs.append(self._GetStructFromMethod(method))
369 if method.response_parameters: 369 if method.response_parameters:
370 all_structs.append(self._GetResponseStructFromMethod(method)) 370 all_structs.append(self._GetResponseStructFromMethod(method))
371 371
372 if (len(all_structs) > 0 or len(self.module.interfaces) > 0 372 if (len(all_structs) > 0 or len(self.module.interfaces) > 0
373 or len(self.module.unions) > 0 or len(self.module.enums) > 0): 373 or len(self.module.unions) > 0):
374 imports['fmt'] = 'fmt' 374 imports['fmt'] = 'fmt'
375 imports['mojo/public/go/bindings'] = 'bindings' 375 imports['mojo/public/go/bindings'] = 'bindings'
376 if len(self.module.interfaces) > 0: 376 if len(self.module.interfaces) > 0:
377 imports['mojo/public/go/system'] = 'system' 377 imports['mojo/public/go/system'] = 'system'
378 if len(all_structs) > 0: 378 if len(all_structs) > 0:
379 imports['sort'] = 'sort' 379 imports['sort'] = 'sort'
380 380
381 for union in self.module.unions: 381 for union in self.module.unions:
382 for field in union.fields: 382 for field in union.fields:
383 AddImport(imports, mojom_imports, self.module, field.kind) 383 AddImport(imports, mojom_imports, self.module, field.kind)
(...skipping 12 matching lines...) Expand all
396 396
397 # Mojom Type generation requires additional imports. 397 # Mojom Type generation requires additional imports.
398 defInterface = len(self.module.interfaces) > 0 398 defInterface = len(self.module.interfaces) > 0
399 defOtherType = len(self.module.unions) + len(all_structs) + \ 399 defOtherType = len(self.module.unions) + len(all_structs) + \
400 len(GetAllEnums(self.module)) > 0 400 len(GetAllEnums(self.module)) > 0
401 401
402 if self.should_gen_mojom_types: 402 if self.should_gen_mojom_types:
403 imports['bytes'] = 'bytes' 403 imports['bytes'] = 'bytes'
404 imports['compress/gzip'] = 'gzip' 404 imports['compress/gzip'] = 'gzip'
405 imports['encoding/base64'] = 'base64' 405 imports['encoding/base64'] = 'base64'
406 imports['fmt'] = 'fmt'
406 imports['io/ioutil'] = 'ioutil' 407 imports['io/ioutil'] = 'ioutil'
408 imports['mojo/public/go/bindings'] = 'bindings'
407 409
408 if GetPackageName(self.module) != _mojom_types_pkg_short: 410 if GetPackageName(self.module) != _mojom_types_pkg_short:
409 if defInterface: 411 if defInterface:
410 # Each Interface has a service description that uses this. 412 # Each Interface has a service description that uses this.
411 imports[_mojom_types_pkg] = _mojom_types_pkg_short 413 imports[_mojom_types_pkg] = _mojom_types_pkg_short
412 if defOtherType and self.should_gen_mojom_types: 414 if defOtherType and self.should_gen_mojom_types:
413 # This import is needed only if generating mojom type definitions. 415 # This import is needed only if generating mojom type definitions.
414 imports[_mojom_types_pkg] = _mojom_types_pkg_short 416 imports[_mojom_types_pkg] = _mojom_types_pkg_short
415 417
416 if GetPackageName(self.module) != _service_describer_pkg_short and \ 418 if GetPackageName(self.module) != _service_describer_pkg_short and \
(...skipping 27 matching lines...) Expand all
444 # modify the |name| property. Instead we add a |go_name| property. 446 # modify the |name| property. Instead we add a |go_name| property.
445 def _GetResponseStructFromMethod(self, method): 447 def _GetResponseStructFromMethod(self, method):
446 self._AddStructComputedData(False, method.response_param_struct) 448 self._AddStructComputedData(False, method.response_param_struct)
447 if not hasattr(method.response_param_struct, "go_name"): 449 if not hasattr(method.response_param_struct, "go_name"):
448 # Only generate the go_names if they have not already been generated. 450 # Only generate the go_names if they have not already been generated.
449 method.response_param_struct.go_name = "%s_%s_ResponseParams" % ( 451 method.response_param_struct.go_name = "%s_%s_ResponseParams" % (
450 GetNameForElement(method.interface), GetNameForElement(method)) 452 GetNameForElement(method.interface), GetNameForElement(method))
451 for field in method.response_param_struct.fields: 453 for field in method.response_param_struct.fields:
452 field.go_name = "out%s" % GetNameForElement(field) 454 field.go_name = "out%s" % GetNameForElement(field)
453 return method.response_param_struct 455 return method.response_param_struct
OLDNEW
« no previous file with comments | « mojo/go/tests/test_enums.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698