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

Issue 1345263002: Generate Mojom Types in Go (Closed)

Created:
5 years, 3 months ago by alexfandrianto
Modified:
5 years, 2 months ago
Reviewers:
mattr, rudominer, azani
CC:
mojo-reviews_chromium.org, gregsimon, qsr+mojo_chromium.org, viettrungluu+watch_chromium.org, yzshen+watch_chromium.org, abarth-chromium, Aaron Boodman, darin (slow to review), ben+mojo_chromium.org
Base URL:
https://github.com/domokit/mojo.git@master
Target Ref:
refs/heads/master
Project:
mojo
Visibility:
Public.

Description

This CL generates mojom type descriptions for every Go .mojom file. * Each Struct/Union/Enum/Interface will have a corresponding Mojom Type and Type Identifier. * Each generated file will now expose a global Descriptor() function. This allows .mojom files to know about all the types relevant to their package. It is a map[string]UserDefinedType. * Each Mojom Interface's ServiceRequest will now also expose Type() and Desc() on the "client-side", so that clients can know all the type metadata that they like about the service they are accessing. * Each Mojom Interface also generates a ServiceDescription (service_describers.mojom) implementation. This allows Mojo server applications to additionally expose a ServiceDescriber implementation that directs interface name queries to the corresponding ServiceDescription. Notes: * The CL does not generate types for constants. The Go generator does not generate constants yet, anyway. * A best attempt was made to preserve ordinals, but descriptions and such are not included because the Python generator doesn't have those available. The generation occurs as follows. mojom_util_macros.tmpl: - A helper that sets up the unique identifier for each mojom type. This is essentially {package}_{typeName}__ This is used by the other jinja templates to attain consistent variable and type key naming. source.tmpl and mojom_reference_macros.tmpl: - The String Identifiers are used (by reference), so they are best initialized early on in the file. Some are exposed publicly (since other files may need them). - Creates the init function where the mapping/descriptor is built. It traverses each of the types defined by the user and registers those into the map. If types are referenced from external files, these are found by copying the mappings from the relevant mojom imports. I think this is good since it saves a lot of runtime logic, and the cost (larger maps during init) seems small. - Writes the Descriptor() method to reveal the mapping. mojom_type_macros.tmpl and struct/union/enum.tmpl: - All of these call writeMojomType, which traverses the type and prints out the corresponding MojomStruct. - If there is a reference to an interface or a non-top-level struct/union/enum, then a mojom_types.TypeTypeReference is used instead. As the spec describes, this removes the possibility of generating a recursive value. - The mojom_types.TypeTypeReference will use both Identifier and TypeKey as the reference to the String Identifiers variables created earlier. interface.tmpl: - This generates the parameter (and possibly response) structs for each method. - It also generates a mojom_types.MojomInterface that wraps up each MojomMethod. - Lastly, it generates the ServiceDescription and Type() and Desc() methods for the ServiceRequest. go/application/connection.go was also updated; the ServiceRequest now also has the Type() and Desc() methods on the interface. Question: - This CL allows writing a universal mojo client and a mojo proxy application. Should I write one or the other for Go? (Note that in a branch of mattr-google, this implementation is sufficient and was tested there.) R=rudominer@chromium.org Committed: https://chromium.googlesource.com/external/mojo/+/b30d89292737f11cf1b33e476212e8158c5e5d33

Patch Set 1 #

Total comments: 10

Patch Set 2 : Add Client and Server Hooks to the Type Description #

Patch Set 3 : Replace Signature call with ServiceDescriptions #

Patch Set 4 : Use unexported functions instead of variables #

Total comments: 17

Patch Set 5 : Templates Updated, Service Describer Implemented, Tests Added #

Total comments: 13

Patch Set 6 : Minor refactors for clarity #

Patch Set 7 : GetIdentifier without a default #

Total comments: 6

Patch Set 8 : Update Comments and Enum Template+Tests #

Total comments: 4

Patch Set 9 : Wrap long lines #

Patch Set 10 : Add a toggle that can turn off mojom type generation #

Total comments: 16

