blob: 74912dfe06ae75aeb26002876abc0ca1d61de739 [file] [log] [blame] [view]
James Robinsonfca33c52014-10-01 13:06:09 -07001Mojo
2====
James Robinson5562f1d2014-10-14 15:03:43 -07003
Jim Beveridgea98e4352014-11-14 10:21:29 -08004Mojo 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 Robinson5562f1d2014-10-14 15:03:43 -07005
Jim Beveridgea98e4352014-11-14 10:21:29 -08006## Set up your environment
James Robinson5562f1d2014-10-14 15:03:43 -07007
Jim Beveridgea98e4352014-11-14 10:21:29 -08008The 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
101. 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 Beveridge804f6c02014-11-24 15:58:08 -0800122. [Googlers only] Install Goma in ~/goma.
13
143. Create a directory somewhere for your checkout (preferably on an SSD), cd into it, and run the following commands:
Jim Beveridgea98e4352014-11-14 10:21:29 -080015
James Robinson5562f1d2014-10-14 15:03:43 -070016
17```
Jim Beveridge804f6c02014-11-24 15:58:08 -080018$ fetch mojo # append --target_os=android to include Android build support.
Dirk Prankea54f8842014-10-22 10:56:31 -070019$ cd src
aboodman51c5df52015-02-24 12:40:41 -080020
aboodman68d79572015-02-24 12:40:20 -080021# Or install-build-deps-android.sh if you plan to build for Android.
Matt Perry0060e382014-10-21 16:34:57 -040022$ ./build/install-build-deps.sh
aboodman51c5df52015-02-24 12:40:41 -080023
Jim Beveridge804f6c02014-11-24 15:58:08 -080024$ mojo/tools/mojob.py gn
James Robinsonfb7fc8c2014-10-14 15:04:21 -070025```
John Abd-El-Malekb315f492014-10-23 14:31:58 -070026
Jim Beveridgea98e4352014-11-14 10:21:29 -080027The "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 Beveridge804f6c02014-11-24 15:58:08 -080032`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 Beveridgea98e4352014-11-14 10:21:29 -080033
34If the fetch command fails, you will need to delete the src directory and start over.
35
Jim Beveridge0ac4ba42015-02-18 14:55:51 -080036## <a name="buildmojo"></a>Build Mojo
Jim Beveridgea98e4352014-11-14 10:21:29 -080037
Jim Beveridge0ac4ba42015-02-18 14:55:51 -080038Build Mojo for Linux by running:
Jim Beveridgea98e4352014-11-14 10:21:29 -080039
John Abd-El-Malekb315f492014-10-23 14:31:58 -070040```
Nick Braye5ac3422014-12-16 13:27:24 -080041$ ninja -C out/Debug -j 10
John Abd-El-Malekb315f492014-10-23 14:31:58 -070042```
43
Jim Beveridgea98e4352014-11-14 10:21:29 -080044(If you are a Googler, see the section at the end of this document for faster builds.)
John Abd-El-Malekb315f492014-10-23 14:31:58 -070045
Jim Beveridgea98e4352014-11-14 10:21:29 -080046You 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```
48mojo/tools/mojob.py build
49```
John Abd-El-Malekb315f492014-10-23 14:31:58 -070050
aboodmand53c2692014-10-29 21:46:27 -070051Run a demo:
52```
Tony Gentilcore3425f212015-01-07 17:17:04 -080053mojo/tools/mojo_demo.py --browser
aboodmand53c2692014-10-29 21:46:27 -070054```
55
John Abd-El-Malekb315f492014-10-23 14:31:58 -070056Run the tests:
57```
John Abd-El-Malek6d1ef8a2014-11-10 12:04:25 -080058mojo/tools/mojob.py test
Scott Violet57244942014-10-27 13:55:48 -070059```
60
Jim Beveridge0ac4ba42015-02-18 14:55:51 -080061Create a release build:
62```
63mojo/tools/mojob.py gn --release
64mojo/tools/mojob.py build --release
65mojo/tools/mojob.py test --release
66```
67
Jim Beveridgea98e4352014-11-14 10:21:29 -080068## Update your repo
Scott Violet57244942014-10-27 13:55:48 -070069
Jim Beveridgea98e4352014-11-14 10:21:29 -080070You can update your repo like this:
71```
Jim Beveridgea98e4352014-11-14 10:21:29 -080072$ git pull --rebase
Julien Tinnesa1f799b2015-02-12 22:36:32 -080073(fetch changes from upstream and rebase the current branch on top)
Jim Beveridge1c5fe0e2015-02-11 07:58:49 -080074$ gclient sync
Julien Tinnesa1f799b2015-02-12 22:36:32 -080075(update all modules as directed by the DEPS file)
Jim Beveridgea98e4352014-11-14 10:21:29 -080076```
77
Jim Beveridge0ac4ba42015-02-18 14:55:51 -080078You do not need to rerun `gn gen out/Debug` or `mojo/tools/mojob.py gn`. Ninja will do so automatically as needed.
Jim Beveridgea98e4352014-11-14 10:21:29 -080079
80## Contribute
81
82With git you should make all your changes in a local branch. Once your change is committed, you can delete this branch.
83
84Create a local branch named "mywork" and make changes to it.
85```
86 cd src
87 git new-branch mywork
88 vi ...
89```
90Commit your change locally (this doesn't commit your change to the SVN or Git server)
91
92```
93 git commit -a
94```
Jim Beveridge3adac662014-12-02 08:57:48 -080095
96Fix your source code formatting
97
98```
99$ git cl format
100```
Jim Beveridgea98e4352014-11-14 10:21:29 -0800101
102Upload your change for review
103
104```
Jim Beveridge804f6c02014-11-24 15:58:08 -0800105$ git cl upload
Jim Beveridgea98e4352014-11-14 10:21:29 -0800106```
107
108Respond to review comments
Jim Beveridge3adac662014-12-02 08:57:48 -0800109
Jim Beveridgea98e4352014-11-14 10:21:29 -0800110See <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
112To land a change after receiving LGTM:
Scott Violet57244942014-10-27 13:55:48 -0700113```
114$ git cl land
115```
116
Jim Beveridgea98e4352014-11-14 10:21:29 -0800117Don't break the build! Waterfall is here: http://build.chromium.org/p/client.mojo/waterfall
118
Jim Beveridge804f6c02014-11-24 15:58:08 -0800119## Android Builds
120
121To 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```
124target_os = [u'android']
125```
126
Scott Violet965eaf22015-02-25 16:30:47 -0800127Bring in android specific build dependencies:
128```
129$ build/install-build-deps-android.sh
130```
131
Jim Beveridge804f6c02014-11-24 15:58:08 -0800132Pull down all of the packages with this command:
133
134```
135$ gclient sync
136```
137
138Prepare the build directory for Android:
139
140```
Jim Beveridge0ac4ba42015-02-18 14:55:51 -0800141$ mojo/tools/mojob.py gn --android
Jim Beveridge804f6c02014-11-24 15:58:08 -0800142```
143
144Finally, perform the build. The result will be in out/android_Debug:
145
146```
Jim Beveridge0ac4ba42015-02-18 14:55:51 -0800147$ mojo/tools/mojob.py build --android
Jim Beveridge804f6c02014-11-24 15:58:08 -0800148```
149
Eric Seidelfd6151e2015-01-22 13:08:27 -0800150If you see javac compile errors, make sure you have an up-to-date JDK:
151https://code.google.com/p/chromium/wiki/AndroidBuildInstructions#Install_Java_JDK
152
Elliot Glaysher2175b882015-02-26 14:32:20 -0800153## Dart Code
154
155Because 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 Beveridgea98e4352014-11-14 10:21:29 -0800161## Googlers
162
163If 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
165To enable Goma, update your "args.gn" file. Open the file in your editor with this command:
166```
167$ gn args out/Debug
168```
169
170Add this line to the end of the file:
171```
172use_goma = true
173```
174
175After you close the editor, the "gn args" command will automatically run "gn gen out/Debug" again.
176
177Now you can dramatically increase the number of parallel tasks:
178```
Nick Braye5ac3422014-12-16 13:27:24 -0800179$ ninja -C out/Debug -j 1000
Jim Beveridgea98e4352014-11-14 10:21:29 -0800180```
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800181
182## Run Mojo Shell
183
184### On Android
185
1860. 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 Gokhale06bec972015-02-11 16:15:42 -0800189 * 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 Shen06d1c3f2015-01-21 13:51:57 -0800193
1941. Build changed files:
195 ```
Jim Beveridge0ac4ba42015-02-18 14:55:51 -0800196 mojo/tools/mojob.py build --android
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800197 ```
198
1992. Push mojo_shell to to your device:
200 ```
201 adb install -r out/android_Debug/apks/MojoShell.apk
202 ```
203
2043. Run Mojo Shell on the device:
205 ```
Przemyslaw Pietrzkiewicz69171512015-03-02 11:45:56 +0100206 mojo/tools/android_mojo_shell.py mojo:spinning_cube
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800207 ```
aboodman64059012015-02-24 13:35:08 -0800208If 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 Shen06d1c3f2015-01-21 13:51:57 -0800214
2154. 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 Shen420429b2015-01-21 13:53:52 -0800220### On Linux
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800221
Jim Beveridge0ac4ba42015-02-18 14:55:51 -08002221. Build the mojo target as described under [link](#buildmojo).
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800223
2242. Run Mojo Shell:
225 ```
Przemyslaw Pietrzkiewicz69171512015-03-02 11:45:56 +0100226 ./out/Debug/mojo_shell mojo:spinning_cube
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800227 ```
228
2293. Optional: Run Mojo Shell with an HTTP server
230 ```
Jim Beveridge0ac4ba42015-02-18 14:55:51 -0800231 cd out/Debug
Eric Seidelfd6151e2015-01-22 13:08:27 -0800232 python -m SimpleHTTPServer 4444 &
Przemyslaw Pietrzkiewicz69171512015-03-02 11:45:56 +0100233 ./mojo_shell --origin=http://127.0.0.1:4444 --disable-cache mojo:spinning_cube
Yuzhu Shen06d1c3f2015-01-21 13:51:57 -0800234 ```