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

Unified Diff: mojo/public/dart/README.md

Issue 1311803002: Dart: Removes dartzip (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Readme fixes Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/dart/BUILD.gn ('k') | mojo/public/dart/rules.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/dart/README.md
diff --git a/mojo/public/dart/README.md b/mojo/public/dart/README.md
index 62526904b4d2413fe5aa6974ac129ee331272b9b..5decce33d1e0386e8df59b106016a6e2f6219048 100644
--- a/mojo/public/dart/README.md
+++ b/mojo/public/dart/README.md
@@ -8,53 +8,47 @@ Dart Mojo Applications
## Application Packaging
All Dart sources for a Mojo application are collected in a specially formatted
-zip file, which is understood by Dart's content handler in the Mojo shell.
+snapshot file, which is understood by Dart's content handler in the Mojo shell.
This section describes what the various parts of that package are, and how they
all make it to the right place.
### GN Template
-Dart Mojo applications are built with the GN template
-'dartzip_packaged_application' defined in `//mojo/public/dart/rules.gni`.
-Here is an example:
+Dart Mojo applications are built with the GN template 'dart_pkg' defined in
+`//mojo/public/dart/rules.gni`. Here is an example:
```
-dartzip_packaged_application("foo") {
- output_name = "dart_foo"
- uses_pub = true
+dart_pkg("foo") {
+ app_name_override = "dart_foo"
+ app = "lib/main.dart"
sources = [
- "main.dart",
- "foo.dart",
+ "lib/foo.dart",
+ "pubspec.yaml",
]
deps = [
+ ":foo_mojom",
"//mojo/public/dart",
- "//mojo/services/network/public/interfaces",
+ ]
+}
+
+mojom("foo_mojom") {
+ sources = [
+ "foo.mojom",
]
}
```
-There are several parts:
-* `output_name` is the name of the resulting .mojo file if it should be
- different from the name of the target. (In this case we get dart_foo.mojo
- instead of foo.mojo.)
-* `uses_pub` should be true when the application depends on Dart packages pulled
- down from pub. The application should have `pubspec.yaml` and `pubspec.lock`
- files adjacent to `main.dart`. More on this below.
-* `sources` is the list of Dart sources for the application. Each application
- **must** contain a `main.dart` file. `main.dart` must be the library entry
- point, and must contain the `main()` function.
-* `deps` has the usual meaning. In the example above,
- `//mojo/services/network/public/interfaces` indicates that the "foo"
- application uses the Dart bindings generated for the network service.
+There are several parts. See the documentation in `//mojo/public/dart/rules.gni`
+for all the details.
### pub packages
Dart Mojo applications may use packages from the pub package repository at
pub.dartlang.org.
-The "foo" example above has `uses_pub` set to true. Suppose its `pubspec.yaml`
-is as follows:
+The "foo" example above has `uses_pub` set to true. Suppose the "foo" package's
+`pubspec.yaml` is as follows:
```
name: foo
@@ -73,8 +67,8 @@ Dart packages. `pub get` also creates a `pubspec.lock` file that locks down
pub packages to specific versions. This `pubspec.lock` file must be checked in
in order to have hermetic builds.
-During the build, The `dartzip_packaged_application` rule looks for a
-"packages/" directory, and copies its contents into the zip file.
+During the build, The `dart_pkg` rule looks for a "packages/" directory, and
+ensures that its contents are available when running the application.
### Generated bindings
@@ -82,45 +76,53 @@ The script `//mojo/public/tools/bindings/generators/mojom_dart_generator.py`
and the templates under `//mojo/public/tools/bindings/generators/dart_templates`
govern how `.mojom` files are compiled into Dart code.
-Consider the `network_error.mojom` file from the network services used by our
-"foo" example:
+Consider the `foo.mojom` file used by our example:
```
-module mojo;
+[DartPackage="foo"]
+module foo;
-struct NetworkError {
+struct Foo {
int32 code;
string? description;
};
```
-This contents of this file are in the `mojo` module. The Dart source generated
-for this file will end up under, e.g.
-`//out/Debug/gen/dart-gen/mojom/mojo/network_error.mojom.dart`, along with the
-other Dart sources generated for `.mojom` files in the `mojo` module.
+This contents of this file are in the `foo` module. The Dart source generated
+for this file will end up under, e.g. `//out/Debug/gen/dart-
+pkg/foo/lib/foo/network_error.mojom.dart`, along with the other Dart sources
+generated for `.mojom` files with the "foo" `DartPackage` annotation in the
+`foo` module.
+
+### Resulting file
-### Resulting layout
+The `dart_pkg` rule has two results. The first result is a Dart snapshot file
+zipped up into a .mojo file in the build output directory---something like
+`//out/Release/foo.mojo`. This file is understood by the Dart content handler
+and is suitable for deployment. The second result is a directory layout of the
+"foo" app that can be served by a webserver. When the URL of `lib/main.dart` is
+given to the `mojo_shell`, the app will be run in the Dart content handler.
They layout for our "foo" example will be the following:
```
-//main.dart
-//foo.dart
-//crypto/... # Dart's crypto pub package.
-//mojo/public/dart/... # Mojo SDK Dart libraries.
-//mojom/mojo/... # Generated bindings in the mojo module.
+//lib/main.dart
+//lib/foo.dart
+//lib/foo/foo.mojom.dart
+//packages/crypto/... # Dart's crypto pub package.
+//packages/mojo/... # Mojo SDK Dart libraries.
```
-Where `//mojo/public/dart` contains Dart's Mojo bindings, `//crypto` contains
-the `crypto` pub package, and `//mojom/mojo` contains the generated bindings in
-the mojom module for the network service.
+Where `//packages/mojo` contains Dart's Mojo bindings, `//packages/crypto`
+contains the `crypto` pub package, and `//lib/foo/` contains the bindings
+generated for `foo.mojom`.
Mojo's Dart content handler sets the package root for a Dart application to be
-the root directory of the unpacked zip file. Therefore, Dart sources in this
-application can use the following imports:
+the packages directory. Therefore, Dart sources in this application can use the
+following imports:
```dart
import 'package:crypto/crypto.dart';
-import 'package:mojo/public/dart/application.dart';
-import 'package:mojom/mojo/network_error.mojom.dart';
+import 'package:foo/foo/foo.mojom.dart';
+import 'package:mojo/application.dart';
```
« no previous file with comments | « mojo/public/dart/BUILD.gn ('k') | mojo/public/dart/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698