blob: 8f7a6eb45ac6b1818ccf5b0d5665aac2c4a2442c [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
Sylvain Defresned019a702018-02-01 10:11:51239$ out/Debug-iphonesimulator/iossim \
Vaclav Brozek09fe5ec2017-07-18 11:13:16240 -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
Sylvain Defresned019a702018-02-01 10:11:51256### Running on specific simulator
257
258By default, `iossim` will pick an arbitrary simulator to run the tests. If
259you want to run them on a specific simulator, you can use `-d` to pick the
260simulated device and `-s` to select the iOS version.
261
262For example, to run the tests on a simulated iPhone 6s running iOS 10.0,
263you would invoke `iossim` like this.
264
265```shell
266$ out/Debug-iphonesimulator/iossim -d 'iPhone 6s' -s '10.0' \
267 out/Debug-iphonesimulator/base_unittests.app
268```
269
270Please note that by default only a subset of simulator devices are installed
271with Xcode. You may have to install additional simulators in Xcode (or even
272an older version of Xcode) to be able to run on a specific configuration.
273
274Go to "Preferences > Components" tab in Xcode to install other simulator images
275(this is the location the setting is in Xcode 9.2; it may be different in other
276version of the tool).
277
michaeldo8cccf2142017-03-06 22:12:02278## Update your checkout
279
280To update an existing checkout, you can run
281
282```shell
283$ git rebase-update
284$ gclient sync
285```
286
287The first command updates the primary Chromium source repository and rebases
288any of your local branches on top of tip-of-tree (aka the Git branch
289`origin/master`). If you don't want to use this script, you can also just use
290`git pull` or other common Git commands to update the repo.
291
292The second command syncs dependencies to the appropriate versions and re-runs
293hooks as needed.
294
295## Tips, tricks, and troubleshooting
296
297If you have problems building, join us in `#chromium` on `irc.freenode.net` and
298ask there. As mentioned above, be sure that the
299[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
300is open before checking out. This will increase your chances of success.
301
302### Improving performance of `git status`
303
ishermance1d9d82017-05-12 23:10:04304#### Increase the vnode cache size
305
michaeldo8cccf2142017-03-06 22:12:02306`git status` is used frequently to determine the status of your checkout. Due
307to the large number of files in Chromium's checkout, `git status` performance
308can be quite variable. Increasing the system's vnode cache appears to help.
309By default, this command:
310
311```shell
312$ sysctl -a | egrep kern\..*vnodes
313```
314
315Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
316setting:
317
318```shell
319$ sudo sysctl kern.maxvnodes=$((512*1024))
320```
321
322Higher values may be appropriate if you routinely move between different
323Chromium checkouts. This setting will reset on reboot, the startup setting can
324be set in `/etc/sysctl.conf`:
325
326```shell
327$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
328```
329
330Or edit the file directly.
331
ishermance1d9d82017-05-12 23:10:04332#### Configure git to use an untracked cache
333
334If `git --version` reports 2.8 or higher, try running
335
336```shell
337$ git update-index --test-untracked-cache
338```
339
340If the output ends with `OK`, then the following may also improve performance of
341`git status`:
342
343```shell
344$ git config core.untrackedCache true
345```
346
347If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
michaeldo8cccf2142017-03-06 22:12:02348
349```shell
350$ git update-index --untracked-cache
351```
352
353### Xcode license agreement
354
355If you're getting the error
356
357> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
358> root via sudo.
359
360the Xcode license hasn't been accepted yet which (contrary to the message) any
361user can do by running:
362
363```shell
364$ xcodebuild -license
365```
366
367Only accepting for all users of the machine requires root:
368
369```shell
370$ sudo xcodebuild -license
371```