michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 1 | # Checking out and building Chromium for iOS |
| 2 | |
| 3 | There are instructions for other platforms linked from the |
| 4 | [get the code](../get_the_code.md) page. |
| 5 | |
| 6 | ## Instructions for Google Employees |
| 7 | |
| 8 | Are 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 Pinkerton | 90553fe | 2017-12-13 16:40:30 | [diff] [blame^] | 15 | * A 64-bit Mac running 10.12.6 or later. |
Justin Cohen | 0dcd4d8 | 2017-09-13 18:18:56 | [diff] [blame] | 16 | * [Xcode](https://developer.apple.com/xcode) 9.0+. |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 17 | * The current version of the JDK (required for the Closure compiler). |
| 18 | |
| 19 | ## Install `depot_tools` |
| 20 | |
| 21 | Clone the `depot_tools` repository: |
| 22 | |
| 23 | ```shell |
| 24 | $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 25 | ``` |
| 26 | |
| 27 | Add `depot_tools` to the end of your PATH (you will probably want to put this |
| 28 | in 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 | |
| 37 | Create a `chromium` directory for the checkout and change to it (you can call |
| 38 | this whatever you like and put it wherever you like, as |
| 39 | long as the full path has no spaces): |
| 40 | |
| 41 | ```shell |
| 42 | $ mkdir chromium && cd chromium |
| 43 | ``` |
| 44 | |
| 45 | Run the `fetch` tool from `depot_tools` to check out the code and its |
| 46 | dependencies. |
| 47 | |
| 48 | ```shell |
| 49 | $ fetch ios |
| 50 | ``` |
| 51 | |
| 52 | If you don't want the full repo history, you can save a lot of time by |
| 53 | adding the `--no-history` flag to `fetch`. |
| 54 | |
| 55 | Expect the command to take 30 minutes on even a fast connection, and many |
| 56 | hours on slower ones. |
| 57 | |
| 58 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 59 | directory called `src` in the working directory. The remaining instructions |
| 60 | assume you have switched to the `src` directory: |
| 61 | |
| 62 | ```shell |
| 63 | $ cd src |
| 64 | ``` |
| 65 | |
| 66 | *Optional*: You can also [install API |
| 67 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 68 | build to talk to some Google services, but this is not necessary for most |
| 69 | development and testing purposes. |
| 70 | |
| 71 | ## Setting up the build |
| 72 | |
| 73 | Since 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 |
| 75 | build directories under `out` for Release and Debug device and simulator |
ichikawa | 7c540a1 | 2017-05-18 05:50:32 | [diff] [blame] | 76 | builds, and generates an appropriate Xcode workspace |
| 77 | (`out/build/all.xcworkspace`) as well. |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 78 | |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 79 | You can customize the build by editing the file `$HOME/.setup-gn` (create it if |
| 80 | it does not exist). Look at `src/ios/build/tools/setup-gn.config` for |
| 81 | available configuration options. |
| 82 | |
| 83 | From 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 | |
| 91 | Note: you need to run `setup-gn.py` script every time one of the `BUILD.gn` |
| 92 | file is updated (either by you or after rebasing). If you forget to run it, |
| 93 | the list of targets and files in the Xcode solution may be stale. |
| 94 | |
| 95 | You can also follow the manual instructions on the |
| 96 | [Mac page](../mac_build_instructions.md), but make sure you set the |
| 97 | GN arg `target_os="ios"`. |
| 98 | |
| 99 | ## Building for device |
| 100 | |
| 101 | To be able to build and run Chromium and the tests for devices, you need to |
| 102 | have an Apple developer account (a free one will work) and the appropriate |
| 103 | provisioning profiles, then configure the build to use them. |
| 104 | |
| 105 | ### Code signing identity |
| 106 | |
| 107 | Please refer to the Apple documentation on how to get a code signing identity |
| 108 | and certificates. You can check that you have a code signing identity correctly |
| 109 | installed 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 | |
| 117 | If the command output says you have zero valid identities, then you do not |
| 118 | have a code signing identity installed and need to get one from Apple. If |
| 119 | you have more than one identity, the build system may select the wrong one |
| 120 | automatically, and you can use the `ios_code_signing_identity` gn variable |
| 121 | to control which one to use by setting it to the identity hash, e.g. to |
| 122 | `"0123456789ABCDEF0123456789ABCDEF01234567"`. |
| 123 | |
| 124 | ### Mobile provisioning profiles |
| 125 | |
| 126 | Once you have the code signing identity, you need to decide on a prefix |
| 127 | for 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 | |
| 131 | You then need to request provisioning profiles from Apple for your devices |
| 132 | for the following bundle identifiers to build and run Chromium with these |
| 133 | application extensions: |
| 134 | |
| 135 | - `${prefix}.chrome.ios.herebedragons` |
| 136 | - `${prefix}.chrome.ios.herebedragons.ShareExtension` |
| 137 | - `${prefix}.chrome.ios.herebedragons.TodayExtension` |
lod | f31fea5a | 2017-04-19 15:05:59 | [diff] [blame] | 138 | - `${prefix}.chrome.ios.herebedragons.SearchTodayExtension` |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 139 | |
| 140 | All these certificates need to have the "App Groups" |
| 141 | (`com.apple.security.application-groups`) capability enabled for |
| 142 | the following groups: |
| 143 | |
| 144 | - `group.${prefix}.chrome` |
| 145 | - `group.${prefix}.common` |
| 146 | |
| 147 | The `group.${prefix}.chrome` is only shared by Chromium and its extensions |
| 148 | to share files and configurations while the `group.${prefix}.common` is shared |
| 149 | with Chromium and other applications from the same organisation and can be used |
| 150 | to send commands to Chromium. |
| 151 | |
| 152 | ### Mobile provisioning profiles for tests |
| 153 | |
| 154 | In addition to that, you need provisioning profiles for the individual test |
| 155 | suites that you want to run. Their bundle identifier depends on whether the |
| 156 | gn variable `ios_automatically_manage_certs` is set to true (the default) |
| 157 | or false. |
| 158 | |
| 159 | If set to true, then you just need a provisioning profile for the bundle |
| 160 | identifier `${prefix}.gtest.generic-unit-test` but you can only have a |
| 161 | single test application installed on the device (all the test application |
| 162 | will share the same bundle identifier). |
| 163 | |
| 164 | If set to false, then you need a different provisioning profile for each |
| 165 | test application. Those provisioning profile will have a bundle identifier |
| 166 | matching the following pattern `${prefix}.gtest.${test-suite-name}` where |
| 167 | `${test-suite-name}` is the name of the test suite with underscores changed |
| 168 | to dashes (e.g. `base_unittests` app will use `${prefix}.gest.base-unittests` |
| 169 | as bundle identifier). |
| 170 | |
| 171 | To be able to run the EarlGrey tests on a device, you'll need two provisioning |
| 172 | profiles for EarlGrey and OCHamcrest frameworks: |
| 173 | |
| 174 | - `${prefix}.test.OCHamcrest` |
| 175 | - `${prefix}.test.EarlGrey` |
| 176 | |
| 177 | In addition to that, then you'll need one additional provisioning profile for |
| 178 | the XCTest module too. This module bundle identifier depends on whether the |
| 179 | gn variable `ios_automatically_manage_certs` is set to true or false. If set |
Sylvain Defresne | c6395714 | 2017-07-11 12:04:01 | [diff] [blame] | 180 | to true, then `${prefix}.gtest.generic-unit-test-module` will be used, otherwise |
| 181 | it will match the pattern: `${prefix}.gtest.${test-suite-name}-module`. |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 182 | |
| 183 | ### Other applications |
| 184 | |
| 185 | Other applications like `ios_web_shell` usually will require mobile provisioning |
| 186 | profiles with bundle identifiers that may usually match the following pattern |
| 187 | `${prefix}.${application-name}` and may require specific capabilities. |
| 188 | |
| 189 | Generally, if the mobile provisioning profile is missing then the code signing |
| 190 | step will fail and will print the bundle identifier of the bundle that could not |
| 191 | be signed on the command line, e.g.: |
| 192 | |
| 193 | ```shell |
| 194 | $ ninja -C out/Debug-iphoneos ios_web_shell |
| 195 | ninja: Entering directory `out/Debug-iphoneos' |
| 196 | FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision |
| 197 | python ../../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 |
| 198 | Error: no mobile provisioning profile found for "org.chromium.ios-web-shell". |
| 199 | ninja: build stopped: subcommand failed. |
| 200 | ``` |
| 201 | |
| 202 | Here, the build is failing because there are no mobile provisioning profiles |
| 203 | installed that could sign the `ios_web_shell.app` bundle with the identity |
| 204 | `0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to |
| 205 | request such a mobile provisioning profile from Apple. |
| 206 | |
| 207 | You can inspect the file passed via the `-e` flag to the `codesign.py` script |
| 208 | to check which capabilites are required for the mobile provisioning profile |
| 209 | (e.g. `src/build/config/ios/entitlements.plist` for the above build error, |
| 210 | remember that the paths are relative to the build directory, not to the source |
| 211 | directory). |
| 212 | |
| 213 | If the required capabilities are not enabled on the mobile provisioning profile, |
| 214 | then it will be impossible to install the application on a device (Xcode will |
| 215 | display an error stating that "The application was signed with invalid |
| 216 | entitlements"). |
| 217 | |
| 218 | ## Running apps from the commandline |
| 219 | |
| 220 | Any target that is built and runs on the bots (see [below](#Troubleshooting)) |
| 221 | should run successfully in a local build. To run in the simulator from the |
| 222 | command 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 Pinkerton | 90553fe | 2017-12-13 16:40:30 | [diff] [blame^] | 229 | With Xcode 9, `iossim` no longer automatically launches the Simulator. This must now |
| 230 | be done manually from within Xcode (`Xcode > Open Developer Tool > Simulator`), and |
| 231 | also must be done *after* running `iossim`. |
| 232 | |
Vaclav Brozek | 09fe5ec | 2017-07-18 11:13:16 | [diff] [blame] | 233 | ### Passing arguments |
| 234 | |
| 235 | Arguments 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 Baxley | cb99a9f | 2017-07-12 15:16:11 | [diff] [blame] | 244 | ### Running EarlGrey tests |
| 245 | |
| 246 | EarlGrey tests are run differently than other test targets, as there is an |
| 247 | XCTest bundle that is injected into the target application. Therefore you must |
| 248 | also 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 | |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 256 | ## Update your checkout |
| 257 | |
| 258 | To update an existing checkout, you can run |
| 259 | |
| 260 | ```shell |
| 261 | $ git rebase-update |
| 262 | $ gclient sync |
| 263 | ``` |
| 264 | |
| 265 | The first command updates the primary Chromium source repository and rebases |
| 266 | any 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 | |
| 270 | The second command syncs dependencies to the appropriate versions and re-runs |
| 271 | hooks as needed. |
| 272 | |
| 273 | ## Tips, tricks, and troubleshooting |
| 274 | |
| 275 | If you have problems building, join us in `#chromium` on `irc.freenode.net` and |
| 276 | ask there. As mentioned above, be sure that the |
| 277 | [waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree |
| 278 | is open before checking out. This will increase your chances of success. |
| 279 | |
| 280 | ### Improving performance of `git status` |
| 281 | |
isherman | ce1d9d8 | 2017-05-12 23:10:04 | [diff] [blame] | 282 | #### Increase the vnode cache size |
| 283 | |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 284 | `git status` is used frequently to determine the status of your checkout. Due |
| 285 | to the large number of files in Chromium's checkout, `git status` performance |
| 286 | can be quite variable. Increasing the system's vnode cache appears to help. |
| 287 | By default, this command: |
| 288 | |
| 289 | ```shell |
| 290 | $ sysctl -a | egrep kern\..*vnodes |
| 291 | ``` |
| 292 | |
| 293 | Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this |
| 294 | setting: |
| 295 | |
| 296 | ```shell |
| 297 | $ sudo sysctl kern.maxvnodes=$((512*1024)) |
| 298 | ``` |
| 299 | |
| 300 | Higher values may be appropriate if you routinely move between different |
| 301 | Chromium checkouts. This setting will reset on reboot, the startup setting can |
| 302 | be set in `/etc/sysctl.conf`: |
| 303 | |
| 304 | ```shell |
| 305 | $ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf |
| 306 | ``` |
| 307 | |
| 308 | Or edit the file directly. |
| 309 | |
isherman | ce1d9d8 | 2017-05-12 23:10:04 | [diff] [blame] | 310 | #### Configure git to use an untracked cache |
| 311 | |
| 312 | If `git --version` reports 2.8 or higher, try running |
| 313 | |
| 314 | ```shell |
| 315 | $ git update-index --test-untracked-cache |
| 316 | ``` |
| 317 | |
| 318 | If 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 | |
| 325 | If `git --version` reports 2.6 or higher, but below 2.8, you can instead run |
michaeldo | 8cccf214 | 2017-03-06 22:12:02 | [diff] [blame] | 326 | |
| 327 | ```shell |
| 328 | $ git update-index --untracked-cache |
| 329 | ``` |
| 330 | |
| 331 | ### Xcode license agreement |
| 332 | |
| 333 | If 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 | |
| 338 | the Xcode license hasn't been accepted yet which (contrary to the message) any |
| 339 | user can do by running: |
| 340 | |
| 341 | ```shell |
| 342 | $ xcodebuild -license |
| 343 | ``` |
| 344 | |
| 345 | Only accepting for all users of the machine requires root: |
| 346 | |
| 347 | ```shell |
| 348 | $ sudo xcodebuild -license |
| 349 | ``` |