blob: 46192e6bc2d5ed032620c97d4623c53ad283131b [file] [log] [blame] [view]
James Robinsonfca33c52014-10-01 13:06:09 -07001Mojo
2====
James Robinson5562f1d2014-10-14 15:03:43 -07003
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +02004Mojo is an effort to extract a common platform out of Chrome's renderer and
5plugin processes that can support multiple types of sandboxed content, such as
6HTML, Pepper, or NaCl.
James Robinson5562f1d2014-10-14 15:03:43 -07007
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +02008## Set-up and code check-out
James Robinson5562f1d2014-10-14 15:03:43 -07009
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +020010The instructions below only need to be done once. Note that a simple "git clone"
11command is not sufficient to build the source code because this repo uses the
12gclient command from depot_tools to manage most third party dependencies.
Jim Beveridgea98e4352014-11-14 10:21:29 -080013
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200141. [Download
15 depot_tools](http://www.chromium.org/developers/how-tos/install-depot-tools)
16 and make sure it is in your path.
Jim Beveridge804f6c02014-11-24 15:58:08 -0800172. [Googlers only] Install Goma in ~/goma.
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200183. Create a directory somewhere for your checkout (preferably on an SSD), cd
19 into it, and run the following commands:
Jim Beveridgea98e4352014-11-14 10:21:29 -080020
James Robinson5562f1d2014-10-14 15:03:43 -070021
22```
Jim Beveridge804f6c02014-11-24 15:58:08 -080023$ fetch mojo # append --target_os=android to include Android build support.
Dirk Prankea54f8842014-10-22 10:56:31 -070024$ cd src
aboodman51c5df52015-02-24 12:40:41 -080025
aboodman68d79572015-02-24 12:40:20 -080026# Or install-build-deps-android.sh if you plan to build for Android.
Matt Perry0060e382014-10-21 16:34:57 -040027$ ./build/install-build-deps.sh
aboodman51c5df52015-02-24 12:40:41 -080028
Jim Beveridge804f6c02014-11-24 15:58:08 -080029$ mojo/tools/mojob.py gn
James Robinsonfb7fc8c2014-10-14 15:04:21 -070030```
John Abd-El-Malekb315f492014-10-23 14:31:58 -070031
Tony Gentilcore42b06a02015-07-27 15:04:28 -070032The `fetch mojo` command does the following:
Jim Beveridgea98e4352014-11-14 10:21:29 -080033- creates a directory called 'src' under your checkout directory
34- clones the repository using git clone
35- clones dependencies with gclient sync
36
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +020037`install-build-deps.sh` installs any packages needed to build, then
38`mojo/tools/mojob.py gn` runs `gn args` and configures the build directory,
39out/Debug.
Jim Beveridgea98e4352014-11-14 10:21:29 -080040
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +020041If the fetch command fails, you will need to delete the src directory and start
42over.
Jim Beveridgea98e4352014-11-14 10:21:29 -080043
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +020044### <a name="configure-android"></a>Adding Android bits in an existing checkout
45
46If you configured your set-up for Linux and now wish to build for Android, edit
47the `.gclient` file in your root Mojo directory (the parent directory to src.)
48and add this line at the end of the file:
49
50```
51target_os = [u'android',u'linux']
52```
53
54Bring in Android-specific build dependencies:
55```
56$ build/install-build-deps-android.sh
57```
58
59Pull down all of the packages with this command:
60```
61$ gclient sync
62```
63
Przemyslaw Pietrzkiewicz52764c42015-11-02 15:27:06 +010064## Update your checkout
65
66You can update your checkout like this. The order is important. You must do the
67`git pull` first because `gclient sync` is dependent on the current revision.
68
69```
70# Fetch changes from upstream and rebase the current branch on top
71$ git pull --rebase
72# Update all modules as directed by the DEPS file
73$ gclient sync
74```
75
76You do not need to rerun `gn gen out/Debug` - ninja does so automatically each
77time you build. You might need to rerun `mojo/tools/mojob.py gn` if the GN
78flags have changed.
79
Jim Beveridge0ac4ba42015-02-18 14:55:51 -080080## <a name="buildmojo"></a>Build Mojo
Jim Beveridgea98e4352014-11-14 10:21:29 -080081
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +020082### Linux
83
Jim Beveridge0ac4ba42015-02-18 14:55:51 -080084Build Mojo for Linux by running:
Jim Beveridgea98e4352014-11-14 10:21:29 -080085
John Abd-El-Malekb315f492014-10-23 14:31:58 -070086```
Nick Braye5ac3422014-12-16 13:27:24 -080087$ ninja -C out/Debug -j 10
John Abd-El-Malekb315f492014-10-23 14:31:58 -070088```
89
Przemyslaw Pietrzkiewicz628d9072015-06-09 18:33:52 +020090You can also use the `mojob.py` script for building. This script automatically
91calls ninja and sets -j to an appropriate value based on whether Goma (see the
92section on Goma below) is present. You cannot specify a target name with this
93script.
John Abd-El-Malekb315f492014-10-23 14:31:58 -070094
Jim Beveridgea98e4352014-11-14 10:21:29 -080095```
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +020096mojo/tools/mojob.py gn
Jim Beveridgea98e4352014-11-14 10:21:29 -080097mojo/tools/mojob.py build
98```
John Abd-El-Malekb315f492014-10-23 14:31:58 -070099
aboodmand53c2692014-10-29 21:46:27 -0700100Run a demo:
101```
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +0200102out/Debug/mojo_shell mojo:spinning_cube
aboodmand53c2692014-10-29 21:46:27 -0700103```
104
John Abd-El-Malekb315f492014-10-23 14:31:58 -0700105Run the tests:
106```
John Abd-El-Malek6d1ef8a2014-11-10 12:04:25 -0800107mojo/tools/mojob.py test
Scott Violet57244942014-10-27 13:55:48 -0700108```
109
Jim Beveridge0ac4ba42015-02-18 14:55:51 -0800110Create a release build:
111```
112mojo/tools/mojob.py gn --release
113mojo/tools/mojob.py build --release
114mojo/tools/mojob.py test --release
115```
116
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +0200117### Android
Scott Violet57244942014-10-27 13:55:48 -0700118
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +0200119To build for Android, first make sure that your checkout is [configured](#configure-android) to build
120for Android. After that you can use the mojob script as follows:
Przemyslaw Pietrzkiewicz87efd5f2015-06-08 18:00:43 +0200121```
122$ mojo/tools/mojob.py gn --android
123$ mojo/tools/mojob.py build --android
124```
125
126The result will be in out/android_Debug. If you see javac compile errors,
127[make sure you have an up-to-date JDK](https://code.google.com/p/chromium/wiki/AndroidBuildInstructions#Install_Java_JDK)
128
Przemyslaw Pietrzkiewicz628d9072015-06-09 18:33:52 +0200129### Goma (Googlers only)
130
131If you're a Googler, you can use Goma, a distributed compiler service for
132open-source projects such as Chrome and Android. If Goma is installed in the
133default location (~/goma), it will work out-of-the-box with the `mojob.py gn`,
134`mojob.py build` workflow described above.
135
136You can also manually add:
137```
138use_goma = true
139```
140
141at the end of the file opened through:
142```
143$ gn args out/Debug
144```
145
146After you close the editor `gn gen out/Debug` will run automatically. Now you
147can dramatically increase the number of parallel tasks:
148```
149$ ninja -C out/Debug -j 1000
150```
151
Etienne Membrives79888662015-06-17 13:00:21 +0200152### Official builds
153
154Official builds for android generate a signed Mojo Shell intended for
155distribution. You normally should not need to produce one. If you have any
156questions, reach out to [etiennej@chromium.org](mailto:etiennej@chromium.org).
157
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800158## Run Mojo Shell
159
Przemyslaw Pietrzkiewicz11e4fcd2015-07-31 14:00:44 +0200160Devtools `mojo_run` is a universal shell runner abstracting away the differences
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200161between running on Linux and Android.
162
163Having built Mojo as described above, a demo app can be run as follows:
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800164
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200165```
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200166mojo/devtools/common/mojo_run https://core.mojoapps.io/spinning_cube.mojo # Linux
167mojo/devtools/common/mojo_run https://core.mojoapps.io/spinning_cube.mojo --android # Android
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200168```
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200169
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200170### Development server
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200171
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200172Whenever `mojo_run` is run, a development server is set up according to [the
173config file](mojoconfig). The server runs on your machine, serving the locally
174built apps, but appears to the shell under the `https://core.mojoapps.io` host.
175
176You can ignore the config file and skip spawning the local server (for example,
177in order to use apps at the actual https://core.mojoapps.io web host) by passing
178`--no-config-file` to `mojo_run`.
179
180### More examples
181
182Some applications can be run directly from the source tree. The development
183server serves the `src` directory, allowing to refer to these apps. For
184instance, this command serves a dart Mojo app from the source at
185`examples/dart/device_info/main.dart`:
186
187```sh
Przemyslaw Pietrzkiewiczcd345352015-09-17 17:20:46 +0200188mojo/devtools/common/mojo_run https://core.mojoapps.io/examples/dart/device_info/lib/main.dart [--android]
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200189```
190
191Some applications are meant to be run embedded in a **window manager**. To run
Przemyslaw Pietrzkiewicz4f1253d2015-08-10 14:32:28 +0200192these, you can pass the app url using the `--embed` flag. This will run the
193window manager and pass the given url to it:
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200194
195```sh
Przemyslaw Pietrzkiewiczcd345352015-09-17 17:20:46 +0200196mojo/devtools/common/mojo_run --embed https://core.mojoapps.io/ganesh_app.mojo [--android]
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200197```
198
Przemyslaw Pietrzkiewiczcd345352015-09-17 17:20:46 +0200199By default, `mojo_run` uses mojo:kiosk_wm as the window
Przemyslaw Pietrzkiewicz4f1253d2015-08-10 14:32:28 +0200200manager. You can pass a different window manager url using the
201`--window-manager` flag to override this.
202
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200203For additional information on `mojo_run` refer to the built-in help and the
Przemyslaw Pietrzkiewiczcd345352015-09-17 17:20:46 +0200204[documentation](mojo/devtools/common/docs/mojo_run.md).
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200205You can also request more information on what the tool is doing for you by
206passing the `--verbose` flag.
Przemyslaw Pietrzkiewicz07b257f2015-06-15 17:29:26 +0200207
Przemyslaw Pietrzkiewicz8fc79b02015-06-10 17:44:55 +0200208### <a name="debugging"></a>Debugging, tracing, profiling
209
Przemyslaw Pietrzkiewicz11e4fcd2015-07-31 14:00:44 +0200210Devtools `mojo_debug` allows you to interactively inspect a running shell,
211collect performance traces and attach a gdb debugger.
212
213For additional information refer to the built-in help and the
Przemyslaw Pietrzkiewiczcd345352015-09-17 17:20:46 +0200214[documentation](mojo/devtools/common/docs/mojo_debug.md).
Etienne Membrives72098cf2015-07-16 13:07:11 +0200215
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200216### Android set-up
217
218#### Adb
219
220For the Android tooling to work, you will need to have `adb` in your PATH. For
221that, you can either run:
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200222```
223source build/android/envsetup.sh
224```
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800225
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200226each time you open a fresh terminal, or add something like:
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200227```
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200228export PATH="$PATH":$MOJO_DIR/src/third_party/android_tools/sdk/platform-tools
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200229```
230
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200231to your ~/.bashrc file, $MOJO_DIR being a path to your Mojo checkout.
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200232
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200233#### Device
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200234
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200235**The device has to be running Android 5.0 (Lollipop) or newer.**
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800236
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200237Many features useful for development (ie. streaming of the shell stdout when
238running shell on the device) will not work unless the device is rooted and
239running a userdebug build. For Googlers, [follow the instructions at this
240link](http://go/mojo-internal-build-instructions).
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200241
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200242### Running manually on Linux
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800243
Przemyslaw Pietrzkiewicz31bb9092015-06-09 20:34:31 +0200244If you wish to, you can also run the Linux Mojo shell directly with no wrappers:
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200245```
Przemyslaw Pietrzkiewiczf54ced52015-08-07 13:33:39 +0200246./out/Debug/mojo_shell out/Debug/spinning_cube.mojo
Przemyslaw Pietrzkiewicz7510eb82015-06-05 14:40:57 +0200247```
Przemyslaw Pietrzkiewiczed913682015-08-10 15:37:14 +0200248
249## Contribute
250
251With git you should make all your changes in a local branch. Once your change is
252committed, you can delete this branch.
253
254Create a local branch named "mywork" and make changes to it.
255```
256 cd src
257 git new-branch mywork
258 vi ...
259```
260Commit your change locally. (this doesn't commit your change to the SVN or Git
261server)
262
263```
264 git commit -a
265```
266
267Fix your source code formatting.
268
269```
270$ git cl format
271```
272
273Upload your change for review.
274
275```
276$ git cl upload
277```
278
279Respond to review comments.
280
281See [Contributing code](http://www.chromium.org/developers/contributing-code)
282for more detailed git instructions, including how to update your CL when you get
283review comments. There's a short tutorial that might be helpful to try before
284making your first change: [C++ in Chromium
285101](http://dev.chromium.org/developers/cpp-in-chromium-101-codelab).
286
287To land a change after receiving LGTM:
288```
289$ git cl land
290```
291
292Don't break the build! Waterfall is here:
293http://build.chromium.org/p/client.mojo/waterfall