James Robinson | fca33c5 | 2014-10-01 13:06:09 -0700 | [diff] [blame] | 1 | Mojo |
| 2 | ==== |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 3 | |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 4 | Mojo is an effort to extract a common platform out of Chrome's renderer and |
| 5 | plugin processes that can support multiple types of sandboxed content, such as |
| 6 | HTML, Pepper, or NaCl. |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 7 | |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 8 | ## Set-up and code check-out |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 9 | |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 10 | The instructions below only need to be done once. Note that a simple "git clone" |
| 11 | command is not sufficient to build the source code because this repo uses the |
| 12 | gclient command from depot_tools to manage most third party dependencies. |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 13 | |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 14 | 1. [Download |
| 15 | depot_tools](http://www.chromium.org/developers/how-tos/install-depot-tools) |
| 16 | and make sure it is in your path. |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 17 | 2. [Googlers only] Install Goma in ~/goma. |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 18 | 3. Create a directory somewhere for your checkout (preferably on an SSD), cd |
| 19 | into it, and run the following commands: |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 20 | |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 21 | |
| 22 | ``` |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 23 | $ fetch mojo # append --target_os=android to include Android build support. |
Dirk Pranke | a54f884 | 2014-10-22 10:56:31 -0700 | [diff] [blame] | 24 | $ cd src |
aboodman | 51c5df5 | 2015-02-24 12:40:41 -0800 | [diff] [blame] | 25 | |
aboodman | 68d7957 | 2015-02-24 12:40:20 -0800 | [diff] [blame] | 26 | # Or install-build-deps-android.sh if you plan to build for Android. |
Matt Perry | 0060e38 | 2014-10-21 16:34:57 -0400 | [diff] [blame] | 27 | $ ./build/install-build-deps.sh |
aboodman | 51c5df5 | 2015-02-24 12:40:41 -0800 | [diff] [blame] | 28 | |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 29 | $ mojo/tools/mojob.py gn |
James Robinson | fb7fc8c | 2014-10-14 15:04:21 -0700 | [diff] [blame] | 30 | ``` |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 31 | |
Tony Gentilcore | 42b06a0 | 2015-07-27 15:04:28 -0700 | [diff] [blame] | 32 | The `fetch mojo` command does the following: |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 33 | - creates a directory called 'src' under your checkout directory |
| 34 | - clones the repository using git clone |
| 35 | - clones dependencies with gclient sync |
| 36 | |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 37 | `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, |
| 39 | out/Debug. |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 40 | |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 41 | If the fetch command fails, you will need to delete the src directory and start |
| 42 | over. |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 43 | |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 44 | ### <a name="configure-android"></a>Adding Android bits in an existing checkout |
| 45 | |
| 46 | If you configured your set-up for Linux and now wish to build for Android, edit |
| 47 | the `.gclient` file in your root Mojo directory (the parent directory to src.) |
| 48 | and add this line at the end of the file: |
| 49 | |
| 50 | ``` |
| 51 | target_os = [u'android',u'linux'] |
| 52 | ``` |
| 53 | |
| 54 | Bring in Android-specific build dependencies: |
| 55 | ``` |
| 56 | $ build/install-build-deps-android.sh |
| 57 | ``` |
| 58 | |
| 59 | Pull down all of the packages with this command: |
| 60 | ``` |
| 61 | $ gclient sync |
| 62 | ``` |
| 63 | |
Przemyslaw Pietrzkiewicz | 52764c4 | 2015-11-02 15:27:06 +0100 | [diff] [blame] | 64 | ## Update your checkout |
| 65 | |
| 66 | You 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 | |
| 76 | You do not need to rerun `gn gen out/Debug` - ninja does so automatically each |
| 77 | time you build. You might need to rerun `mojo/tools/mojob.py gn` if the GN |
| 78 | flags have changed. |
| 79 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 80 | ## <a name="buildmojo"></a>Build Mojo |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 81 | |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 82 | ### Linux |
| 83 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 84 | Build Mojo for Linux by running: |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 85 | |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 86 | ``` |
Nick Bray | e5ac342 | 2014-12-16 13:27:24 -0800 | [diff] [blame] | 87 | $ ninja -C out/Debug -j 10 |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 88 | ``` |
| 89 | |
Przemyslaw Pietrzkiewicz | 628d907 | 2015-06-09 18:33:52 +0200 | [diff] [blame] | 90 | You can also use the `mojob.py` script for building. This script automatically |
| 91 | calls ninja and sets -j to an appropriate value based on whether Goma (see the |
| 92 | section on Goma below) is present. You cannot specify a target name with this |
| 93 | script. |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 94 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 95 | ``` |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 96 | mojo/tools/mojob.py gn |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 97 | mojo/tools/mojob.py build |
| 98 | ``` |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 99 | |
aboodman | d53c269 | 2014-10-29 21:46:27 -0700 | [diff] [blame] | 100 | Run a demo: |
| 101 | ``` |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 102 | out/Debug/mojo_shell mojo:spinning_cube |
aboodman | d53c269 | 2014-10-29 21:46:27 -0700 | [diff] [blame] | 103 | ``` |
| 104 | |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 105 | Run the tests: |
| 106 | ``` |
John Abd-El-Malek | 6d1ef8a | 2014-11-10 12:04:25 -0800 | [diff] [blame] | 107 | mojo/tools/mojob.py test |
Scott Violet | 5724494 | 2014-10-27 13:55:48 -0700 | [diff] [blame] | 108 | ``` |
| 109 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 110 | Create a release build: |
| 111 | ``` |
| 112 | mojo/tools/mojob.py gn --release |
| 113 | mojo/tools/mojob.py build --release |
| 114 | mojo/tools/mojob.py test --release |
| 115 | ``` |
| 116 | |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 117 | ### Android |
Scott Violet | 5724494 | 2014-10-27 13:55:48 -0700 | [diff] [blame] | 118 | |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 119 | To build for Android, first make sure that your checkout is [configured](#configure-android) to build |
| 120 | for Android. After that you can use the mojob script as follows: |
Przemyslaw Pietrzkiewicz | 87efd5f | 2015-06-08 18:00:43 +0200 | [diff] [blame] | 121 | ``` |
| 122 | $ mojo/tools/mojob.py gn --android |
| 123 | $ mojo/tools/mojob.py build --android |
| 124 | ``` |
| 125 | |
| 126 | The 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 Pietrzkiewicz | 628d907 | 2015-06-09 18:33:52 +0200 | [diff] [blame] | 129 | ### Goma (Googlers only) |
| 130 | |
| 131 | If you're a Googler, you can use Goma, a distributed compiler service for |
| 132 | open-source projects such as Chrome and Android. If Goma is installed in the |
| 133 | default location (~/goma), it will work out-of-the-box with the `mojob.py gn`, |
| 134 | `mojob.py build` workflow described above. |
| 135 | |
| 136 | You can also manually add: |
| 137 | ``` |
| 138 | use_goma = true |
| 139 | ``` |
| 140 | |
| 141 | at the end of the file opened through: |
| 142 | ``` |
| 143 | $ gn args out/Debug |
| 144 | ``` |
| 145 | |
| 146 | After you close the editor `gn gen out/Debug` will run automatically. Now you |
| 147 | can dramatically increase the number of parallel tasks: |
| 148 | ``` |
| 149 | $ ninja -C out/Debug -j 1000 |
| 150 | ``` |
| 151 | |
Etienne Membrives | 7988866 | 2015-06-17 13:00:21 +0200 | [diff] [blame] | 152 | ### Official builds |
| 153 | |
| 154 | Official builds for android generate a signed Mojo Shell intended for |
| 155 | distribution. You normally should not need to produce one. If you have any |
| 156 | questions, reach out to [etiennej@chromium.org](mailto:etiennej@chromium.org). |
| 157 | |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 158 | ## Run Mojo Shell |
| 159 | |
Przemyslaw Pietrzkiewicz | 11e4fcd | 2015-07-31 14:00:44 +0200 | [diff] [blame] | 160 | Devtools `mojo_run` is a universal shell runner abstracting away the differences |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 161 | between running on Linux and Android. |
| 162 | |
| 163 | Having built Mojo as described above, a demo app can be run as follows: |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 164 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 165 | ``` |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 166 | mojo/devtools/common/mojo_run https://core.mojoapps.io/spinning_cube.mojo # Linux |
| 167 | mojo/devtools/common/mojo_run https://core.mojoapps.io/spinning_cube.mojo --android # Android |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 168 | ``` |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 169 | |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 170 | ### Development server |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 171 | |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 172 | Whenever `mojo_run` is run, a development server is set up according to [the |
| 173 | config file](mojoconfig). The server runs on your machine, serving the locally |
| 174 | built apps, but appears to the shell under the `https://core.mojoapps.io` host. |
| 175 | |
| 176 | You can ignore the config file and skip spawning the local server (for example, |
| 177 | in 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 | |
| 182 | Some applications can be run directly from the source tree. The development |
| 183 | server serves the `src` directory, allowing to refer to these apps. For |
| 184 | instance, this command serves a dart Mojo app from the source at |
| 185 | `examples/dart/device_info/main.dart`: |
| 186 | |
| 187 | ```sh |
Przemyslaw Pietrzkiewicz | cd34535 | 2015-09-17 17:20:46 +0200 | [diff] [blame] | 188 | mojo/devtools/common/mojo_run https://core.mojoapps.io/examples/dart/device_info/lib/main.dart [--android] |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 189 | ``` |
| 190 | |
| 191 | Some applications are meant to be run embedded in a **window manager**. To run |
Przemyslaw Pietrzkiewicz | 4f1253d | 2015-08-10 14:32:28 +0200 | [diff] [blame] | 192 | these, you can pass the app url using the `--embed` flag. This will run the |
| 193 | window manager and pass the given url to it: |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 194 | |
| 195 | ```sh |
Przemyslaw Pietrzkiewicz | cd34535 | 2015-09-17 17:20:46 +0200 | [diff] [blame] | 196 | mojo/devtools/common/mojo_run --embed https://core.mojoapps.io/ganesh_app.mojo [--android] |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 197 | ``` |
| 198 | |
Przemyslaw Pietrzkiewicz | cd34535 | 2015-09-17 17:20:46 +0200 | [diff] [blame] | 199 | By default, `mojo_run` uses mojo:kiosk_wm as the window |
Przemyslaw Pietrzkiewicz | 4f1253d | 2015-08-10 14:32:28 +0200 | [diff] [blame] | 200 | manager. You can pass a different window manager url using the |
| 201 | `--window-manager` flag to override this. |
| 202 | |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 203 | For additional information on `mojo_run` refer to the built-in help and the |
Przemyslaw Pietrzkiewicz | cd34535 | 2015-09-17 17:20:46 +0200 | [diff] [blame] | 204 | [documentation](mojo/devtools/common/docs/mojo_run.md). |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 205 | You can also request more information on what the tool is doing for you by |
| 206 | passing the `--verbose` flag. |
Przemyslaw Pietrzkiewicz | 07b257f | 2015-06-15 17:29:26 +0200 | [diff] [blame] | 207 | |
Przemyslaw Pietrzkiewicz | 8fc79b0 | 2015-06-10 17:44:55 +0200 | [diff] [blame] | 208 | ### <a name="debugging"></a>Debugging, tracing, profiling |
| 209 | |
Przemyslaw Pietrzkiewicz | 11e4fcd | 2015-07-31 14:00:44 +0200 | [diff] [blame] | 210 | Devtools `mojo_debug` allows you to interactively inspect a running shell, |
| 211 | collect performance traces and attach a gdb debugger. |
| 212 | |
| 213 | For additional information refer to the built-in help and the |
Przemyslaw Pietrzkiewicz | cd34535 | 2015-09-17 17:20:46 +0200 | [diff] [blame] | 214 | [documentation](mojo/devtools/common/docs/mojo_debug.md). |
Etienne Membrives | 72098cf | 2015-07-16 13:07:11 +0200 | [diff] [blame] | 215 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 216 | ### Android set-up |
| 217 | |
| 218 | #### Adb |
| 219 | |
| 220 | For the Android tooling to work, you will need to have `adb` in your PATH. For |
| 221 | that, you can either run: |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 222 | ``` |
| 223 | source build/android/envsetup.sh |
| 224 | ``` |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 225 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 226 | each time you open a fresh terminal, or add something like: |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 227 | ``` |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 228 | export PATH="$PATH":$MOJO_DIR/src/third_party/android_tools/sdk/platform-tools |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 229 | ``` |
| 230 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 231 | to your ~/.bashrc file, $MOJO_DIR being a path to your Mojo checkout. |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 232 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 233 | #### Device |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 234 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 235 | **The device has to be running Android 5.0 (Lollipop) or newer.** |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 236 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 237 | Many features useful for development (ie. streaming of the shell stdout when |
| 238 | running shell on the device) will not work unless the device is rooted and |
| 239 | running a userdebug build. For Googlers, [follow the instructions at this |
| 240 | link](http://go/mojo-internal-build-instructions). |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 241 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 242 | ### Running manually on Linux |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 243 | |
Przemyslaw Pietrzkiewicz | 31bb909 | 2015-06-09 20:34:31 +0200 | [diff] [blame] | 244 | If you wish to, you can also run the Linux Mojo shell directly with no wrappers: |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 245 | ``` |
Przemyslaw Pietrzkiewicz | f54ced5 | 2015-08-07 13:33:39 +0200 | [diff] [blame] | 246 | ./out/Debug/mojo_shell out/Debug/spinning_cube.mojo |
Przemyslaw Pietrzkiewicz | 7510eb8 | 2015-06-05 14:40:57 +0200 | [diff] [blame] | 247 | ``` |
Przemyslaw Pietrzkiewicz | ed91368 | 2015-08-10 15:37:14 +0200 | [diff] [blame] | 248 | |
| 249 | ## Contribute |
| 250 | |
| 251 | With git you should make all your changes in a local branch. Once your change is |
| 252 | committed, you can delete this branch. |
| 253 | |
| 254 | Create a local branch named "mywork" and make changes to it. |
| 255 | ``` |
| 256 | cd src |
| 257 | git new-branch mywork |
| 258 | vi ... |
| 259 | ``` |
| 260 | Commit your change locally. (this doesn't commit your change to the SVN or Git |
| 261 | server) |
| 262 | |
| 263 | ``` |
| 264 | git commit -a |
| 265 | ``` |
| 266 | |
| 267 | Fix your source code formatting. |
| 268 | |
| 269 | ``` |
| 270 | $ git cl format |
| 271 | ``` |
| 272 | |
| 273 | Upload your change for review. |
| 274 | |
| 275 | ``` |
| 276 | $ git cl upload |
| 277 | ``` |
| 278 | |
| 279 | Respond to review comments. |
| 280 | |
| 281 | See [Contributing code](http://www.chromium.org/developers/contributing-code) |
| 282 | for more detailed git instructions, including how to update your CL when you get |
| 283 | review comments. There's a short tutorial that might be helpful to try before |
| 284 | making your first change: [C++ in Chromium |
| 285 | 101](http://dev.chromium.org/developers/cpp-in-chromium-101-codelab). |
| 286 | |
| 287 | To land a change after receiving LGTM: |
| 288 | ``` |
| 289 | $ git cl land |
| 290 | ``` |
| 291 | |
| 292 | Don't break the build! Waterfall is here: |
| 293 | http://build.chromium.org/p/client.mojo/waterfall |