Patch Set 11 : Address Naming changes and Comment Updates #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1148 lines, -20 lines) Patch
M mojo/go/BUILD.gn View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
A mojo/go/tests/validation_type_test.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +454 lines, -0 lines 0 comments Download
M mojo/public/go/application/connection.go View 1 2 3 4 5 6 7 8 9 10 7 chunks +49 lines, -1 line 0 comments Download
A mojo/public/go/application/describer.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +103 lines, -0 lines 0 comments Download
M mojo/public/tools/bindings/generators/go_templates/enum.tmpl View 1 2 3 4 2 chunks +5 lines, -1 line 0 comments Download
M mojo/public/tools/bindings/generators/go_templates/interface.tmpl View 1 2 3 4 5 6 7 8 9 10 5 chunks +53 lines, -3 lines 0 comments Download
A mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl View 1 2 3 4 5 6 1 chunk +51 lines, -0 lines 0 comments Download
A mojo/public/tools/bindings/generators/go_templates/mojom_type_macros.tmpl View 1 2 3 4 5 6 7 8 9 1 chunk +231 lines, -0 lines 0 comments Download
M mojo/public/tools/bindings/generators/go_templates/source.tmpl View 1 2 3 4 5 6 7 8 9 10 1 chunk +62 lines, -5 lines 0 comments Download
M mojo/public/tools/bindings/generators/go_templates/struct.tmpl View 1 2 3 4 2 chunks +4 lines, -1 line 0 comments Download
M mojo/public/tools/bindings/generators/go_templates/union.tmpl View 1 2 3 4 2 chunks +4 lines, -2 lines 0 comments Download
M mojo/public/tools/bindings/generators/mojom_go_generator.py View 1 2 3 4 5 6 7 8 9 9 chunks +131 lines, -7 lines 0 comments Download

Messages

