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 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 4 | Mojo is an effort to extract a common platform out of Chrome's renderer and plugin processes that can support multiple types of sandboxed content, such as HTML, Pepper, or NaCl. |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 5 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 6 | ## Set up your environment |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 7 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 8 | The instructions below only need to be done once. Note that a simple "git clone" command is not sufficient to build the source code because this repo uses the gclient command from depot_tools to manage most third party dependencies. |
| 9 | |
| 10 | 1. Download depot_tools and make sure it is in your path:<br>http://www.chromium.org/developers/how-tos/install-depot-tools<br> |
| 11 | |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 12 | 2. [Googlers only] Install Goma in ~/goma. |
| 13 | |
| 14 | 3. Create a directory somewhere for your checkout (preferably on an SSD), cd into it, and run the following commands: |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 15 | |
James Robinson | 5562f1d | 2014-10-14 15:03:43 -0700 | [diff] [blame] | 16 | |
| 17 | ``` |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 18 | $ fetch mojo # append --target_os=android to include Android build support. |
Dirk Pranke | a54f884 | 2014-10-22 10:56:31 -0700 | [diff] [blame] | 19 | $ cd src |
aboodman | 51c5df5 | 2015-02-24 12:40:41 -0800 | [diff] [blame] | 20 | |
aboodman | 68d7957 | 2015-02-24 12:40:20 -0800 | [diff] [blame] | 21 | # 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] | 22 | $ ./build/install-build-deps.sh |
aboodman | 51c5df5 | 2015-02-24 12:40:41 -0800 | [diff] [blame] | 23 | |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 24 | $ mojo/tools/mojob.py gn |
James Robinson | fb7fc8c | 2014-10-14 15:04:21 -0700 | [diff] [blame] | 25 | ``` |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 26 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 27 | The "fetch mojo" command does the following: |
| 28 | - creates a directory called 'src' under your checkout directory |
| 29 | - clones the repository using git clone |
| 30 | - clones dependencies with gclient sync |
| 31 | |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 32 | `install-build-deps.sh` installs any packages needed to build, then `mojo/tools/mojob.py gn` runs `gn args` and configures the build directory, out/Debug. |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 33 | |
| 34 | If the fetch command fails, you will need to delete the src directory and start over. |
| 35 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 36 | ## <a name="buildmojo"></a>Build Mojo |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 37 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 38 | Build Mojo for Linux by running: |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 39 | |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 40 | ``` |
Nick Bray | e5ac342 | 2014-12-16 13:27:24 -0800 | [diff] [blame] | 41 | $ ninja -C out/Debug -j 10 |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 42 | ``` |
| 43 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 44 | (If you are a Googler, see the section at the end of this document for faster builds.) |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 45 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 46 | You can also use the mojob.py script for building. This script automatically calls ninja and sets -j to an appropriate value based on whether Goma is present. You cannot specify a target name with this script. |
| 47 | ``` |
| 48 | mojo/tools/mojob.py build |
| 49 | ``` |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 50 | |
aboodman | d53c269 | 2014-10-29 21:46:27 -0700 | [diff] [blame] | 51 | Run a demo: |
| 52 | ``` |
Tony Gentilcore | 3425f21 | 2015-01-07 17:17:04 -0800 | [diff] [blame] | 53 | mojo/tools/mojo_demo.py --browser |
aboodman | d53c269 | 2014-10-29 21:46:27 -0700 | [diff] [blame] | 54 | ``` |
| 55 | |
John Abd-El-Malek | b315f49 | 2014-10-23 14:31:58 -0700 | [diff] [blame] | 56 | Run the tests: |
| 57 | ``` |
John Abd-El-Malek | 6d1ef8a | 2014-11-10 12:04:25 -0800 | [diff] [blame] | 58 | mojo/tools/mojob.py test |
Scott Violet | 5724494 | 2014-10-27 13:55:48 -0700 | [diff] [blame] | 59 | ``` |
| 60 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 61 | Create a release build: |
| 62 | ``` |
| 63 | mojo/tools/mojob.py gn --release |
| 64 | mojo/tools/mojob.py build --release |
| 65 | mojo/tools/mojob.py test --release |
| 66 | ``` |
| 67 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 68 | ## Update your repo |
Scott Violet | 5724494 | 2014-10-27 13:55:48 -0700 | [diff] [blame] | 69 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 70 | You can update your repo like this: |
| 71 | ``` |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 72 | $ git pull --rebase |
Julien Tinnes | a1f799b | 2015-02-12 22:36:32 -0800 | [diff] [blame] | 73 | (fetch changes from upstream and rebase the current branch on top) |
Jim Beveridge | 1c5fe0e | 2015-02-11 07:58:49 -0800 | [diff] [blame] | 74 | $ gclient sync |
Julien Tinnes | a1f799b | 2015-02-12 22:36:32 -0800 | [diff] [blame] | 75 | (update all modules as directed by the DEPS file) |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 76 | ``` |
| 77 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 78 | You do not need to rerun `gn gen out/Debug` or `mojo/tools/mojob.py gn`. Ninja will do so automatically as needed. |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 79 | |
| 80 | ## Contribute |
| 81 | |
| 82 | With git you should make all your changes in a local branch. Once your change is committed, you can delete this branch. |
| 83 | |
| 84 | Create a local branch named "mywork" and make changes to it. |
| 85 | ``` |
| 86 | cd src |
| 87 | git new-branch mywork |
| 88 | vi ... |
| 89 | ``` |
| 90 | Commit your change locally (this doesn't commit your change to the SVN or Git server) |
| 91 | |
| 92 | ``` |
| 93 | git commit -a |
| 94 | ``` |
Jim Beveridge | 3adac66 | 2014-12-02 08:57:48 -0800 | [diff] [blame] | 95 | |
| 96 | Fix your source code formatting |
| 97 | |
| 98 | ``` |
| 99 | $ git cl format |
| 100 | ``` |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 101 | |
| 102 | Upload your change for review |
| 103 | |
| 104 | ``` |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 105 | $ git cl upload |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 106 | ``` |
| 107 | |
| 108 | Respond to review comments |
Jim Beveridge | 3adac66 | 2014-12-02 08:57:48 -0800 | [diff] [blame] | 109 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 110 | See <a href="http://www.chromium.org/developers/contributing-code">Contributing code</a> for more detailed git instructions, including how to update your CL when you get review comments. There's a short tutorial that might be helpful to try before your first change: <a href="http://dev.chromium.org/developers/cpp-in-chromium-101-codelab">C++ in Chromium 101</a>. |
| 111 | |
| 112 | To land a change after receiving LGTM: |
Scott Violet | 5724494 | 2014-10-27 13:55:48 -0700 | [diff] [blame] | 113 | ``` |
| 114 | $ git cl land |
| 115 | ``` |
| 116 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 117 | Don't break the build! Waterfall is here: http://build.chromium.org/p/client.mojo/waterfall |
| 118 | |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 119 | ## Android Builds |
| 120 | |
| 121 | To build for Android, first make sure you've downloaded build support for Android, which you would have done by adding --target_os=android when you ran `fetch mojo`. If you didn't do that, there's an easy fix. Edit the file .gclient in your root Mojo directory (the parent directory to src.) Add this line at the end of the file: |
| 122 | |
| 123 | ``` |
| 124 | target_os = [u'android'] |
| 125 | ``` |
| 126 | |
Scott Violet | 965eaf2 | 2015-02-25 16:30:47 -0800 | [diff] [blame] | 127 | Bring in android specific build dependencies: |
| 128 | ``` |
| 129 | $ build/install-build-deps-android.sh |
| 130 | ``` |
| 131 | |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 132 | Pull down all of the packages with this command: |
| 133 | |
| 134 | ``` |
| 135 | $ gclient sync |
| 136 | ``` |
| 137 | |
| 138 | Prepare the build directory for Android: |
| 139 | |
| 140 | ``` |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 141 | $ mojo/tools/mojob.py gn --android |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 142 | ``` |
| 143 | |
| 144 | Finally, perform the build. The result will be in out/android_Debug: |
| 145 | |
| 146 | ``` |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 147 | $ mojo/tools/mojob.py build --android |
Jim Beveridge | 804f6c0 | 2014-11-24 15:58:08 -0800 | [diff] [blame] | 148 | ``` |
| 149 | |
Eric Seidel | fd6151e | 2015-01-22 13:08:27 -0800 | [diff] [blame] | 150 | If you see javac compile errors, make sure you have an up-to-date JDK: |
| 151 | https://code.google.com/p/chromium/wiki/AndroidBuildInstructions#Install_Java_JDK |
| 152 | |
Elliot Glaysher | 2175b88 | 2015-02-26 14:32:20 -0800 | [diff] [blame] | 153 | ## Dart Code |
| 154 | |
| 155 | Because the dart analyzer is a bit slow, we don't run it unless the user specifically asks for it. To run the dart analyzer against the list of dart targets in the toplevel BUILD.gn file, run: |
| 156 | |
| 157 | ``` |
| 158 | $ mojo/tools/mojob.py dartcheck |
| 159 | ``` |
| 160 | |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 161 | ## Googlers |
| 162 | |
| 163 | If you're a Googler, you can use Goma, a distributed compiler service for open-source projects such as Chrome and Android. The instructions below assume that Goma is installed in the default location (~/goma). |
| 164 | |
| 165 | To enable Goma, update your "args.gn" file. Open the file in your editor with this command: |
| 166 | ``` |
| 167 | $ gn args out/Debug |
| 168 | ``` |
| 169 | |
| 170 | Add this line to the end of the file: |
| 171 | ``` |
| 172 | use_goma = true |
| 173 | ``` |
| 174 | |
| 175 | After you close the editor, the "gn args" command will automatically run "gn gen out/Debug" again. |
| 176 | |
| 177 | Now you can dramatically increase the number of parallel tasks: |
| 178 | ``` |
Nick Bray | e5ac342 | 2014-12-16 13:27:24 -0800 | [diff] [blame] | 179 | $ ninja -C out/Debug -j 1000 |
Jim Beveridge | a98e435 | 2014-11-14 10:21:29 -0800 | [diff] [blame] | 180 | ``` |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 181 | |
| 182 | ## Run Mojo Shell |
| 183 | |
| 184 | ### On Android |
| 185 | |
| 186 | 0. Prerequisites: |
| 187 | * Before you start, you'll need a device with an unlocked bootloader, otherwise you won't be able to run adb root (or any of the commands that require root). For Googlers, <a href="http://go/mojo-internal-build-instructions">follow this link</a> and follow the instructions before returning to this page. |
| 188 | * Ensure your device is running Lollipop and has an userdebug build. |
Alhaad Gokhale | 06bec97 | 2015-02-11 16:15:42 -0800 | [diff] [blame] | 189 | * Set up environment for building on Android. This sets up the adb path, etc. You may need to remove /usr/bin/adb. |
| 190 | ``` |
| 191 | source build/android/envsetup.sh |
| 192 | ``` |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 193 | |
| 194 | 1. Build changed files: |
| 195 | ``` |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 196 | mojo/tools/mojob.py build --android |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 197 | ``` |
| 198 | |
| 199 | 2. Push mojo_shell to to your device: |
| 200 | ``` |
| 201 | adb install -r out/android_Debug/apks/MojoShell.apk |
| 202 | ``` |
| 203 | |
| 204 | 3. Run Mojo Shell on the device: |
| 205 | ``` |
Przemyslaw Pietrzkiewicz | 6917151 | 2015-03-02 11:45:56 +0100 | [diff] [blame] | 206 | mojo/tools/android_mojo_shell.py mojo:spinning_cube |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 207 | ``` |
aboodman | 6405901 | 2015-02-24 13:35:08 -0800 | [diff] [blame] | 208 | If this fails and prints: |
| 209 | ``` |
| 210 | error: closed |
| 211 | error: closed |
| 212 | ``` |
| 213 | ... then you may not have a new enough build of Android on your device. You need L (Lollipop) or later. |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 214 | |
| 215 | 4. If you get a crash you won't see symbols. Use tools/android_stack_parser/stack to map back to symbols, e.g.: |
| 216 | ``` |
| 217 | adb logcat | ./tools/android_stack_parser/stack |
| 218 | ``` |
| 219 | |
Yuzhu Shen | 420429b | 2015-01-21 13:53:52 -0800 | [diff] [blame] | 220 | ### On Linux |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 221 | |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 222 | 1. Build the mojo target as described under [link](#buildmojo). |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 223 | |
| 224 | 2. Run Mojo Shell: |
| 225 | ``` |
Przemyslaw Pietrzkiewicz | 6917151 | 2015-03-02 11:45:56 +0100 | [diff] [blame] | 226 | ./out/Debug/mojo_shell mojo:spinning_cube |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 227 | ``` |
| 228 | |
| 229 | 3. Optional: Run Mojo Shell with an HTTP server |
| 230 | ``` |
Jim Beveridge | 0ac4ba4 | 2015-02-18 14:55:51 -0800 | [diff] [blame] | 231 | cd out/Debug |
Eric Seidel | fd6151e | 2015-01-22 13:08:27 -0800 | [diff] [blame] | 232 | python -m SimpleHTTPServer 4444 & |
Przemyslaw Pietrzkiewicz | 6917151 | 2015-03-02 11:45:56 +0100 | [diff] [blame] | 233 | ./mojo_shell --origin=http://127.0.0.1:4444 --disable-cache mojo:spinning_cube |
Yuzhu Shen | 06d1c3f | 2015-01-21 13:51:57 -0800 | [diff] [blame] | 234 | ``` |