| OLD | NEW |
| 1 Dart Mojo Applications | 1 Dart Mojo Applications |
| 2 ==== | 2 ==== |
| 3 | 3 |
| 4 ## Mojo Application API | 4 ## Mojo Application API |
| 5 | 5 |
| 6 *TODO(zra)* | 6 *TODO(zra)* |
| 7 | 7 |
| 8 ## Application Packaging | 8 ## Application Packaging |
| 9 | 9 |
| 10 All Dart sources for a Mojo application are collected in a specially formatted | 10 All Dart sources for a Mojo application are collected in a specially formatted |
| 11 zip file, which is understood by Dart's content handler in the Mojo shell. | 11 zip file, which is understood by Dart's content handler in the Mojo shell. |
| 12 This section describes what the various parts of that package are, and how they | 12 This section describes what the various parts of that package are, and how they |
| 13 all make it to the right place. | 13 all make it to the right place. |
| 14 | 14 |
| 15 ### GN Template | 15 ### GN Template |
| 16 | 16 |
| 17 Dart Mojo applications are built with the GN template | 17 Dart Mojo applications are built with the GN template |
| 18 'dart_packaged_application' defined in `//mojo/public/dart/rules.gni`. | 18 'dartzip_packaged_application' defined in `//mojo/public/dart/rules.gni`. |
| 19 Here is an example: | 19 Here is an example: |
| 20 | 20 |
| 21 | 21 |
| 22 ``` | 22 ``` |
| 23 dart_packaged_application("foo") { | 23 dartzip_packaged_application("foo") { |
| 24 output_name = "dart_foo" | 24 output_name = "dart_foo" |
| 25 uses_pub = true | 25 uses_pub = true |
| 26 sources = [ | 26 sources = [ |
| 27 "main.dart", | 27 "main.dart", |
| 28 "foo.dart", | 28 "foo.dart", |
| 29 ] | 29 ] |
| 30 deps = [ | 30 deps = [ |
| 31 "//mojo/public/dart", | 31 "//mojo/public/dart", |
| 32 "//mojo/services/network/public/interfaces", | 32 "//mojo/services/network/public/interfaces", |
| 33 ] | 33 ] |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 The script `//mojo/public/tools/git/dart_pub_get.py` should be run before build | 67 The script `//mojo/public/tools/git/dart_pub_get.py` should be run before build |
| 68 time, e.g. as a "runhooks" action during `gclient sync`. The script traverses | 68 time, e.g. as a "runhooks" action during `gclient sync`. The script traverses |
| 69 a directory tree looking for `pubspec.yaml` files. On finding one, in the | 69 a directory tree looking for `pubspec.yaml` files. On finding one, in the |
| 70 containing directory, it runs `pub get`. This creates a "packages/" directory | 70 containing directory, it runs `pub get`. This creates a "packages/" directory |
| 71 in the source tree adjacent to the `pubspec.yaml` file containing the downloaded | 71 in the source tree adjacent to the `pubspec.yaml` file containing the downloaded |
| 72 Dart packages. `pub get` also creates a `pubspec.lock` file that locks down | 72 Dart packages. `pub get` also creates a `pubspec.lock` file that locks down |
| 73 pub packages to specific versions. This `pubspec.lock` file must be checked in | 73 pub packages to specific versions. This `pubspec.lock` file must be checked in |
| 74 in order to have hermetic builds. | 74 in order to have hermetic builds. |
| 75 | 75 |
| 76 During the build, The `dart_packaged_application` rule looks for a "packages/" | 76 During the build, The `dartzip_packaged_application` rule looks for a |
| 77 directory, and copies its contents into the zip file. | 77 "packages/" directory, and copies its contents into the zip file. |
| 78 | 78 |
| 79 ### Generated bindings | 79 ### Generated bindings |
| 80 | 80 |
| 81 The script `//mojo/public/tools/bindings/generators/mojom_dart_generator.py` | 81 The script `//mojo/public/tools/bindings/generators/mojom_dart_generator.py` |
| 82 and the templates under `//mojo/public/tools/bindings/generators/dart_templates` | 82 and the templates under `//mojo/public/tools/bindings/generators/dart_templates` |
| 83 govern how `.mojom` files are compiled into Dart code. | 83 govern how `.mojom` files are compiled into Dart code. |
| 84 | 84 |
| 85 Consider the `network_error.mojom` file from the network services used by our | 85 Consider the `network_error.mojom` file from the network services used by our |
| 86 "foo" example: | 86 "foo" example: |
| 87 | 87 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 117 | 117 |
| 118 Mojo's Dart content handler sets the package root for a Dart application to be | 118 Mojo's Dart content handler sets the package root for a Dart application to be |
| 119 the root directory of the unpacked zip file. Therefore, Dart sources in this | 119 the root directory of the unpacked zip file. Therefore, Dart sources in this |
| 120 application can use the following imports: | 120 application can use the following imports: |
| 121 | 121 |
| 122 ```dart | 122 ```dart |
| 123 import 'package:crypto/crypto.dart'; | 123 import 'package:crypto/crypto.dart'; |
| 124 import 'package:mojo/public/dart/application.dart'; | 124 import 'package:mojo/public/dart/application.dart'; |
| 125 import 'package:mojom/mojo/network_error.mojom.dart'; | 125 import 'package:mojom/mojo/network_error.mojom.dart'; |
| 126 ``` | 126 ``` |
| OLD | NEW |