Total messages: 31 (3 generated)
mattr
Only had time to scan through a make a few comments. I'll take a longer ...
5 years, 3 months ago (2015-09-17 00:37:35 UTC) #2
alexfandrianto
I thought I'd mailed these comments earlier, but here they are now. https://codereview.chromium.org/1345263002/diff/1/mojo/public/tools/bindings/generators/go_templates/struct.tmpl File mojo/public/tools/bindings/generators/go_templates/struct.tmpl ...
5 years, 2 months ago (2015-10-09 17:43:55 UTC) #3
rudominer
I added azani@ as a reviewer because I think he will be able to help ...
5 years, 2 months ago (2015-10-12 19:39:28 UTC) #6
azani
I have 2 high level comments: 1) Instead of defining those functions directly in the ...
5 years, 2 months ago (2015-10-12 21:13:08 UTC) #7
alexfandrianto
Thanks, I will work on this tomorrow. I don't think any changes will be overly ...
5 years, 2 months ago (2015-10-13 03:00:11 UTC) #8
rudominer
https://codereview.chromium.org/1345263002/diff/60001/mojo/public/go/application/connection.go File mojo/public/go/application/connection.go (right): https://codereview.chromium.org/1345263002/diff/60001/mojo/public/go/application/connection.go#newcode34 mojo/public/go/application/connection.go:34: type ServiceRequest interface { This does not seem right ...
5 years, 2 months ago (2015-10-14 05:15:41 UTC) #9
rudominer
https://codereview.chromium.org/1345263002/diff/60001/mojo/public/go/application/connection.go File mojo/public/go/application/connection.go (right): https://codereview.chromium.org/1345263002/diff/60001/mojo/public/go/application/connection.go#newcode34 mojo/public/go/application/connection.go:34: type ServiceRequest interface { On 2015/10/14 05:15:41, rudominer wrote: ...
5 years, 2 months ago (2015-10-14 06:17:55 UTC) #10
alexfandrianto
https://codereview.chromium.org/1345263002/diff/60001/mojo/public/go/application/connection.go File mojo/public/go/application/connection.go (right): https://codereview.chromium.org/1345263002/diff/60001/mojo/public/go/application/connection.go#newcode34 mojo/public/go/application/connection.go:34: type ServiceRequest interface { On 2015/10/14 06:17:55, rudominer wrote: ...
5 years, 2 months ago (2015-10-14 06:44:50 UTC) #11
alexfandrianto
I added tests in mojo/go/tests/validation_type_test.go and implemented a service_describer in mojo/public/go/application/describer.go https://codereview.chromium.org/1345263002/diff/60001/mojo/public/tools/bindings/generators/go_templates/enum.tmpl File mojo/public/tools/bindings/generators/go_templates/enum.tmpl (right): ...
5 years, 2 months ago (2015-10-16 21:25:50 UTC) #12
rudominer
Hi Alex, I think that mojom_types.mojom changed out from under you and you need to ...
5 years, 2 months ago (2015-10-19 18:01:27 UTC) #13
alexfandrianto
On 2015/10/19 18:01:27, rudominer wrote: > Hi Alex, > > I think that mojom_types.mojom changed ...
5 years, 2 months ago (2015-10-19 18:15:33 UTC) #14
azani
https://codereview.chromium.org/1345263002/diff/60001/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl File mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl (right): https://codereview.chromium.org/1345263002/diff/60001/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl#newcode7 mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl:7: {%- macro registerType(mapping, typepkg, pkg, t) -%} On 2015/10/16 ...
5 years, 2 months ago (2015-10-19 18:27:02 UTC) #15
alexfandrianto
Thanks, PTAL https://codereview.chromium.org/1345263002/diff/60001/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl File mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl (right): https://codereview.chromium.org/1345263002/diff/60001/mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl#newcode7 mojo/public/tools/bindings/generators/go_templates/mojom_reference_macros.tmpl:7: {%- macro registerType(mapping, typepkg, pkg, t) -%} ...
5 years, 2 months ago (2015-10-19 21:36:30 UTC) #16
azani
https://codereview.chromium.org/1345263002/diff/80001/mojo/public/tools/bindings/generators/mojom_go_generator.py File mojo/public/tools/bindings/generators/mojom_go_generator.py (right): https://codereview.chromium.org/1345263002/diff/80001/mojo/public/tools/bindings/generators/mojom_go_generator.py#newcode325 mojo/public/tools/bindings/generators/mojom_go_generator.py:325: package = GetPackageNameForElement(kind, default) On 2015/10/19 21:36:30, alexfandrianto wrote: ...
5 years, 2 months ago (2015-10-19 21:43:07 UTC) #17
alexfandrianto
On 2015/10/19 21:43:07, azani wrote: > https://codereview.chromium.org/1345263002/diff/80001/mojo/public/tools/bindings/generators/mojom_go_generator.py > File mojo/public/tools/bindings/generators/mojom_go_generator.py (right): > > https://codereview.chromium.org/1345263002/diff/80001/mojo/public/tools/bindings/generators/mojom_go_generator.py#newcode325 > ...
5 years, 2 months ago (2015-10-19 22:03:19 UTC) #18
azani
On 2015/10/19 22:03:19, alexfandrianto wrote: > On 2015/10/19 21:43:07, azani wrote: > > > https://codereview.chromium.org/1345263002/diff/80001/mojo/public/tools/bindings/generators/mojom_go_generator.py ...
5 years, 2 months ago (2015-10-19 22:13:51 UTC) #19
alexfandrianto
On 2015/10/19 22:13:51, azani wrote: > On 2015/10/19 22:03:19, alexfandrianto wrote: > > On 2015/10/19 ...
5 years, 2 months ago (2015-10-19 22:54:36 UTC) #20
azani
On 2015/10/19 22:54:36, alexfandrianto wrote: > On 2015/10/19 22:13:51, azani wrote: > > On 2015/10/19 ...
5 years, 2 months ago (2015-10-20 20:41:04 UTC) #21
rudominer
Just a few minor comments after my first pass. I'll take another pass after your ...
5 years, 2 months ago (2015-10-20 21:14:06 UTC) #22
alexfandrianto
It also looks like https://codereview.chromium.org/1417473002/ was submitted. So I have also made changes to my ...
5 years, 2 months ago (2015-10-20 23:08:03 UTC) #23
azani
just a few nits https://codereview.chromium.org/1345263002/diff/140001/mojo/public/tools/bindings/generators/mojom_go_generator.py File mojo/public/tools/bindings/generators/mojom_go_generator.py (right): https://codereview.chromium.org/1345263002/diff/140001/mojo/public/tools/bindings/generators/mojom_go_generator.py#newcode225 mojo/public/tools/bindings/generators/mojom_go_generator.py:225: return '%sTypeHandleType{%sHandleType{Nullable: %s, Kind: %sHandleType_Kind_%s}}' ...
5 years, 2 months ago (2015-10-20 23:35:46 UTC) #24
alexfandrianto
This fixes the long lines nit. https://codereview.chromium.org/1345263002/diff/140001/mojo/public/tools/bindings/generators/mojom_go_generator.py File mojo/public/tools/bindings/generators/mojom_go_generator.py (right): https://codereview.chromium.org/1345263002/diff/140001/mojo/public/tools/bindings/generators/mojom_go_generator.py#newcode225 mojo/public/tools/bindings/generators/mojom_go_generator.py:225: return '%sTypeHandleType{%sHandleType{Nullable: %s, ...
5 years, 2 months ago (2015-10-21 00:12:46 UTC) #25
alexfandrianto
I also added the toggle for whether to generate types or not. This toggle is ...
5 years, 2 months ago (2015-10-22 00:27:01 UTC) #26
rudominer
Hey Alex, This is looking very nice. Thanks for your good work here. Just a ...
5 years, 2 months ago (2015-10-22 21:28:48 UTC) #27
alexfandrianto
Thanks, Mitch. Here's the updated CL. https://codereview.chromium.org/1345263002/diff/180001/mojo/public/go/application/connection.go File mojo/public/go/application/connection.go (right): https://codereview.chromium.org/1345263002/diff/180001/mojo/public/go/application/connection.go#newcode39 mojo/public/go/application/connection.go:39: // examine the ...
5 years, 2 months ago (2015-10-22 22:58:11 UTC) #28
rudominer
lgtm
5 years, 2 months ago (2015-10-22 23:10:47 UTC) #29
alexfandrianto
On 2015/10/22 23:10:47, rudominer wrote: > lgtm I don't use Chromium normally, so I didn't ...
5 years, 2 months ago (2015-10-22 23:15:10 UTC) #30
alexfandrianto
5 years, 2 months ago (2015-10-23 20:35:55 UTC) #31
Message was sent while issue was closed.
Committed patchset #11 (id:200001) manually as
b30d89292737f11cf1b33e476212e8158c5e5d33 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698