blob: 1d0c76ab43b9fc604843deb7a8e27a931d1d1c2f [file] [log] [blame] [view]
michaeldo8cccf2142017-03-06 22:12:021# Checking out and building Chromium for iOS
2
3There are instructions for other platforms linked from the
4[get the code](../get_the_code.md) page.
5
6## Instructions for Google Employees
7
8Are you a Google employee? See
9[go/building-chrome](https://goto.google.com/building-chrome) instead.
10
11[TOC]
12
13## System requirements
14
Mike Pinkerton90553fe2017-12-13 16:40:3015* A 64-bit Mac running 10.12.6 or later.
Justin Cohen0dcd4d82017-09-13 18:18:5616* [Xcode](https://developer.apple.com/xcode) 9.0+.
michaeldo8cccf2142017-03-06 22:12:0217* The current version of the JDK (required for the Closure compiler).
18
19## Install `depot_tools`
20
21Clone the `depot_tools` repository:
22
23```shell
24$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
25```
26
27Add `depot_tools` to the end of your PATH (you will probably want to put this
28in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
29`/path/to/depot_tools`:
30
31```shell
32$ export PATH="$PATH:/path/to/depot_tools"
33```
34
35## Get the code
36
37Create a `chromium` directory for the checkout and change to it (you can call
38this whatever you like and put it wherever you like, as
39long as the full path has no spaces):
40
41```shell
42$ mkdir chromium && cd chromium
43```
44
45Run the `fetch` tool from `depot_tools` to check out the code and its
46dependencies.
47
48```shell
49$ fetch ios
50```
51
52If you don't want the full repo history, you can save a lot of time by
53adding the `--no-history` flag to `fetch`.
54
55Expect the command to take 30 minutes on even a fast connection, and many
56hours on slower ones.
57
58When `fetch` completes, it will have created a hidden `.gclient` file and a
59directory called `src` in the working directory. The remaining instructions
60assume you have switched to the `src` directory:
61
62```shell
63$ cd src
64```
65
66*Optional*: You can also [install API
67keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
68build to talk to some Google services, but this is not necessary for most
69development and testing purposes.
70
71## Setting up the build
72
73Since the iOS build is a bit more complicated than a desktop build, we provide
74`ios/build/tools/setup-gn.py`, which will create four appropriately configured
75build directories under `out` for Release and Debug device and simulator
ichikawa7c540a12017-05-18 05:50:3276builds, and generates an appropriate Xcode workspace
77(`out/build/all.xcworkspace`) as well.
michaeldo8cccf2142017-03-06 22:12:0278
michaeldo8cccf2142017-03-06 22:12:0279You can customize the build by editing the file `$HOME/.setup-gn` (create it if
80it does not exist). Look at `src/ios/build/tools/setup-gn.config` for
81available configuration options.
82
83From this point, you can either build from Xcode or from the command line using
84`ninja`. `setup-gn.py` creates sub-directories named
85`out/${configuration}-${platform}`, so for a `Debug` build for simulator use:
86
87```shell
88$ ninja -C out/Debug-iphonesimulator gn_all
89```
90
91Note: you need to run `setup-gn.py` script every time one of the `BUILD.gn`
92file is updated (either by you or after rebasing). If you forget to run it,
93the list of targets and files in the Xcode solution may be stale.
94
95You can also follow the manual instructions on the
96[Mac page](../mac_build_instructions.md), but make sure you set the
97GN arg `target_os="ios"`.
98
99## Building for device
100
101To be able to build and run Chromium and the tests for devices, you need to
102have an Apple developer account (a free one will work) and the appropriate
103provisioning profiles, then configure the build to use them.
104
105### Code signing identity
106
107Please refer to the Apple documentation on how to get a code signing identity
108and certificates. You can check that you have a code signing identity correctly
109installed by running the following command.
110
111```shell
112$ xcrun security find-identity -v -p codesigning
113 1) 0123456789ABCDEF0123456789ABCDEF01234567 "iPhone Developer: [email protected] (XXXXXXXXXX)"
114 1 valid identities found
115```
116
117If the command output says you have zero valid identities, then you do not
118have a code signing identity installed and need to get one from Apple. If
119you have more than one identity, the build system may select the wrong one
120automatically, and you can use the `ios_code_signing_identity` gn variable
121to control which one to use by setting it to the identity hash, e.g. to
122`"0123456789ABCDEF0123456789ABCDEF01234567"`.
123
124### Mobile provisioning profiles
125
126Once you have the code signing identity, you need to decide on a prefix
127for the application bundle identifier. This is controlled by the gn variable
128`ios_app_bundle_id_prefix` and usually corresponds to a reversed domain name
129(the default value is `"org.chromium"`).
130
131You then need to request provisioning profiles from Apple for your devices
132for the following bundle identifiers to build and run Chromium with these
133application extensions:
134
135- `${prefix}.chrome.ios.herebedragons`
136- `${prefix}.chrome.ios.herebedragons.ShareExtension`
137- `${prefix}.chrome.ios.herebedragons.TodayExtension`
lodf31fea5a2017-04-19 15:05:59138- `${prefix}.chrome.ios.herebedragons.SearchTodayExtension`
michaeldo8cccf2142017-03-06 22:12:02139
140All these certificates need to have the "App Groups"
141(`com.apple.security.application-groups`) capability enabled for
142the following groups:
143
144- `group.${prefix}.chrome`
145- `group.${prefix}.common`
146
147The `group.${prefix}.chrome` is only shared by Chromium and its extensions
148to share files and configurations while the `group.${prefix}.common` is shared
149with Chromium and other applications from the same organisation and can be used
150to send commands to Chromium.
151
152### Mobile provisioning profiles for tests
153
154In addition to that, you need provisioning profiles for the individual test
155suites that you want to run. Their bundle identifier depends on whether the
156gn variable `ios_automatically_manage_certs` is set to true (the default)
157or false.
158
159If set to true, then you just need a provisioning profile for the bundle
160identifier `${prefix}.gtest.generic-unit-test` but you can only have a
161single test application installed on the device (all the test application
162will share the same bundle identifier).
163
164If set to false, then you need a different provisioning profile for each
165test application. Those provisioning profile will have a bundle identifier
166matching the following pattern `${prefix}.gtest.${test-suite-name}` where
167`${test-suite-name}` is the name of the test suite with underscores changed
168to dashes (e.g. `base_unittests` app will use `${prefix}.gest.base-unittests`
169as bundle identifier).
170
171To be able to run the EarlGrey tests on a device, you'll need two provisioning
172profiles for EarlGrey and OCHamcrest frameworks:
173
174- `${prefix}.test.OCHamcrest`
175- `${prefix}.test.EarlGrey`
176
177In addition to that, then you'll need one additional provisioning profile for
178the XCTest module too. This module bundle identifier depends on whether the
179gn variable `ios_automatically_manage_certs` is set to true or false. If set
Sylvain Defresnec63957142017-07-11 12:04:01180to true, then `${prefix}.gtest.generic-unit-test-module` will be used, otherwise
181it will match the pattern: `${prefix}.gtest.${test-suite-name}-module`.
michaeldo8cccf2142017-03-06 22:12:02182
183### Other applications
184
185Other applications like `ios_web_shell` usually will require mobile provisioning
186profiles with bundle identifiers that may usually match the following pattern
187`${prefix}.${application-name}` and may require specific capabilities.
188
189Generally, if the mobile provisioning profile is missing then the code signing
190step will fail and will print the bundle identifier of the bundle that could not
191be signed on the command line, e.g.:
192
193```shell
194$ ninja -C out/Debug-iphoneos ios_web_shell
195ninja: Entering directory `out/Debug-iphoneos'
196FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision
197python ../../build/config/ios/codesign.py code-sign-bundle -t=iphoneos -i=0123456789ABCDEF0123456789ABCDEF01234567 -e=../../build/config/ios/entitlements.plist -b=obj/ios/web/shell/ios_web_shell ios_web_shell.app
198Error: no mobile provisioning profile found for "org.chromium.ios-web-shell".
199ninja: build stopped: subcommand failed.
200```
201
202Here, the build is failing because there are no mobile provisioning profiles
203installed that could sign the `ios_web_shell.app` bundle with the identity
204`0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to
205request such a mobile provisioning profile from Apple.
206
207You can inspect the file passed via the `-e` flag to the `codesign.py` script
208to check which capabilites are required for the mobile provisioning profile
209(e.g. `src/build/config/ios/entitlements.plist` for the above build error,
210remember that the paths are relative to the build directory, not to the source
211directory).
212
213If the required capabilities are not enabled on the mobile provisioning profile,
214then it will be impossible to install the application on a device (Xcode will
215display an error stating that "The application was signed with invalid
216entitlements").
217
218## Running apps from the commandline
219
220Any target that is built and runs on the bots (see [below](#Troubleshooting))
221should run successfully in a local build. To run in the simulator from the
222command line, you can use `iossim`. For example, to run a debug build of
223`Chromium`:
224
225```shell
226$ out/Debug-iphonesimulator/iossim out/Debug-iphonesimulator/Chromium.app
227```
228
Mike Pinkerton90553fe2017-12-13 16:40:30229With Xcode 9, `iossim` no longer automatically launches the Simulator. This must now
230be done manually from within Xcode (`Xcode > Open Developer Tool > Simulator`), and
231also must be done *after* running `iossim`.
232
Vaclav Brozek09fe5ec2017-07-18 11:13:16233### Passing arguments
234
235Arguments needed to be passed to the test application through `iossim`, such as
236`--gtest_filter=SomeTest.FooBar` should be passed through the `-c` flag:
237
238```shell
239$ out/Debug-iphonesimulator/iossim -d "iPhone 6s" -s 10.0 \
240 -c "--gtest_filter=SomeTest.FooBar --gtest_repeat=3" \
241 out/Debug-iphonesimulator/base_unittests.app
242```
243
Mike Baxleycb99a9f2017-07-12 15:16:11244### Running EarlGrey tests
245
246EarlGrey tests are run differently than other test targets, as there is an
247XCTest bundle that is injected into the target application. Therefore you must
248also pass in the test bundle:
249
250```shell
251$ out/Debug-iphonesimulator/iossim \
252 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app \
253 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app/PlugIns/ios_chrome_ui_egtests_module.xctest
254```
255
michaeldo8cccf2142017-03-06 22:12:02256## Update your checkout
257
258To update an existing checkout, you can run
259
260```shell
261$ git rebase-update
262$ gclient sync
263```
264
265The first command updates the primary Chromium source repository and rebases
266any of your local branches on top of tip-of-tree (aka the Git branch
267`origin/master`). If you don't want to use this script, you can also just use
268`git pull` or other common Git commands to update the repo.
269
270The second command syncs dependencies to the appropriate versions and re-runs
271hooks as needed.
272
273## Tips, tricks, and troubleshooting
274
275If you have problems building, join us in `#chromium` on `irc.freenode.net` and
276ask there. As mentioned above, be sure that the
277[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
278is open before checking out. This will increase your chances of success.
279
280### Improving performance of `git status`
281
ishermance1d9d82017-05-12 23:10:04282#### Increase the vnode cache size
283
michaeldo8cccf2142017-03-06 22:12:02284`git status` is used frequently to determine the status of your checkout. Due
285to the large number of files in Chromium's checkout, `git status` performance
286can be quite variable. Increasing the system's vnode cache appears to help.
287By default, this command:
288
289```shell
290$ sysctl -a | egrep kern\..*vnodes
291```
292
293Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
294setting:
295
296```shell
297$ sudo sysctl kern.maxvnodes=$((512*1024))
298```
299
300Higher values may be appropriate if you routinely move between different
301Chromium checkouts. This setting will reset on reboot, the startup setting can
302be set in `/etc/sysctl.conf`:
303
304```shell
305$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
306```
307
308Or edit the file directly.
309
ishermance1d9d82017-05-12 23:10:04310#### Configure git to use an untracked cache
311
312If `git --version` reports 2.8 or higher, try running
313
314```shell
315$ git update-index --test-untracked-cache
316```
317
318If the output ends with `OK`, then the following may also improve performance of
319`git status`:
320
321```shell
322$ git config core.untrackedCache true
323```
324
325If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
michaeldo8cccf2142017-03-06 22:12:02326
327```shell
328$ git update-index --untracked-cache
329```
330
331### Xcode license agreement
332
333If you're getting the error
334
335> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
336> root via sudo.
337
338the Xcode license hasn't been accepted yet which (contrary to the message) any
339user can do by running:
340
341```shell
342$ xcodebuild -license
343```
344
345Only accepting for all users of the machine requires root:
346
347```shell
348$ sudo xcodebuild -license
349```